From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 04/10] bisect: use new "struct argv_array" to prepare argv for "setup_revisions"
Date: Sat, 09 May 2009 17:55:41 +0200 [thread overview]
Message-ID: <20090509155548.5387.51730.chriscool@tuxfamily.org> (raw)
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
next prev parent reply other threads:[~2009-05-09 16:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-09 15:55 [PATCH 00/10] bisect: port git bisect merge base checking to C Christian Couder
2009-05-09 15:55 ` [PATCH 01/10] bisect: use "sha1_array" to store skipped revisions Christian Couder
2009-05-09 15:55 ` [PATCH 02/10] bisect: implement "rev_argv_push" to fill an argv with revs Christian Couder
2009-05-09 15:55 ` [PATCH 03/10] bisect: store good revisions in a "sha1_array" Christian Couder
2009-05-09 15:55 ` Christian Couder [this message]
2009-05-09 15:55 ` [PATCH 05/10] bisect: remove too much function nesting Christian Couder
2009-05-09 15:55 ` [PATCH 06/10] bisect: make skipped array functions more generic Christian Couder
2009-05-09 15:55 ` [PATCH 07/10] bisect: automatically sort sha1_array if needed when looking it up Christian Couder
2009-05-09 16:28 ` Jakub Narebski
2009-05-10 4:44 ` Christian Couder
2009-05-09 15:55 ` [PATCH 08/10] bisect: implement the "check_merge_bases" function Christian Couder
2009-05-09 15:55 ` [PATCH 09/10] bisect: add "check_good_are_ancestors_of_bad" function Christian Couder
2009-05-09 15:55 ` [PATCH 10/10] bisect: make "git bisect" use new "--next-all" bisect-helper function Christian Couder
2009-05-11 0:44 ` Junio C Hamano
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=20090509155548.5387.51730.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).