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/sys/config.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/git2/sys') 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 *); }; -- 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/sys/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index 61dcce544..f617623a9 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -37,7 +37,7 @@ struct git_config_backend { int (*del)(struct git_config_backend *, const char *key); 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 (*next)(git_config_entry *, git_config_backend_iter *); int (*refresh)(struct git_config_backend *); void (*free)(struct git_config_backend *); }; -- 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/sys/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index f617623a9..09c79638a 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -31,7 +31,7 @@ struct git_config_backend { /* Open means open the file/database and parse if necessary */ int (*open)(struct git_config_backend *, git_config_level_t level); int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry); - int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload); + int (*get_multivar_foreach)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload); 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); -- 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/sys/config.h | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index 09c79638a..45599dc69 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -20,6 +20,32 @@ */ GIT_BEGIN_DECL +/** + * Every iterator must have this struct as its first element, so the + * API can talk to it. You'd define your iterator as + * + * struct my_iterator { + * git_config_iterator parent; + * ... + * } + * + * and assign `iter->parent.backend` to your `git_config_backend`. + */ +struct git_config_iterator { + git_config_backend *backend; + unsigned int flags; + + /** + * Return the current entry and advance the iterator + */ + int (*next)(git_config_entry *entry, git_config_iterator *iter); + + /** + * Free the iterator + */ + void (*free)(git_config_iterator *iter); +}; + /** * Generic backend that implements the interface to * access a configuration file @@ -35,9 +61,7 @@ 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 (*iterator_new)(git_config_backend_iter **, struct git_config_backend *); - void (*iterator_free)(git_config_backend_iter *); - int (*next)(git_config_entry *, git_config_backend_iter *); + int (*iterator)(git_config_iterator **, struct git_config_backend *); int (*refresh)(struct git_config_backend *); void (*free)(struct git_config_backend *); }; -- cgit v1.2.1 From 3a7ffc29c9416c5d182835c7f18c04437366f218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 16:18:07 +0200 Subject: config: initial multivar iterator --- include/git2/sys/config.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index 45599dc69..477d47271 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -36,9 +36,10 @@ struct git_config_iterator { unsigned int flags; /** - * Return the current entry and advance the iterator + * Return the current entry and advance the iterator. The + * memory belongs to the library. */ - int (*next)(git_config_entry *entry, git_config_iterator *iter); + int (*next)(const git_config_entry *entry, git_config_iterator *iter); /** * Free the iterator @@ -58,6 +59,7 @@ struct git_config_backend { int (*open)(struct git_config_backend *, git_config_level_t level); int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry); int (*get_multivar_foreach)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload); + int (*get_multivar)(git_config_iterator **, struct git_config_backend *, const char *name, const char *regexp); 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); -- cgit v1.2.1 From cca5df6376fd41fb4fbbb9f8a9ff87c38079dfd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 8 Aug 2013 16:59:39 +0200 Subject: config: hopefully get the iterator to work on multivars --- include/git2/sys/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index 477d47271..d5b450a6c 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -39,7 +39,7 @@ struct git_config_iterator { * Return the current entry and advance the iterator. The * memory belongs to the library. */ - int (*next)(const git_config_entry *entry, git_config_iterator *iter); + int (*next)(git_config_entry *entry, git_config_iterator *iter); /** * Free the iterator -- 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/sys/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index d5b450a6c..e369fb8ab 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -39,7 +39,7 @@ struct git_config_iterator { * Return the current entry and advance the iterator. The * memory belongs to the library. */ - int (*next)(git_config_entry *entry, git_config_iterator *iter); + int (*next)(git_config_entry **entry, git_config_iterator *iter); /** * Free the iterator -- 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/sys/config.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/git2/sys') diff --git a/include/git2/sys/config.h b/include/git2/sys/config.h index e369fb8ab..7572ace51 100644 --- a/include/git2/sys/config.h +++ b/include/git2/sys/config.h @@ -58,8 +58,6 @@ struct git_config_backend { /* Open means open the file/database and parse if necessary */ int (*open)(struct git_config_backend *, git_config_level_t level); int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry); - int (*get_multivar_foreach)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload); - int (*get_multivar)(git_config_iterator **, struct git_config_backend *, const char *name, const char *regexp); 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); -- cgit v1.2.1