summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2013-03-18 21:02:36 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-08-08 11:14:53 +0200
commita603c191578f7b33720e36e95421fcd58bc7abe4 (patch)
tree4de06cb51a580e85e5be38c91bbdfe980b4a55b5 /include
parent6385fc5ff5d669d3ec99d89f19c5860cf53011ba (diff)
downloadlibgit2-a603c191578f7b33720e36e95421fcd58bc7abe4.tar.gz
replaced foreach() with non callback based iterations in git_config_backend
new functions in struct git_config_backend: * iterator_new(...) * iterator_free(...) * next(...) The old callback based foreach style can still be used with `git_config_backend_foreach_match`
Diffstat (limited to 'include')
-rw-r--r--include/git2/config.h20
-rw-r--r--include/git2/sys/config.h4
2 files changed, 23 insertions, 1 deletions
diff --git a/include/git2/config.h b/include/git2/config.h
index 827d43544..f6fc74ee1 100644
--- a/include/git2/config.h
+++ b/include/git2/config.h
@@ -61,6 +61,7 @@ typedef struct {
} git_config_entry;
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
+typedef struct git_config_backend_iter* git_config_backend_iter;
typedef enum {
GIT_CVAR_FALSE = 0,
@@ -535,6 +536,25 @@ GIT_EXTERN(int) git_config_parse_int32(int32_t *out, const char *value);
GIT_EXTERN(int) git_config_parse_int64(int64_t *out, const char *value);
+/**
+ * Perform an operation on each config variable in given config backend
+ * matching a regular expression.
+ *
+ * This behaviors like `git_config_foreach_match` except instead of all config
+ * entries it just enumerates through the given backend entry.
+ *
+ * @param backend where to get the variables from
+ * @param regexp regular expression to match against config names (can be NULL)
+ * @param callback the function to call on each variable
+ * @param payload the data to pass to the callback
+ */
+GIT_EXTERN(int) git_config_backend_foreach_match(
+ git_config_backend *backend,
+ const char *regexp,
+ int (*fn)(const git_config_entry *, void *),
+ void *data);
+
+
/** @} */
GIT_END_DECL
#endif
diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h
index 11e59cf03..61dcce544 100644
--- a/include/git2/sys/config.h
+++ b/include/git2/sys/config.h
@@ -35,7 +35,9 @@ struct git_config_backend {
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
- int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
+ int (*iterator_new)(git_config_backend_iter **, struct git_config_backend *);
+ void (*iterator_free)(git_config_backend_iter *);
+ int (*next)(git_config_backend_iter *, git_config_entry *, struct git_config_backend *);
int (*refresh)(struct git_config_backend *);
void (*free)(struct git_config_backend *);
};