From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>,
Marc Branchaud <marcnarc@xiplink.com>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Johannes Sixt <j.sixt@viscovery.net>
Subject: [PATCH 3/4] string-list: add for_each_string_list()
Date: Thu, 19 Feb 2009 00:14:30 -0500 [thread overview]
Message-ID: <1235020471-59982-4-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1235020471-59982-3-git-send-email-jaysoffian@gmail.com>
Give string-list a convenience function for iterating over each of the
items in a string_list.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
string-list.c | 10 ++++++++++
string-list.h | 5 +++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/string-list.c b/string-list.c
index 15e14cf..1ac536e 100644
--- a/string-list.c
+++ b/string-list.c
@@ -92,6 +92,16 @@ struct string_list_item *string_list_lookup(const char *string, struct string_li
return list->items + i;
}
+int for_each_string_list(string_list_each_func_t fn,
+ struct string_list *list, void *cb_data)
+{
+ int i, ret = 0;
+ for (i = 0; i < list->nr; i++)
+ if ((ret = fn(&list->items[i], cb_data)))
+ break;
+ return ret;
+}
+
void string_list_clear(struct string_list *list, int free_util)
{
if (list->items) {
diff --git a/string-list.h b/string-list.h
index d32ba05..14bbc47 100644
--- a/string-list.h
+++ b/string-list.h
@@ -20,6 +20,11 @@ void string_list_clear(struct string_list *list, int free_util);
typedef void (*string_list_clear_func_t)(void *p, const char *str);
void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
+/* Use this function to iterate over each item */
+typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
+int for_each_string_list(string_list_each_func_t,
+ struct string_list *list, void *cb_data);
+
/* Use these functions only on sorted lists: */
int string_list_has_string(const struct string_list *list, const char *string);
int string_list_find_insert_index(const struct string_list *list, const char *string,
--
1.6.2.rc1.218.g1b4fab
next prev parent reply other threads:[~2009-02-19 5:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-19 5:14 [PATCH 0/4] Improve "remote show" output Jay Soffian
2009-02-19 5:14 ` [PATCH 1/4] remote: minor code cleanups in preparation for changing "show" output Jay Soffian
2009-02-19 5:14 ` [PATCH 2/4] remote: move append_ref_to_tracked_list to get rid of prototype Jay Soffian
2009-02-19 5:14 ` Jay Soffian [this message]
2009-02-19 5:14 ` [PATCH 4/4] remote: new show output style Jay Soffian
2009-02-19 16:03 ` Marc Branchaud
2009-02-19 16:16 ` Sverre Rabbelier
2009-02-19 16:31 ` Marc Branchaud
2009-02-19 16:33 ` Sverre Rabbelier
2009-02-19 16:17 ` Rostislav Svoboda
2009-02-19 17:57 ` Jay Soffian
2009-02-19 17:59 ` Jay Soffian
2009-02-19 18:58 ` Julian Phillips
2009-02-20 22:34 ` Marc Branchaud
2009-02-20 22:55 ` Jay Soffian
2009-02-19 19:29 ` Johannes Sixt
2009-02-19 19:51 ` Jay Soffian
2009-02-20 7:19 ` [PATCH 1/4] remote: minor code cleanups in preparation for changing "show" output Junio C Hamano
2009-02-20 10:50 ` Jay Soffian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1235020471-59982-4-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=marcnarc@xiplink.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).