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>maint
parent
2df5a846d0
commit
43f9d9f3a6
46
bisect.c
46
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_show_branch[] = {"show-branch", NULL, NULL};
|
||||||
static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", 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 */
|
/* Remember to update object flag allocation in object.h */
|
||||||
#define COUNTED (1u<<16)
|
#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,
|
static int register_ref(const char *refname, const struct object_id *oid,
|
||||||
int flags, void *cb_data)
|
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));
|
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
|
||||||
oidcpy(current_bad_oid, 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);
|
sha1_array_append(&good_revs, oid->hash);
|
||||||
} else if (starts_with(refname, "skip-")) {
|
} else if (starts_with(refname, "skip-")) {
|
||||||
sha1_array_append(&skipped_revs, oid->hash);
|
sha1_array_append(&skipped_revs, oid->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strbuf_release(&good_prefix);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,7 +643,7 @@ static void exit_if_skipped_commits(struct commit_list *tried,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("There are only 'skip'ped commits left to test.\n"
|
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");
|
print_commit_list(tried, "%s\n", "%s\n");
|
||||||
if (bad)
|
if (bad)
|
||||||
printf("%s\n", oid_to_hex(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)) {
|
if (is_expected_rev(current_bad_oid)) {
|
||||||
char *bad_hex = oid_to_hex(current_bad_oid);
|
char *bad_hex = oid_to_hex(current_bad_oid);
|
||||||
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
|
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
|
||||||
|
if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) {
|
||||||
fprintf(stderr, "The merge base %s is bad.\n"
|
fprintf(stderr, "The merge base %s is bad.\n"
|
||||||
"This means the bug has been fixed "
|
"This means the bug has been fixed "
|
||||||
"between %s and [%s].\n",
|
"between %s and [%s].\n",
|
||||||
bad_hex, bad_hex, good_hex);
|
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);
|
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"
|
"git bisect cannot work properly in this case.\n"
|
||||||
"Maybe you mistook good and bad revs?\n");
|
"Maybe you mistook %s and %s revs?\n",
|
||||||
|
term_good, term_bad, term_good, term_bad);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,10 +770,10 @@ static void handle_skipped_merge_base(const unsigned char *mb)
|
||||||
|
|
||||||
warning("the merge base between %s and [%s] "
|
warning("the merge base between %s and [%s] "
|
||||||
"must be skipped.\n"
|
"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"
|
"between %s and %s.\n"
|
||||||
"We continue anyway.",
|
"We continue anyway.",
|
||||||
bad_hex, good_hex, mb_hex, bad_hex);
|
bad_hex, good_hex, term_bad, mb_hex, bad_hex);
|
||||||
free(good_hex);
|
free(good_hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,7 +854,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (!current_bad_oid)
|
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. */
|
/* Check if file BISECT_ANCESTORS_OK exists. */
|
||||||
if (!stat(filename, &st) && S_ISREG(st.st_mode))
|
if (!stat(filename, &st) && S_ISREG(st.st_mode))
|
||||||
|
@ -905,6 +920,8 @@ int bisect_next_all(const char *prefix, int no_checkout)
|
||||||
const unsigned char *bisect_rev;
|
const unsigned char *bisect_rev;
|
||||||
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
|
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
|
||||||
|
|
||||||
|
term_bad = "bad";
|
||||||
|
term_good = "good";
|
||||||
if (read_bisect_refs())
|
if (read_bisect_refs())
|
||||||
die("reading bisect refs failed");
|
die("reading bisect refs failed");
|
||||||
|
|
||||||
|
@ -926,8 +943,10 @@ int bisect_next_all(const char *prefix, int no_checkout)
|
||||||
*/
|
*/
|
||||||
exit_if_skipped_commits(tried, NULL);
|
exit_if_skipped_commits(tried, NULL);
|
||||||
|
|
||||||
printf("%s was both good and bad\n",
|
printf("%s was both %s and %s\n",
|
||||||
oid_to_hex(current_bad_oid));
|
oid_to_hex(current_bad_oid),
|
||||||
|
term_good,
|
||||||
|
term_bad);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -942,7 +961,8 @@ int bisect_next_all(const char *prefix, int no_checkout)
|
||||||
|
|
||||||
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
|
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
|
||||||
exit_if_skipped_commits(tried, current_bad_oid);
|
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);
|
show_diff_tree(prefix, revs.commits->item);
|
||||||
/* This means the bisection process succeeded. */
|
/* This means the bisection process succeeded. */
|
||||||
exit(10);
|
exit(10);
|
||||||
|
|
|
@ -32,6 +32,8 @@ OPTIONS_SPEC=
|
||||||
|
|
||||||
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
||||||
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
|
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
|
||||||
|
TERM_BAD=bad
|
||||||
|
TERM_GOOD=good
|
||||||
|
|
||||||
bisect_head()
|
bisect_head()
|
||||||
{
|
{
|
||||||
|
@ -100,8 +102,8 @@ bisect_start() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case $bad_seen in
|
case $bad_seen in
|
||||||
0) state='bad' ; bad_seen=1 ;;
|
0) state=$TERM_BAD ; bad_seen=1 ;;
|
||||||
*) state='good' ;;
|
*) state=$TERM_GOOD ;;
|
||||||
esac
|
esac
|
||||||
eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
|
eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
|
||||||
shift
|
shift
|
||||||
|
@ -184,9 +186,12 @@ bisect_write() {
|
||||||
rev="$2"
|
rev="$2"
|
||||||
nolog="$3"
|
nolog="$3"
|
||||||
case "$state" in
|
case "$state" in
|
||||||
bad) tag="$state" ;;
|
"$TERM_BAD")
|
||||||
good|skip) tag="$state"-"$rev" ;;
|
tag="$state" ;;
|
||||||
*) die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
|
"$TERM_GOOD"|skip)
|
||||||
|
tag="$state"-"$rev" ;;
|
||||||
|
*)
|
||||||
|
die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
|
||||||
esac
|
esac
|
||||||
git update-ref "refs/bisect/$tag" "$rev" || exit
|
git update-ref "refs/bisect/$tag" "$rev" || exit
|
||||||
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
|
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
|
||||||
|
@ -230,12 +235,12 @@ bisect_state() {
|
||||||
case "$#,$state" in
|
case "$#,$state" in
|
||||||
0,*)
|
0,*)
|
||||||
die "$(gettext "Please call 'bisect_state' with at least one argument.")" ;;
|
die "$(gettext "Please call 'bisect_state' with at least one argument.")" ;;
|
||||||
1,bad|1,good|1,skip)
|
1,"$TERM_BAD"|1,"$TERM_GOOD"|1,skip)
|
||||||
rev=$(git rev-parse --verify $(bisect_head)) ||
|
rev=$(git rev-parse --verify $(bisect_head)) ||
|
||||||
die "$(gettext "Bad rev input: $(bisect_head)")"
|
die "$(gettext "Bad rev input: $(bisect_head)")"
|
||||||
bisect_write "$state" "$rev"
|
bisect_write "$state" "$rev"
|
||||||
check_expected_revs "$rev" ;;
|
check_expected_revs "$rev" ;;
|
||||||
2,bad|*,good|*,skip)
|
2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip)
|
||||||
shift
|
shift
|
||||||
hash_list=''
|
hash_list=''
|
||||||
for rev in "$@"
|
for rev in "$@"
|
||||||
|
@ -249,8 +254,8 @@ bisect_state() {
|
||||||
bisect_write "$state" "$rev"
|
bisect_write "$state" "$rev"
|
||||||
done
|
done
|
||||||
check_expected_revs $hash_list ;;
|
check_expected_revs $hash_list ;;
|
||||||
*,bad)
|
*,"$TERM_BAD")
|
||||||
die "$(gettext "'git bisect bad' can take only one argument.")" ;;
|
die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;;
|
||||||
*)
|
*)
|
||||||
usage ;;
|
usage ;;
|
||||||
esac
|
esac
|
||||||
|
@ -259,21 +264,21 @@ bisect_state() {
|
||||||
|
|
||||||
bisect_next_check() {
|
bisect_next_check() {
|
||||||
missing_good= missing_bad=
|
missing_good= missing_bad=
|
||||||
git show-ref -q --verify refs/bisect/bad || missing_bad=t
|
git show-ref -q --verify refs/bisect/$TERM_BAD || missing_bad=t
|
||||||
test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
|
test -n "$(git for-each-ref "refs/bisect/$TERM_GOOD-*")" || missing_good=t
|
||||||
|
|
||||||
case "$missing_good,$missing_bad,$1" in
|
case "$missing_good,$missing_bad,$1" in
|
||||||
,,*)
|
,,*)
|
||||||
: have both good and bad - ok
|
: have both $TERM_GOOD and $TERM_BAD - ok
|
||||||
;;
|
;;
|
||||||
*,)
|
*,)
|
||||||
# do not have both but not asked to fail - just report.
|
# do not have both but not asked to fail - just report.
|
||||||
false
|
false
|
||||||
;;
|
;;
|
||||||
t,,good)
|
t,,"$TERM_GOOD")
|
||||||
# have bad but not good. we could bisect although
|
# have bad but not good. we could bisect although
|
||||||
# this is less optimum.
|
# this is less optimum.
|
||||||
gettextln "Warning: bisecting only with a bad commit." >&2
|
eval_gettextln "Warning: bisecting only with a \$TERM_BAD commit." >&2
|
||||||
if test -t 0
|
if test -t 0
|
||||||
then
|
then
|
||||||
# TRANSLATORS: Make sure to include [Y] and [n] in your
|
# TRANSLATORS: Make sure to include [Y] and [n] in your
|
||||||
|
@ -283,7 +288,7 @@ bisect_next_check() {
|
||||||
read yesno
|
read yesno
|
||||||
case "$yesno" in [Nn]*) exit 1 ;; esac
|
case "$yesno" in [Nn]*) exit 1 ;; esac
|
||||||
fi
|
fi
|
||||||
: bisect without good...
|
: bisect without $TERM_GOOD...
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
@ -307,7 +312,7 @@ bisect_auto_next() {
|
||||||
bisect_next() {
|
bisect_next() {
|
||||||
case "$#" in 0) ;; *) usage ;; esac
|
case "$#" in 0) ;; *) usage ;; esac
|
||||||
bisect_autostart
|
bisect_autostart
|
||||||
bisect_next_check good
|
bisect_next_check $TERM_GOOD
|
||||||
|
|
||||||
# Perform all bisection computation, display and checkout
|
# Perform all bisection computation, display and checkout
|
||||||
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
|
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
|
||||||
|
@ -316,18 +321,18 @@ bisect_next() {
|
||||||
# Check if we should exit because bisection is finished
|
# Check if we should exit because bisection is finished
|
||||||
if test $res -eq 10
|
if test $res -eq 10
|
||||||
then
|
then
|
||||||
bad_rev=$(git show-ref --hash --verify refs/bisect/bad)
|
bad_rev=$(git show-ref --hash --verify refs/bisect/$TERM_BAD)
|
||||||
bad_commit=$(git show-branch $bad_rev)
|
bad_commit=$(git show-branch $bad_rev)
|
||||||
echo "# first bad commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
|
echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
|
||||||
exit 0
|
exit 0
|
||||||
elif test $res -eq 2
|
elif test $res -eq 2
|
||||||
then
|
then
|
||||||
echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG"
|
echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG"
|
||||||
good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/good-*")
|
good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*")
|
||||||
for skipped in $(git rev-list refs/bisect/bad --not $good_revs)
|
for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs)
|
||||||
do
|
do
|
||||||
skipped_commit=$(git show-branch $skipped)
|
skipped_commit=$(git show-branch $skipped)
|
||||||
echo "# possible first bad commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG"
|
echo "# possible first $TERM_BAD commit: $skipped_commit" >>"$GIT_DIR/BISECT_LOG"
|
||||||
done
|
done
|
||||||
exit $res
|
exit $res
|
||||||
fi
|
fi
|
||||||
|
@ -421,7 +426,7 @@ bisect_replay () {
|
||||||
start)
|
start)
|
||||||
cmd="bisect_start $rev"
|
cmd="bisect_start $rev"
|
||||||
eval "$cmd" ;;
|
eval "$cmd" ;;
|
||||||
good|bad|skip)
|
$TERM_GOOD|$TERM_BAD|skip)
|
||||||
bisect_write "$command" "$rev" ;;
|
bisect_write "$command" "$rev" ;;
|
||||||
*)
|
*)
|
||||||
die "$(gettext "?? what are you talking about?")" ;;
|
die "$(gettext "?? what are you talking about?")" ;;
|
||||||
|
@ -455,9 +460,9 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
|
||||||
state='skip'
|
state='skip'
|
||||||
elif [ $res -gt 0 ]
|
elif [ $res -gt 0 ]
|
||||||
then
|
then
|
||||||
state='bad'
|
state="$TERM_BAD"
|
||||||
else
|
else
|
||||||
state='good'
|
state="$TERM_GOOD"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# We have to use a subshell because "bisect_state" can exit.
|
# 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
|
||||||
|
|
||||||
cat "$GIT_DIR/BISECT_RUN"
|
cat "$GIT_DIR/BISECT_RUN"
|
||||||
|
|
||||||
if sane_grep "first bad commit could be any of" "$GIT_DIR/BISECT_RUN" \
|
if sane_grep "first $TERM_BAD commit could be any of" "$GIT_DIR/BISECT_RUN" \
|
||||||
>/dev/null
|
>/dev/null
|
||||||
then
|
then
|
||||||
gettextln "bisect run cannot continue any more" >&2
|
gettextln "bisect run cannot continue any more" >&2
|
||||||
|
@ -480,7 +485,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
|
||||||
exit $res
|
exit $res
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if sane_grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" >/dev/null
|
if sane_grep "is the first $TERM_BAD commit" "$GIT_DIR/BISECT_RUN" >/dev/null
|
||||||
then
|
then
|
||||||
gettextln "bisect run success"
|
gettextln "bisect run success"
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
Loading…
Reference in New Issue