#include "run-command.h"
#include "bisect.h"
-static unsigned char (*skipped_sha1)[20];
-static int skipped_sha1_nr;
-static int skipped_sha1_alloc;
+struct sha1_array {
+ unsigned char (*sha1)[20];
+ int sha1_nr;
+ int sha1_alloc;
+};
-static const char **rev_argv;
-static int rev_argv_nr;
-static int rev_argv_alloc;
+static struct sha1_array good_revs;
+static struct sha1_array skipped_revs;
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};
return best;
}
+static void argv_array_push(struct argv_array *array, const char *string)
+{
+ 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));
+ argv_array_push(array, strbuf_detach(&buf, NULL));
+}
+
+static void sha1_array_push(struct sha1_array *array,
+ const unsigned char *sha1)
+{
+ ALLOC_GROW(array->sha1, array->sha1_nr + 1, array->sha1_alloc);
+ hashcpy(array->sha1[array->sha1_nr++], sha1);
+}
+
static int register_ref(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
if (!strcmp(refname, "bad")) {
- ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
current_bad_sha1 = sha1;
- rev_argv[rev_argv_nr++] = xstrdup(sha1_to_hex(sha1));
} else if (!prefixcmp(refname, "good-")) {
- const char *hex = sha1_to_hex(sha1);
- char *good = xmalloc(strlen(hex) + 2);
- *good = '^';
- memcpy(good + 1, hex, strlen(hex) + 1);
- ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
- rev_argv[rev_argv_nr++] = good;
+ sha1_array_push(&good_revs, sha1);
} else if (!prefixcmp(refname, "skip-")) {
- ALLOC_GROW(skipped_sha1, skipped_sha1_nr + 1,
- skipped_sha1_alloc);
- hashcpy(skipped_sha1[skipped_sha1_nr++], sha1);
+ sha1_array_push(&skipped_revs, sha1);
}
return 0;
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");
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);
static void prepare_skipped(void)
{
- qsort(skipped_sha1, skipped_sha1_nr, sizeof(*skipped_sha1), skipcmp);
+ qsort(skipped_revs.sha1, skipped_revs.sha1_nr,
+ sizeof(*skipped_revs.sha1), skipcmp);
}
static const unsigned char *skipped_sha1_access(size_t index, void *table)
static int lookup_skipped(unsigned char *sha1)
{
- return sha1_pos(sha1, skipped_sha1, skipped_sha1_nr,
+ return sha1_pos(sha1, skipped_revs.sha1, skipped_revs.sha1_nr,
skipped_sha1_access);
}
*tried = NULL;
- if (!skipped_sha1_nr)
+ if (!skipped_revs.sha1_nr)
return list;
prepare_skipped();
static void bisect_rev_setup(struct rev_info *revs, const char *prefix)
{
+ int i;
+
init_revisions(revs, prefix);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;
- /* 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");
-
if (read_bisect_refs())
die("reading bisect refs failed");
- 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);
+ /* 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++)
+ 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;
}
mark_edges_uninteresting(revs->commits, revs, NULL);
revs->commits = find_bisection(revs->commits, reaches, all,
- !!skipped_sha1_nr);
-}
-
-int bisect_next_vars(const char *prefix)
-{
- struct rev_info revs;
- struct rev_list_info info;
- int reaches = 0, all = 0;
-
- memset(&info, 0, sizeof(info));
- info.revs = &revs;
- info.bisect_show_flags = BISECT_SHOW_TRIED | BISECT_SHOW_STRINGED;
-
- bisect_common(&revs, prefix, &reaches, &all);
-
- return show_bisect_vars(&info, reaches, all);
+ !!skipped_revs.sha1_nr);
}
static void exit_if_skipped_commits(struct commit_list *tried,