git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] string-list.h: Add STRING_LIST_INIT macro and make use of it.

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 27, 2010, 16:44 UTC
Message-ID
<7vbpawifwa.fsf@alter.siamese.dyndns.org>
In-Reply-To
<de7ad1688930aa47515736885b7d8438118e7aa1.1277595923.git.tfransosi@gmail.com>
I think you need the attached on top to be more complete.

But I wonder if this is worth it (not this "more complete", but your patch). We convert 16 or so instances of initialization for "no strdup" list, but there are about the same number of "strdup" instances still spelled out:

    $ git grep -e 'struct string_list [^ ]* = {.*'
    $ git grep -e 'struct string_list [^ ]* = {.*1'
Wouldn't it be more sensible to use this instead?
    #define STRING_LIST_INIT(pleasedup) { NULL, 0, 0, (pleasedup) }
---
 builtin/mv.c       |    2 +-
 builtin/remote.c   |    4 ++--
 transport-helper.c |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/builtin/mv.c b/builtin/mv.c
index c07f53b..e2f0279 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -63,7 +63,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 	const char **source, **destination, **dest_path;
 	enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
 	struct stat st;
-	struct string_list src_for_dst = {NULL, 0, 0, 0};
+	struct string_list src_for_dst = STRING_LIST_INIT;
 
 	git_config(git_default_config, NULL);
 
diff --git a/builtin/remote.c b/builtin/remote.c
index 9d41792..5ff2b5b 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -134,7 +134,7 @@ static int add_branch(const char *key, const char *branchname,
 static int add(int argc, const char **argv)
 {
 	int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
-	struct string_list track = { NULL, 0, 0 };
+	struct string_list track = STRING_LIST_INIT;
 	const char *master = NULL;
 	struct remote *remote;
 	struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
@@ -1483,7 +1483,7 @@ static int get_one_entry(struct remote *remote, void *priv)
 
 static int show_all(void)
 {
-	struct string_list list = { NULL, 0, 0 };
+	struct string_list list = STRING_LIST_INIT;
 	int result;
 
 	list.strdup_strings = 1;
diff --git a/transport-helper.c b/transport-helper.c
index 0381de5..86a79b9 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -689,7 +689,7 @@ static int push_refs_with_export(struct transport *transport,
 	struct child_process *helper, exporter;
 	struct helper_data *data = transport->data;
 	char *export_marks = NULL, *import_marks = NULL;
-	struct string_list revlist_args = { NULL, 0, 0 };
+	struct string_list revlist_args = STRING_LIST_INIT;
 	struct strbuf buf = STRBUF_INIT;
 
 	helper = get_helper(transport);
Previous: Thiago FarinaNext: Alex Riesen
Message 7 of 21 in “string-list.h: Add STRING_LIST_INIT macro and make use of it.”
  1. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  2. Sverre RabbelierJun 26, 2010
  3. Jonathan NiederJun 26, 2010
  4. Thiago FarinaJun 26, 2010
  5. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  6. string-list.h: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jun 26, 2010
  7. Junio C HamanoJun 27, 2010
  8. Alex RiesenJun 28, 2010
  9. Junio C HamanoJun 29, 2010
  10. Peter KjellerstedtJun 29, 2010
  11. Alex RiesenJun 29, 2010
  12. string_list: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jul 2, 2010
  13. Jonathan NiederJul 2, 2010
  14. Thiago FarinaJul 2, 2010
  15. Jonathan NiederJul 2, 2010
  16. string_list: Add STRING_LIST_INIT macro and make use of it.Thiago Farina, Jul 4, 2010
  17. Jonathan NiederJul 7, 2010
  18. Junio C HamanoJul 7, 2010
  19. Thiago FarinaJul 10, 2010
  20. Jonathan NiederJul 10, 2010
  21. Thiago FarinaAug 19, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.