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

[PATCH 04/10] bisect: use new "struct argv_array" to prepare argv for "setup_revisions"

From
Christian Couder <chriscool@tuxfamily.org>
Date
May 9, 2009, 15:55 UTC
Message-ID
<20090509155548.5387.51730.chriscool@tuxfamily.org>
In-Reply-To
<20090509154419.5324.96204.chriscool@tuxfamily.org>
Because we will use other instances of this struct.

The "rev_argv_push" function is changed into 2 functions "argv_array_push" and "argv_array_push_sha1" that take a "struct argv_array *" as first argument. And these functions are used to simplify "bisect_rev_setup".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 bisect.c |   57 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/bisect.c b/bisect.c
index 7976cbf..8e34186 100644
--- a/bisect.c
+++ b/bisect.c
@@ -18,12 +18,16 @@ struct sha1_array {
 static struct sha1_array good_revs;
 static struct sha1_array skipped_revs;
 
-static const char **rev_argv;
-static int rev_argv_nr;
-static int rev_argv_alloc;
-
 static const unsigned char *current_bad_sha1;
 
+struct argv_array {
+	const char **argv;
+	int argv_nr;
+	int argv_alloc;
+};
+
+struct argv_array rev_argv;
+
 static const char *argv_diff_tree[] = {"diff-tree", "--pretty", NULL, NULL};
 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@@ -410,13 +414,19 @@ struct commit_list *find_bisection(struct commit_list *list,
 	return best;
 }
 
-static void rev_argv_push(const unsigned char *sha1, const char *format)
+static void argv_array_push(struct argv_array *array, const char *string)
 {
-	struct strbuf buf = STRBUF_INIT;
+	ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc);
+	array->argv[array->argv_nr++] = string;
+}
 
+static void argv_array_push_sha1(struct argv_array *array,
+				 const unsigned char *sha1,
+				 const char *format)
+{
+	struct strbuf buf = STRBUF_INIT;
 	strbuf_addf(&buf, format, sha1_to_hex(sha1));
-	ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
-	rev_argv[rev_argv_nr++] = strbuf_detach(&buf, NULL);
+	argv_array_push(array, strbuf_detach(&buf, NULL));
 }
 
 static void sha1_array_push(struct sha1_array *array,
@@ -445,7 +455,7 @@ static int read_bisect_refs(void)
 	return for_each_ref_in("refs/bisect/", register_ref, NULL);
 }
 
-void read_bisect_paths(void)
+void read_bisect_paths(struct argv_array *array)
 {
 	struct strbuf str = STRBUF_INIT;
 	const char *filename = git_path("BISECT_NAMES");
@@ -460,8 +470,8 @@ void read_bisect_paths(void)
 
 		strbuf_trim(&str);
 		quoted = strbuf_detach(&str, NULL);
-		res = sq_dequote_to_argv(quoted, &rev_argv,
-					 &rev_argv_nr, &rev_argv_alloc);
+		res = sq_dequote_to_argv(quoted, &array->argv,
+					 &array->argv_nr, &array->argv_alloc);
 		if (res)
 			die("Badly quoted content in file '%s': %s",
 			    filename, quoted);
@@ -538,25 +548,16 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix)
 	if (read_bisect_refs())
 		die("reading bisect refs failed");
 
-	/* argv[0] will be ignored by setup_revisions */
-	ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
-	rev_argv[rev_argv_nr++] = xstrdup("bisect_rev_setup");
-
-	rev_argv_push(current_bad_sha1, "%s");
-
+	/* rev_argv.argv[0] will be ignored by setup_revisions */
+	argv_array_push(&rev_argv, xstrdup("bisect_rev_setup"));
+	argv_array_push_sha1(&rev_argv, current_bad_sha1, "%s");
 	for (i = 0; i < good_revs.sha1_nr; i++)
-		rev_argv_push(good_revs.sha1[i], "^%s");
-
-	ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
-	rev_argv[rev_argv_nr++] = xstrdup("--");
-
-	read_bisect_paths();
-
-	ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
-	rev_argv[rev_argv_nr++] = NULL;
-
-	setup_revisions(rev_argv_nr, rev_argv, revs, NULL);
+		argv_array_push_sha1(&rev_argv, good_revs.sha1[i], "^%s");
+	argv_array_push(&rev_argv, xstrdup("--"));
+	read_bisect_paths(&rev_argv);
+	argv_array_push(&rev_argv, NULL);
 
+	setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL);
 	revs->limited = 1;
 }
 
-- 
1.6.3.rc1.112.g17e25
Previous: Christian CouderNext: Christian Couder
Message 5 of 14 in “bisect: port git bisect merge base checking to C”
  1. 00/10 bisect: port git bisect merge base checking to CChristian Couder, May 9, 2009
  2. 01/10 bisect: use "sha1_array" to store skipped revisionsChristian Couder, May 9, 2009
  3. 02/10 bisect: implement "rev_argv_push" to fill an argv with revsChristian Couder, May 9, 2009
  4. 03/10 bisect: store good revisions in a "sha1_array"Christian Couder, May 9, 2009
  5. 04/10 bisect: use new "struct argv_array" to prepare argv for "setup_revisions"Christian Couder, May 9, 2009
  6. 05/10 bisect: remove too much function nestingChristian Couder, May 9, 2009
  7. 06/10 bisect: make skipped array functions more genericChristian Couder, May 9, 2009
  8. 07/10 bisect: automatically sort sha1_array if needed when looking it upChristian Couder, May 9, 2009
  9. Jakub NarebskiMay 9, 2009
  10. Christian CouderMay 10, 2009
  11. 08/10 bisect: implement the "check_merge_bases" functionChristian Couder, May 9, 2009
  12. 09/10 bisect: add "check_good_are_ancestors_of_bad" functionChristian Couder, May 9, 2009
  13. 10/10 bisect: make "git bisect" use new "--next-all" bisect-helper functionChristian Couder, May 9, 2009
  14. Junio C HamanoMay 11, 2009

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.