summaryrefslogtreecommitdiff
path: root/bisect.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2015-08-12 14:09:53 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-08-12 14:09:53 -0700
commit71cc60070f9d41765e58468e467352d2f008abfb (patch)
treea68543ff212703cf062e0c5bfd691beca0af5547 /bisect.c
parentSync with maint (diff)
parentbisect: don't mix option parsing and non-trivial code (diff)
downloadtgif-71cc60070f9d41765e58468e467352d2f008abfb.tar.xz
Merge branch 'ad/bisect-cleanup'
Code and documentation clean-up to "git bisect". * ad/bisect-cleanup: bisect: don't mix option parsing and non-trivial code bisect: simplify the addition of new bisect terms bisect: replace hardcoded "bad|good" by variables Documentation/bisect: revise overall content Documentation/bisect: move getting help section to the end bisect: correction of typo
Diffstat (limited to 'bisect.c')
-rw-r--r--bisect.c83
1 files changed, 66 insertions, 17 deletions
diff --git a/bisect.c b/bisect.c
index 03d5cd9454..857cf59aa3 100644
--- a/bisect.c
+++ b/bisect.c
@@ -21,6 +21,9 @@ static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", NULL, NULL};
+static const char *term_bad;
+static const char *term_good;
+
/* Remember to update object flag allocation in object.h */
#define COUNTED (1u<<16)
@@ -403,15 +406,21 @@ struct commit_list *find_bisection(struct commit_list *list,
static int register_ref(const char *refname, const struct object_id *oid,
int flags, void *cb_data)
{
- if (!strcmp(refname, "bad")) {
+ struct strbuf good_prefix = STRBUF_INIT;
+ strbuf_addstr(&good_prefix, term_good);
+ strbuf_addstr(&good_prefix, "-");
+
+ if (!strcmp(refname, term_bad)) {
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
oidcpy(current_bad_oid, oid);
- } else if (starts_with(refname, "good-")) {
+ } else if (starts_with(refname, good_prefix.buf)) {
sha1_array_append(&good_revs, oid->hash);
} else if (starts_with(refname, "skip-")) {
sha1_array_append(&skipped_revs, oid->hash);
}
+ strbuf_release(&good_prefix);
+
return 0;
}
@@ -634,7 +643,7 @@ static void exit_if_skipped_commits(struct commit_list *tried,
return;
printf("There are only 'skip'ped commits left to test.\n"
- "The first bad commit could be any of:\n");
+ "The first %s commit could be any of:\n", term_bad);
print_commit_list(tried, "%s\n", "%s\n");
if (bad)
printf("%s\n", oid_to_hex(bad));
@@ -732,18 +741,24 @@ static void handle_bad_merge_base(void)
if (is_expected_rev(current_bad_oid)) {
char *bad_hex = oid_to_hex(current_bad_oid);
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
-
- fprintf(stderr, "The merge base %s is bad.\n"
- "This means the bug has been fixed "
- "between %s and [%s].\n",
- bad_hex, bad_hex, good_hex);
-
+ if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) {
+ fprintf(stderr, "The merge base %s is bad.\n"
+ "This means the bug has been fixed "
+ "between %s and [%s].\n",
+ bad_hex, bad_hex, good_hex);
+ } else {
+ fprintf(stderr, "The merge base %s is %s.\n"
+ "This means the first '%s' commit is "
+ "between %s and [%s].\n",
+ bad_hex, term_bad, term_good, bad_hex, good_hex);
+ }
exit(3);
}
- fprintf(stderr, "Some good revs are not ancestor of the bad rev.\n"
+ fprintf(stderr, "Some %s revs are not ancestor of the %s rev.\n"
"git bisect cannot work properly in this case.\n"
- "Maybe you mistake good and bad revs?\n");
+ "Maybe you mistook %s and %s revs?\n",
+ term_good, term_bad, term_good, term_bad);
exit(1);
}
@@ -755,10 +770,10 @@ static void handle_skipped_merge_base(const unsigned char *mb)
warning("the merge base between %s and [%s] "
"must be skipped.\n"
- "So we cannot be sure the first bad commit is "
+ "So we cannot be sure the first %s commit is "
"between %s and %s.\n"
"We continue anyway.",
- bad_hex, good_hex, mb_hex, bad_hex);
+ bad_hex, good_hex, term_bad, mb_hex, bad_hex);
free(good_hex);
}
@@ -839,7 +854,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
int fd;
if (!current_bad_oid)
- die("a bad revision is needed");
+ die("a %s revision is needed", term_bad);
/* Check if file BISECT_ANCESTORS_OK exists. */
if (!stat(filename, &st) && S_ISREG(st.st_mode))
@@ -890,6 +905,36 @@ static void show_diff_tree(const char *prefix, struct commit *commit)
}
/*
+ * The terms used for this bisect session are stored in BISECT_TERMS.
+ * We read them and store them to adapt the messages accordingly.
+ * Default is bad/good.
+ */
+void read_bisect_terms(const char **read_bad, const char **read_good)
+{
+ struct strbuf str = STRBUF_INIT;
+ const char *filename = git_path("BISECT_TERMS");
+ FILE *fp = fopen(filename, "r");
+
+ if (!fp) {
+ if (errno == ENOENT) {
+ *read_bad = "bad";
+ *read_good = "good";
+ return;
+ } else {
+ die("could not read file '%s': %s", filename,
+ strerror(errno));
+ }
+ } else {
+ strbuf_getline(&str, fp, '\n');
+ *read_bad = strbuf_detach(&str, NULL);
+ strbuf_getline(&str, fp, '\n');
+ *read_good = strbuf_detach(&str, NULL);
+ }
+ strbuf_release(&str);
+ fclose(fp);
+}
+
+/*
* We use the convention that exiting with an exit code 10 means that
* the bisection process finished successfully.
* In this case the calling shell script should exit 0.
@@ -905,6 +950,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
const unsigned char *bisect_rev;
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
+ read_bisect_terms(&term_bad, &term_good);
if (read_bisect_refs())
die("reading bisect refs failed");
@@ -926,8 +972,10 @@ int bisect_next_all(const char *prefix, int no_checkout)
*/
exit_if_skipped_commits(tried, NULL);
- printf("%s was both good and bad\n",
- oid_to_hex(current_bad_oid));
+ printf("%s was both %s and %s\n",
+ oid_to_hex(current_bad_oid),
+ term_good,
+ term_bad);
exit(1);
}
@@ -942,7 +990,8 @@ int bisect_next_all(const char *prefix, int no_checkout)
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
exit_if_skipped_commits(tried, current_bad_oid);
- printf("%s is the first bad commit\n", bisect_rev_hex);
+ printf("%s is the first %s commit\n", bisect_rev_hex,
+ term_bad);
show_diff_tree(prefix, revs.commits->item);
/* This means the bisection process succeeded. */
exit(10);