bisect: replace hardcoded "bad|good" by variables
To add new tags like old/new and have keywords less confusing, the first step is to avoid hardcoding the keywords. The default mode is still bad/good. Signed-off-by: Antoine Delaite <antoine.delaite@ensimag.grenoble-inp.fr> Signed-off-by: Louis Stuber <stuberl@ensimag.grenoble-inp.fr> Signed-off-by: Valentin Duperray <Valentin.Duperray@ensimag.imag.fr> Signed-off-by: Franck Jonas <Franck.Jonas@ensimag.imag.fr> Signed-off-by: Lucien Kong <Lucien.Kong@ensimag.imag.fr> Signed-off-by: Thomas Nguy <Thomas.Nguy@ensimag.imag.fr> Signed-off-by: Huynh Khoi Nguyen Nguyen <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Antoine Delaite committed
Jun 29, 2015 at 17:40 UTC
43f9d9f3a6c6004853fcc7b283dafc3590478498
2 files changed
+68
-43
bisect.c
+37
-17
@@ -21,6 +21,9 @@ static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
21
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
22
static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", NULL, NULL};
23
24
+static const char *term_bad;
25
+static const char *term_good;
26
+
27
/* Remember to update object flag allocation in object.h */
28
#define COUNTED (1u<<16)
29
@@ -403,15 +406,21 @@ struct commit_list *find_bisection(struct commit_list *list,
406
static int register_ref(const char *refname, const struct object_id *oid,
407
int flags, void *cb_data)
408
{
406
- if (!strcmp(refname, "bad")) {
409
+ struct strbuf good_prefix = STRBUF_INIT;
410
+ strbuf_addstr(&good_prefix, term_good);
411
+ strbuf_addstr(&good_prefix, "-");
412
+
413
+ if (!strcmp(refname, term_bad)) {
414
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
415
oidcpy(current_bad_oid, oid);
409
- } else if (starts_with(refname, "good-")) {
416
+ } else if (starts_with(refname, good_prefix.buf)) {
417
sha1_array_append(&good_revs, oid->hash);
418
} else if (starts_with(refname, "skip-")) {
419
sha1_array_append(&skipped_revs, oid->hash);
420
}
421
422
+ strbuf_release(&good_prefix);
423
+
424
return 0;
425
}
426
@@ -634,7 +643,7 @@ static void exit_if_skipped_commits(struct commit_list *tried,
643
return;
644
645
printf("There are only 'skip'ped commits left to test.\n"
637
- "The first bad commit could be any of:\n");
646
+ "The first %s commit could be any of:\n", term_bad);
647
print_commit_list(tried, "%s\n", "%s\n");
648
if (bad)
649
printf("%s\n", oid_to_hex(bad));
@@ -732,18 +741,24 @@ static void handle_bad_merge_base(void)
741
if (is_expected_rev(current_bad_oid)) {
742
char *bad_hex = oid_to_hex(current_bad_oid);
743
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
735
-
736
- fprintf(stderr, "The merge base %s is bad.\n"
737
- "This means the bug has been fixed "
738
- "between %s and [%s].\n",
739
- bad_hex, bad_hex, good_hex);
740
-
744
+ if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) {
745
+ fprintf(stderr, "The merge base %s is bad.\n"
746
+ "This means the bug has been fixed "
747
+ "between %s and [%s].\n",
748
+ bad_hex, bad_hex, good_hex);
749
+ } else {
750
+ fprintf(stderr, "The merge base %s is %s.\n"
751
+ "This means the first '%s' commit is "
752
+ "between %s and [%s].\n",
753
+ bad_hex, term_bad, term_good, bad_hex, good_hex);
754
+ }
755
exit(3);
756
}
757
744
- fprintf(stderr, "Some good revs are not ancestor of the bad rev.\n"
758
+ fprintf(stderr, "Some %s revs are not ancestor of the %s rev.\n"
759
"git bisect cannot work properly in this case.\n"
746
- "Maybe you mistook good and bad revs?\n");
760
+ "Maybe you mistook %s and %s revs?\n",
761
+ term_good, term_bad, term_good, term_bad);
762
exit(1);
763
}
764
@@ -755,10 +770,10 @@ static void handle_skipped_merge_base(const unsigned char *mb)
770
771
warning("the merge base between %s and [%s] "
772
"must be skipped.\n"
758
- "So we cannot be sure the first bad commit is "
773
+ "So we cannot be sure the first %s commit is "
774
"between %s and %s.\n"
775
"We continue anyway.",
761
- bad_hex, good_hex, mb_hex, bad_hex);
776
+ bad_hex, good_hex, term_bad, mb_hex, bad_hex);
777
free(good_hex);
778
}
779
@@ -839,7 +854,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
854
int fd;
855
856
if (!current_bad_oid)
842
- die("a bad revision is needed");
857
+ die("a %s revision is needed", term_bad);
858
859
/* Check if file BISECT_ANCESTORS_OK exists. */
860
if (!stat(filename, &st) && S_ISREG(st.st_mode))
@@ -905,6 +920,8 @@ int bisect_next_all(const char *prefix, int no_checkout)
920
const unsigned char *bisect_rev;
921
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
922
923
+ term_bad = "bad";
924
+ term_good = "good";
925
if (read_bisect_refs())
926
die("reading bisect refs failed");
927
@@ -926,8 +943,10 @@ int bisect_next_all(const char *prefix, int no_checkout)
943
*/
944
exit_if_skipped_commits(tried, NULL);
945
929
- printf("%s was both good and bad\n",
930
- oid_to_hex(current_bad_oid));
946
+ printf("%s was both %s and %s\n",
947
+ oid_to_hex(current_bad_oid),
948
+ term_good,
949
+ term_bad);
950
exit(1);
951
}
952
@@ -942,7 +961,8 @@ int bisect_next_all(const char *prefix, int no_checkout)
961
962
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
963
exit_if_skipped_commits(tried, current_bad_oid);
945
- printf("%s is the first bad commit\n", bisect_rev_hex);
964
+ printf("%s is the first %s commit\n", bisect_rev_hex,
965
+ term_bad);
966
show_diff_tree(prefix, revs.commits->item);
967
/* This means the bisection process succeeded. */
968
exit(10);
git-bisect.sh
+31
-26
@@ -32,6 +32,8 @@ OPTIONS_SPEC=
32
33
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
34
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
35
+TERM_BAD=bad
36
+TERM_GOOD=good
37
38
bisect_head()
39
{
@@ -100,8 +102,8 @@ bisect_start() {
102
break
103
}
104
case $bad_seen in
103
- 0) state='bad' ; bad_seen=1 ;;
104
- *) state='good' ;;
105
+ 0) state=$TERM_BAD ; bad_seen=1 ;;
106
+ *) state=$TERM_GOOD ;;
107
esac
108
eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
109
shift
@@ -184,9 +186,12 @@ bisect_write() {
186
rev="$2"
187
nolog="$3"
188
case "$state" in
187
- bad) tag="$state" ;;
188
- good|skip) tag="$state"-"$rev" ;;
189
- *) die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
189
+ "$TERM_BAD")
190
+ tag="$state" ;;
191
+ "$TERM_GOOD"|skip)
192
+ tag="$state"-"$rev" ;;
193
+ *)
194
+ die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
195
esac
196
git update-ref "refs/bisect/$tag" "$rev" || exit
197
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
@@ -230,12 +235,12 @@ bisect_state() {
235
case "$#,$state" in
236
0,*)
237
die "$(gettext "Please call 'bisect_state' with at least one argument.")" ;;
233
- 1,bad|1,good|1,skip)
238
+ 1,"$TERM_BAD"|1,"$TERM_GOOD"|1,skip)
239
rev=$(git rev-parse --verify $(bisect_head)) ||
240
die "$(gettext "Bad rev input: $(bisect_head)")"
241
bisect_write "$state" "$rev"
242
check_expected_revs "$rev" ;;
238
- 2,bad|*,good|*,skip)
243
+ 2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip)
244
shift
245
hash_list=''
246
for rev in "$@"
@@ -249,8 +254,8 @@ bisect_state() {
254
bisect_write "$state" "$rev"
255
done
256
check_expected_revs $hash_list ;;
252
- *,bad)
253
- die "$(gettext "'git bisect bad' can take only one argument.")" ;;
257
+ *,"$TERM_BAD")
258
+ die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;;
259
*)
260
usage ;;
261
esac
@@ -259,21 +264,21 @@ bisect_state() {
264
265
bisect_next_check() {
266
missing_good= missing_bad=
262
- git show-ref -q --verify refs/bisect/bad || missing_bad=t
263
- test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
267
+ git show-ref -q --verify refs/bisect/$TERM_BAD || missing_bad=t
268
+ test -n "$(git for-each-ref "refs/bisect/$TERM_GOOD-*")" || missing_good=t
269
270
case "$missing_good,$missing_bad,$1" in
271
,,*)
267
- : have both good and bad - ok
272
+ : have both $TERM_GOOD and $TERM_BAD - ok
273
;;
274
*,)
275
# do not have both but not asked to fail - just report.
276
false
277
;;
273
- t,,good)
278
+ t,,"$TERM_GOOD")
279
# have bad but not good. we could bisect although
280
# this is less optimum.
276
- gettextln "Warning: bisecting only with a bad commit." >&2
281
+ eval_gettextln "Warning: bisecting only with a \$TERM_BAD commit." >&2
282
if test -t 0
283
then
284
# TRANSLATORS: Make sure to include [Y] and [n] in your
@@ -283,7 +288,7 @@ bisect_next_check() {
288
read yesno
289
case "$yesno" in [Nn]*) exit 1 ;; esac
290
fi
286
- : bisect without good...
291
+ : bisect without $TERM_GOOD...
292
;;
293
*)
294
@@ -307,7 +312,7 @@ bisect_auto_next() {
312
bisect_next() {
313
case "$#" in 0) ;; *) usage ;; esac
314
bisect_autostart
310
- bisect_next_check good
315
+ bisect_next_check $TERM_GOOD
316
317
# Perform all bisection computation, display and checkout
318
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
@@ -316,18 +321,18 @@ bisect_next() {
321
# Check if we should exit because bisection is finished
322
if test $res -eq 10
323
then
319
- bad_rev=$(git show-ref --hash --verify refs/bisect/bad)
324
+ bad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD)
325
bad_commit=$(git show-branch $bad_rev)
321
- echo "# first bad commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
326
+ echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
327
exit 0
328
elif test $res -eq 2
329
then
330
echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG"
326
- good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/good-*")
327
- for skipped in $(git rev-list refs/bisect/bad --not $good_revs)
331
+ good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*")
332
+ for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs)
333
do
334
skipped_commit=$(git show-branch $skipped)
330
- echo "# possible first bad commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG"
335
+ echo "# possible first $TERM_BAD commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG"
336
done
337
exit $res
338
fi
@@ -421,7 +426,7 @@ bisect_replay () {
426
start)
427
cmd="bisect_start $rev"
428
eval "$cmd" ;;
424
- good|bad|skip)
429
+ $TERM_GOOD|$TERM_BAD|skip)
430
bisect_write "$command" "$rev" ;;
431
*)
432
die "$(gettext "?? what are you talking about?")" ;;
@@ -455,9 +460,9 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
460
state='skip'
461
elif [ $res -gt 0 ]
462
then
458
- state='bad'
463
+ state="$TERM_BAD"
464
else
460
- state='good'
465
+ state="$TERM_GOOD"
466
fi
467
468
# We have to use a subshell because "bisect_state" can exit.
@@ -466,7 +471,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
471
472
cat "$GIT_DIR/BISECT_RUN"
473
469
- if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
474
+ if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \
475
>/dev/null
476
then
477
gettextln "bisect run cannot continue any more" >&2
@@ -480,7 +485,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
485
exit $res
486
fi
487
483
- if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" >/dev/null
488
+ if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null
489
then
490
gettextln "bisect run success"
491
exit 0;