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

[PATCH v3 2/4] wt-status: use argv_array API

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 29, 2013, 13:05 UTC
Message-ID
<1377781536-31955-3-git-send-email-Matthieu.Moy@imag.fr>
In-Reply-To
<1377781536-31955-1-git-send-email-Matthieu.Moy@imag.fr>

No behavior change, but two slight code reorganization: argv_array_push doesn't accept NULL strings, and duplicates its argument hence summary_limit must be written to before being inserted into argv.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 wt-status.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index cb24f1f..958a53c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -8,6 +8,7 @@
 #include "diffcore.h"
 #include "quote.h"
 #include "run-command.h"
+#include "argv-array.h"
 #include "remote.h"
 #include "refs.h"
 #include "submodule.h"
@@ -663,29 +664,30 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
 	char summary_limit[64];
 	char index[PATH_MAX];
 	const char *env[] = { NULL, NULL };
-	const char *argv[8];
-
-	env[0] =	index;
-	argv[0] =	"submodule";
-	argv[1] =	"summary";
-	argv[2] =	uncommitted ? "--files" : "--cached";
-	argv[3] =	"--for-status";
-	argv[4] =	"--summary-limit";
-	argv[5] =	summary_limit;
-	argv[6] =	uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD");
-	argv[7] =	NULL;
+	struct argv_array argv = ARGV_ARRAY_INIT;
 
 	sprintf(summary_limit, "%d", s->submodule_summary);
 	snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
 
+	env[0] = index;
+	argv_array_push(&argv, "submodule");
+	argv_array_push(&argv, "summary");
+	argv_array_push(&argv, uncommitted ? "--files" : "--cached");
+	argv_array_push(&argv, "--for-status");
+	argv_array_push(&argv, "--summary-limit");
+	argv_array_push(&argv, summary_limit);
+	if (!uncommitted)
+		argv_array_push(&argv, s->amend ? "HEAD^" : "HEAD");
+
 	memset(&sm_summary, 0, sizeof(sm_summary));
-	sm_summary.argv = argv;
+	sm_summary.argv = argv.argv;
 	sm_summary.env = env;
 	sm_summary.git_cmd = 1;
 	sm_summary.no_stdin = 1;
 	fflush(s->fp);
 	sm_summary.out = dup(fileno(s->fp));    /* run_command closes it */
 	run_command(&sm_summary);
+	argv_array_clear(&argv);
 }
 
 static void wt_status_print_other(struct wt_status *s,
-- 
1.8.4.12.gf9d53a3.dirty
Previous: Matthieu MoyNext: Matthieu Moy
Message 3 of 16 in “Disable "git status" comment prefix”
  1. 0/4 Disable "git status" comment prefixMatthieu Moy, Aug 29, 2013
  2. 1/4 builtin/stripspace.c: fix broken indentationMatthieu Moy, Aug 29, 2013
  3. 2/4 wt-status: use argv_array APIMatthieu Moy, Aug 29, 2013
  4. 3/4 get rid of "git submodule summary --for-status"Matthieu Moy, Aug 29, 2013
  5. Jens LehmannAug 29, 2013
  6. Matthieu MoyAug 29, 2013
  7. Jens LehmannAug 30, 2013
  8. Jens LehmannAug 30, 2013
  9. Jens LehmannAug 30, 2013
  10. brian m. carlsonAug 31, 2013
  11. Jens LehmannSep 1, 2013
  12. Jens LehmannSep 3, 2013
  13. Junio C HamanoAug 29, 2013
  14. Matthieu MoyAug 29, 2013
  15. 4/4 status: introduce status.displayCommentChar to disable display of #Matthieu Moy, Aug 29, 2013
  16. Junio C HamanoAug 29, 2013

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.