From a603c191578f7b33720e36e95421fcd58bc7abe4 Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Mon, 18 Mar 2013 21:02:36 +0100 Subject: 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` --- include/git2/config.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/git2/config.h') 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 -- cgit v1.2.1 From 4d588d9713bb558e45a8bdf6c41d232bb592b814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 11:24:47 +0200 Subject: Don't typedef a pointer Make the iterator structure opaque and make sure it compiles. --- include/git2/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index f6fc74ee1..43bc19412 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -61,7 +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 struct git_config_backend_iter git_config_backend_iter; typedef enum { GIT_CVAR_FALSE = 0, -- cgit v1.2.1 From 4efa32903adf131631d283c914e0a5bf29c49e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 13:41:18 +0200 Subject: config: get_multivar -> get_multivar_foreach The plain function will return an iterator, so move this one out of the way. --- include/git2/config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index 43bc19412..a0dc11bb1 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -328,7 +328,7 @@ GIT_EXTERN(int) git_config_get_bool(int *out, const git_config *cfg, const char GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, const char *name); /** - * Get each value of a multivar. + * Get each value of a multivar in a foreach callback * * The callback will be called on each variable found * @@ -339,7 +339,7 @@ GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, c * @param callback the function to be called on each value of the variable * @param payload opaque pointer to pass to the callback */ -GIT_EXTERN(int) git_config_get_multivar(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload); +GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload); /** * Set the value of an integer config variable in the config file -- cgit v1.2.1 From eba7399251cfa95d9346b9b41ca78dc5d43a840d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 14:39:32 +0200 Subject: config: move next() and free() into the iterator Like we have in the references iterator, next and free belong in the iterator itself. --- include/git2/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index a0dc11bb1..950312548 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -61,7 +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 struct git_config_iterator git_config_iterator; typedef enum { GIT_CVAR_FALSE = 0, -- cgit v1.2.1 From 99dfb538addc06c2f40d29371c52dd43f0d6ceb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 17:57:59 +0200 Subject: config: working multivar iterator Implement the foreach version as a wrapper around the iterator. --- include/git2/config.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index 950312548..e1d34b997 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -341,6 +341,16 @@ GIT_EXTERN(int) git_config_get_string(const char **out, const git_config *cfg, c */ GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const char *name, const char *regexp, git_config_foreach_cb callback, void *payload); +/** + * Get each value of a multivar + * + * @param out pointer to store the iterator + * @param cfg where to look for the variable + * @param name the variable's name + * @param regexp regular expression to filter which variables we're + * interested in. Use NULL to indicate all + */ +GIT_EXTERN(int) git_config_get_multivar(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); /** * Set the value of an integer config variable in the config file * with the highest level (usually the local one). -- cgit v1.2.1 From 1e96c9d5341e5f2b0e1af9a1088cc30d3ffb9a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 20:47:06 +0200 Subject: config: add _next() and _iterator_free() Make it look like the refs iterator API. --- include/git2/config.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index e1d34b997..b338e0c81 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -351,6 +351,23 @@ GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const cha * interested in. Use NULL to indicate all */ GIT_EXTERN(int) git_config_get_multivar(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); + +/** + * Return the current entry and advance the iterator + * + * @param entry pointer to store the entry + * @param iter the iterator + * @return 0 or an error code. GIT_ITEROVER if the iteration has completed + */ +GIT_EXTERN(int) git_config_next(git_config_entry **entry, git_config_iterator *iter); + +/** + * Free a config iterator + * + * @param iter the iterator to free + */ +GIT_EXTERN(void) git_config_iterator_free(git_config_iterator *iter); + /** * Set the value of an integer config variable in the config file * with the highest level (usually the local one). -- cgit v1.2.1 From 5880962d90958bc37c08c21d37c9da480ef20e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 9 Aug 2013 09:05:19 +0200 Subject: config: introduce _iterator_new() As the name suggests, it iterates over all the entries --- include/git2/config.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index b338e0c81..aed720fc8 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -452,6 +452,17 @@ GIT_EXTERN(int) git_config_foreach( git_config_foreach_cb callback, void *payload); +/** + * Iterate over all the config variables + * + * Use `git_config_next` to advance the iteration and + * `git_config_iterator_free` when done. + * + * @param out pointer to store the iterator + * @param cfg where to ge the variables from + */ +GIT_EXTERN(int) git_config_iterator_new(git_config_iterator **out, const git_config *cfg); + /** * Perform an operation on each config variable matching a regular expression. * -- cgit v1.2.1 From 54f3a572b4fac419008afa83da56c1b0daee1257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Fri, 9 Aug 2013 10:29:11 +0200 Subject: config: introduce a regex-filtering iterator --- include/git2/config.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index aed720fc8..28216467b 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -463,6 +463,18 @@ GIT_EXTERN(int) git_config_foreach( */ GIT_EXTERN(int) git_config_iterator_new(git_config_iterator **out, const git_config *cfg); +/** + * Iterate over all the config variables whose name matches a pattern + * + * Use `git_config_next` to advance the iteration and + * `git_config_iterator_free` when done. + * + * @param out pointer to store the iterator + * @param cfg where to ge the variables from + * @param regexp regular expression to match the names + */ +GIT_EXTERN(int) git_config_iterator_glob_new(git_config_iterator **out, const git_config *cfg, const char *regexp); + /** * Perform an operation on each config variable matching a regular expression. * -- cgit v1.2.1 From f4be8209afd3cc996667196a1e437aac21485691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 14 Aug 2013 00:45:05 +0200 Subject: config: don't special-case the multivar iterator Build it on top of the normal iterator instead, which lets use re-use a lot of code. --- include/git2/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/config.h') diff --git a/include/git2/config.h b/include/git2/config.h index 28216467b..f14415148 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -350,7 +350,7 @@ GIT_EXTERN(int) git_config_get_multivar_foreach(const git_config *cfg, const cha * @param regexp regular expression to filter which variables we're * interested in. Use NULL to indicate all */ -GIT_EXTERN(int) git_config_get_multivar(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); +GIT_EXTERN(int) git_config_multivar_iterator_new(git_config_iterator **out, const git_config *cfg, const char *name, const char *regexp); /** * Return the current entry and advance the iterator -- cgit v1.2.1