mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
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
This commit is contained in:
commit
71cc60070f
@ -3,7 +3,7 @@ git-bisect(1)
|
||||
|
||||
NAME
|
||||
----
|
||||
git-bisect - Find by binary search the change that introduced a bug
|
||||
git-bisect - Use binary search to find the commit that introduced a bug
|
||||
|
||||
|
||||
SYNOPSIS
|
||||
@ -16,7 +16,6 @@ DESCRIPTION
|
||||
The command takes various subcommands, and different options depending
|
||||
on the subcommand:
|
||||
|
||||
git bisect help
|
||||
git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]
|
||||
git bisect bad [<rev>]
|
||||
git bisect good [<rev>...]
|
||||
@ -26,64 +25,71 @@ on the subcommand:
|
||||
git bisect replay <logfile>
|
||||
git bisect log
|
||||
git bisect run <cmd>...
|
||||
git bisect help
|
||||
|
||||
This command uses 'git rev-list --bisect' to help drive the
|
||||
binary search process to find which change introduced a bug, given an
|
||||
old "good" commit object name and a later "bad" commit object name.
|
||||
|
||||
Getting help
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Use "git bisect" to get a short usage description, and "git bisect
|
||||
help" or "git bisect -h" to get a long usage description.
|
||||
This command uses a binary search algorithm to find which commit in
|
||||
your project's history introduced a bug. You use it by first telling
|
||||
it a "bad" commit that is known to contain the bug, and a "good"
|
||||
commit that is known to be before the bug was introduced. Then `git
|
||||
bisect` picks a commit between those two endpoints and asks you
|
||||
whether the selected commit is "good" or "bad". It continues narrowing
|
||||
down the range until it finds the exact commit that introduced the
|
||||
change.
|
||||
|
||||
Basic bisect commands: start, bad, good
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Using the Linux kernel tree as an example, basic use of the bisect
|
||||
command is as follows:
|
||||
As an example, suppose you are trying to find the commit that broke a
|
||||
feature that was known to work in version `v2.6.13-rc2` of your
|
||||
project. You start a bisect session as follows:
|
||||
|
||||
------------------------------------------------
|
||||
$ git bisect start
|
||||
$ git bisect bad # Current version is bad
|
||||
$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 was the last version
|
||||
# tested that was good
|
||||
$ git bisect good v2.6.13-rc2 # v2.6.13-rc2 is known to be good
|
||||
------------------------------------------------
|
||||
|
||||
When you have specified at least one bad and one good version, the
|
||||
command bisects the revision tree and outputs something similar to
|
||||
the following:
|
||||
Once you have specified at least one bad and one good commit, `git
|
||||
bisect` selects a commit in the middle of that range of history,
|
||||
checks it out, and outputs something similar to the following:
|
||||
|
||||
------------------------------------------------
|
||||
Bisecting: 675 revisions left to test after this
|
||||
Bisecting: 675 revisions left to test after this (roughly 10 steps)
|
||||
------------------------------------------------
|
||||
|
||||
The state in the middle of the set of revisions is then checked out.
|
||||
You would now compile that kernel and boot it. If the booted kernel
|
||||
works correctly, you would then issue the following command:
|
||||
You should now compile the checked-out version and test it. If that
|
||||
version works correctly, type
|
||||
|
||||
------------------------------------------------
|
||||
$ git bisect good # this one is good
|
||||
$ git bisect good
|
||||
------------------------------------------------
|
||||
|
||||
The output of this command would be something similar to the following:
|
||||
If that version is broken, type
|
||||
|
||||
------------------------------------------------
|
||||
Bisecting: 337 revisions left to test after this
|
||||
$ git bisect bad
|
||||
------------------------------------------------
|
||||
|
||||
You keep repeating this process, compiling the tree, testing it, and
|
||||
depending on whether it is good or bad issuing the command "git bisect good"
|
||||
or "git bisect bad" to ask for the next bisection.
|
||||
Then `git bisect` will respond with something like
|
||||
|
||||
------------------------------------------------
|
||||
Bisecting: 337 revisions left to test after this (roughly 9 steps)
|
||||
------------------------------------------------
|
||||
|
||||
Keep repeating the process: compile the tree, test it, and depending
|
||||
on whether it is good or bad run `git bisect good` or `git bisect bad`
|
||||
to ask for the next commit that needs testing.
|
||||
|
||||
Eventually there will be no more revisions left to inspect, and the
|
||||
command will print out a description of the first bad commit. The
|
||||
reference `refs/bisect/bad` will be left pointing at that commit.
|
||||
|
||||
Eventually there will be no more revisions left to bisect, and you
|
||||
will have been left with the first bad kernel revision in "refs/bisect/bad".
|
||||
|
||||
Bisect reset
|
||||
~~~~~~~~~~~~
|
||||
|
||||
After a bisect session, to clean up the bisection state and return to
|
||||
the original HEAD (i.e., to quit bisecting), issue the following command:
|
||||
the original HEAD, issue the following command:
|
||||
|
||||
------------------------------------------------
|
||||
$ git bisect reset
|
||||
@ -100,9 +106,10 @@ instead:
|
||||
$ git bisect reset <commit>
|
||||
------------------------------------------------
|
||||
|
||||
For example, `git bisect reset HEAD` will leave you on the current
|
||||
bisection commit and avoid switching commits at all, while `git bisect
|
||||
reset bisect/bad` will check out the first bad revision.
|
||||
For example, `git bisect reset bisect/bad` will check out the first
|
||||
bad revision, while `git bisect reset HEAD` will leave you on the
|
||||
current bisection commit and avoid switching commits at all.
|
||||
|
||||
|
||||
Bisect visualize
|
||||
~~~~~~~~~~~~~~~~
|
||||
@ -147,17 +154,17 @@ $ git bisect replay that-file
|
||||
Avoiding testing a commit
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If, in the middle of a bisect session, you know that the next suggested
|
||||
revision is not a good one to test (e.g. the change the commit
|
||||
introduces is known not to work in your environment and you know it
|
||||
does not have anything to do with the bug you are chasing), you may
|
||||
want to find a nearby commit and try that instead.
|
||||
If, in the middle of a bisect session, you know that the suggested
|
||||
revision is not a good one to test (e.g. it fails to build and you
|
||||
know that the failure does not have anything to do with the bug you
|
||||
are chasing), you can manually select a nearby commit and test that
|
||||
one instead.
|
||||
|
||||
For example:
|
||||
|
||||
------------
|
||||
$ git bisect good/bad # previous round was good or bad.
|
||||
Bisecting: 337 revisions left to test after this
|
||||
Bisecting: 337 revisions left to test after this (roughly 9 steps)
|
||||
$ git bisect visualize # oops, that is uninteresting.
|
||||
$ git reset --hard HEAD~3 # try 3 revisions before what
|
||||
# was suggested
|
||||
@ -169,18 +176,19 @@ the revision as good or bad in the usual manner.
|
||||
Bisect skip
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Instead of choosing by yourself a nearby commit, you can ask Git
|
||||
to do it for you by issuing the command:
|
||||
Instead of choosing a nearby commit by yourself, you can ask Git to do
|
||||
it for you by issuing the command:
|
||||
|
||||
------------
|
||||
$ git bisect skip # Current version cannot be tested
|
||||
------------
|
||||
|
||||
But Git may eventually be unable to tell the first bad commit among
|
||||
a bad commit and one or more skipped commits.
|
||||
However, if you skip a commit adjacent to the one you are looking for,
|
||||
Git will be unable to tell exactly which of those commits was the
|
||||
first bad one.
|
||||
|
||||
You can even skip a range of commits, instead of just one commit,
|
||||
using the "'<commit1>'..'<commit2>'" notation. For example:
|
||||
You can also skip a range of commits, instead of just one commit,
|
||||
using range notation. For example:
|
||||
|
||||
------------
|
||||
$ git bisect skip v2.5..v2.6
|
||||
@ -196,8 +204,8 @@ would issue the command:
|
||||
$ git bisect skip v2.5 v2.5..v2.6
|
||||
------------
|
||||
|
||||
This tells the bisect process that the commits between `v2.5` included
|
||||
and `v2.6` included should be skipped.
|
||||
This tells the bisect process that the commits between `v2.5` and
|
||||
`v2.6` (inclusive) should be skipped.
|
||||
|
||||
|
||||
Cutting down bisection by giving more parameters to bisect start
|
||||
@ -231,14 +239,14 @@ or bad, you can bisect by issuing the command:
|
||||
$ git bisect run my_script arguments
|
||||
------------
|
||||
|
||||
Note that the script (`my_script` in the above example) should
|
||||
exit with code 0 if the current source code is good, and exit with a
|
||||
code between 1 and 127 (inclusive), except 125, if the current
|
||||
source code is bad.
|
||||
Note that the script (`my_script` in the above example) should exit
|
||||
with code 0 if the current source code is good/old, and exit with a
|
||||
code between 1 and 127 (inclusive), except 125, if the current source
|
||||
code is bad/new.
|
||||
|
||||
Any other exit code will abort the bisect process. It should be noted
|
||||
that a program that terminates via "exit(-1)" leaves $? = 255, (see the
|
||||
exit(3) manual page), as the value is chopped with "& 0377".
|
||||
that a program that terminates via `exit(-1)` leaves $? = 255, (see the
|
||||
exit(3) manual page), as the value is chopped with `& 0377`.
|
||||
|
||||
The special exit code 125 should be used when the current source code
|
||||
cannot be tested. If the script exits with this code, the current
|
||||
@ -247,7 +255,7 @@ as the highest sensible value to use for this purpose, because 126 and 127
|
||||
are used by POSIX shells to signal specific error status (127 is for
|
||||
command not found, 126 is for command found but not executable---these
|
||||
details do not matter, as they are normal errors in the script, as far as
|
||||
"bisect run" is concerned).
|
||||
`bisect run` is concerned).
|
||||
|
||||
You may often find that during a bisect session you want to have
|
||||
temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
|
||||
@ -260,7 +268,7 @@ next revision to test, the script can apply the patch
|
||||
before compiling, run the real test, and afterwards decide if the
|
||||
revision (possibly with the needed patch) passed the test and then
|
||||
rewind the tree to the pristine state. Finally the script should exit
|
||||
with the status of the real test to let the "git bisect run" command loop
|
||||
with the status of the real test to let the `git bisect run` command loop
|
||||
determine the eventual outcome of the bisect session.
|
||||
|
||||
OPTIONS
|
||||
@ -307,12 +315,12 @@ $ git bisect run ~/test.sh
|
||||
$ git bisect reset # quit the bisect session
|
||||
------------
|
||||
+
|
||||
Here we use a "test.sh" custom script. In this script, if "make"
|
||||
Here we use a `test.sh` custom script. In this script, if `make`
|
||||
fails, we skip the current commit.
|
||||
"check_test_case.sh" should "exit 0" if the test case passes,
|
||||
and "exit 1" otherwise.
|
||||
`check_test_case.sh` should `exit 0` if the test case passes,
|
||||
and `exit 1` otherwise.
|
||||
+
|
||||
It is safer if both "test.sh" and "check_test_case.sh" are
|
||||
It is safer if both `test.sh` and `check_test_case.sh` are
|
||||
outside the repository to prevent interactions between the bisect,
|
||||
make and test processes and the scripts.
|
||||
|
||||
@ -379,6 +387,11 @@ In this case, when 'git bisect run' finishes, bisect/bad will refer to a commit
|
||||
has at least one parent whose reachable graph is fully traversable in the sense
|
||||
required by 'git pack objects'.
|
||||
|
||||
Getting help
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Use `git bisect` to get a short usage description, and `git bisect
|
||||
help` or `git bisect -h` to get a long usage description.
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
83
bisect.c
83
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))
|
||||
@ -889,6 +904,36 @@ static void show_diff_tree(const char *prefix, struct commit *commit)
|
||||
log_tree_commit(&opt, 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.
|
||||
@ -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);
|
||||
|
2
bisect.h
2
bisect.h
@ -26,4 +26,6 @@ extern int bisect_next_all(const char *prefix, int no_checkout);
|
||||
|
||||
extern int estimate_bisect_steps(int all);
|
||||
|
||||
extern void read_bisect_terms(const char **bad, const char **good);
|
||||
|
||||
#endif
|
||||
|
144
git-bisect.sh
144
git-bisect.sh
@ -32,6 +32,8 @@ OPTIONS_SPEC=
|
||||
|
||||
_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"
|
||||
TERM_BAD=bad
|
||||
TERM_GOOD=good
|
||||
|
||||
bisect_head()
|
||||
{
|
||||
@ -75,6 +77,8 @@ bisect_start() {
|
||||
orig_args=$(git rev-parse --sq-quote "$@")
|
||||
bad_seen=0
|
||||
eval=''
|
||||
must_write_terms=0
|
||||
revs=''
|
||||
if test "z$(git rev-parse --is-bare-repository)" != zfalse
|
||||
then
|
||||
mode=--no-checkout
|
||||
@ -99,16 +103,27 @@ bisect_start() {
|
||||
die "$(eval_gettext "'\$arg' does not appear to be a valid revision")"
|
||||
break
|
||||
}
|
||||
case $bad_seen in
|
||||
0) state='bad' ; bad_seen=1 ;;
|
||||
*) state='good' ;;
|
||||
esac
|
||||
eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
|
||||
revs="$revs $rev"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for rev in $revs
|
||||
do
|
||||
# The user ran "git bisect start <sha1>
|
||||
# <sha1>", hence did not explicitly specify
|
||||
# the terms, but we are already starting to
|
||||
# set references named with the default terms,
|
||||
# and won't be able to change afterwards.
|
||||
must_write_terms=1
|
||||
|
||||
case $bad_seen in
|
||||
0) state=$TERM_BAD ; bad_seen=1 ;;
|
||||
*) state=$TERM_GOOD ;;
|
||||
esac
|
||||
eval="$eval bisect_write '$state' '$rev' 'nolog' &&"
|
||||
done
|
||||
#
|
||||
# Verify HEAD.
|
||||
#
|
||||
@ -170,6 +185,10 @@ bisect_start() {
|
||||
} &&
|
||||
git rev-parse --sq-quote "$@" >"$GIT_DIR/BISECT_NAMES" &&
|
||||
eval "$eval true" &&
|
||||
if test $must_write_terms -eq 1
|
||||
then
|
||||
write_terms "$TERM_BAD" "$TERM_GOOD"
|
||||
fi &&
|
||||
echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
|
||||
#
|
||||
# Check if we can proceed to the next bisect state.
|
||||
@ -184,9 +203,12 @@ bisect_write() {
|
||||
rev="$2"
|
||||
nolog="$3"
|
||||
case "$state" in
|
||||
bad) tag="$state" ;;
|
||||
good|skip) tag="$state"-"$rev" ;;
|
||||
*) die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
|
||||
"$TERM_BAD")
|
||||
tag="$state" ;;
|
||||
"$TERM_GOOD"|skip)
|
||||
tag="$state"-"$rev" ;;
|
||||
*)
|
||||
die "$(eval_gettext "Bad bisect_write argument: \$state")" ;;
|
||||
esac
|
||||
git update-ref "refs/bisect/$tag" "$rev" || exit
|
||||
echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG"
|
||||
@ -227,15 +249,16 @@ bisect_skip() {
|
||||
bisect_state() {
|
||||
bisect_autostart
|
||||
state=$1
|
||||
check_and_set_terms $state
|
||||
case "$#,$state" in
|
||||
0,*)
|
||||
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)) ||
|
||||
die "$(gettext "Bad rev input: $(bisect_head)")"
|
||||
bisect_write "$state" "$rev"
|
||||
check_expected_revs "$rev" ;;
|
||||
2,bad|*,good|*,skip)
|
||||
2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip)
|
||||
shift
|
||||
hash_list=''
|
||||
for rev in "$@"
|
||||
@ -249,8 +272,8 @@ bisect_state() {
|
||||
bisect_write "$state" "$rev"
|
||||
done
|
||||
check_expected_revs $hash_list ;;
|
||||
*,bad)
|
||||
die "$(gettext "'git bisect bad' can take only one argument.")" ;;
|
||||
*,"$TERM_BAD")
|
||||
die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;;
|
||||
*)
|
||||
usage ;;
|
||||
esac
|
||||
@ -259,21 +282,21 @@ bisect_state() {
|
||||
|
||||
bisect_next_check() {
|
||||
missing_good= missing_bad=
|
||||
git show-ref -q --verify refs/bisect/bad || missing_bad=t
|
||||
test -n "$(git for-each-ref "refs/bisect/good-*")" || missing_good=t
|
||||
git show-ref -q --verify refs/bisect/$TERM_BAD || missing_bad=t
|
||||
test -n "$(git for-each-ref "refs/bisect/$TERM_GOOD-*")" || missing_good=t
|
||||
|
||||
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.
|
||||
false
|
||||
;;
|
||||
t,,good)
|
||||
t,,"$TERM_GOOD")
|
||||
# have bad but not good. we could bisect although
|
||||
# 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
|
||||
then
|
||||
# TRANSLATORS: Make sure to include [Y] and [n] in your
|
||||
@ -283,18 +306,20 @@ bisect_next_check() {
|
||||
read yesno
|
||||
case "$yesno" in [Nn]*) exit 1 ;; esac
|
||||
fi
|
||||
: bisect without good...
|
||||
: bisect without $TERM_GOOD...
|
||||
;;
|
||||
*)
|
||||
|
||||
bad_syn=$(bisect_voc bad)
|
||||
good_syn=$(bisect_voc good)
|
||||
if test -s "$GIT_DIR/BISECT_START"
|
||||
then
|
||||
gettextln "You need to give me at least one good and one bad revision.
|
||||
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
|
||||
|
||||
eval_gettextln "You need to give me at least one \$bad_syn and one \$good_syn revision.
|
||||
(You can use \"git bisect \$bad_syn\" and \"git bisect \$good_syn\" for that.)" >&2
|
||||
else
|
||||
gettextln "You need to start by \"git bisect start\".
|
||||
You then need to give me at least one good and one bad revision.
|
||||
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
|
||||
eval_gettextln "You need to start by \"git bisect start\".
|
||||
You then need to give me at least one \$good_syn and one \$bad_syn revision.
|
||||
(You can use \"git bisect \$bad_syn\" and \"git bisect \$good_syn\" for that.)" >&2
|
||||
fi
|
||||
exit 1 ;;
|
||||
esac
|
||||
@ -307,7 +332,7 @@ bisect_auto_next() {
|
||||
bisect_next() {
|
||||
case "$#" in 0) ;; *) usage ;; esac
|
||||
bisect_autostart
|
||||
bisect_next_check good
|
||||
bisect_next_check $TERM_GOOD
|
||||
|
||||
# Perform all bisection computation, display and checkout
|
||||
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
|
||||
@ -316,18 +341,18 @@ bisect_next() {
|
||||
# Check if we should exit because bisection is finished
|
||||
if test $res -eq 10
|
||||
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)
|
||||
echo "# first bad commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
|
||||
echo "# first $TERM_BAD commit: $bad_commit" >>"$GIT_DIR/BISECT_LOG"
|
||||
exit 0
|
||||
elif test $res -eq 2
|
||||
then
|
||||
echo "# only skipped commits left to test" >>"$GIT_DIR/BISECT_LOG"
|
||||
good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/good-*")
|
||||
for skipped in $(git rev-list refs/bisect/bad --not $good_revs)
|
||||
good_revs=$(git for-each-ref --format="%(objectname)" "refs/bisect/$TERM_GOOD-*")
|
||||
for skipped in $(git rev-list refs/bisect/$TERM_BAD --not $good_revs)
|
||||
do
|
||||
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
|
||||
exit $res
|
||||
fi
|
||||
@ -397,6 +422,7 @@ bisect_clean_state() {
|
||||
rm -f "$GIT_DIR/BISECT_LOG" &&
|
||||
rm -f "$GIT_DIR/BISECT_NAMES" &&
|
||||
rm -f "$GIT_DIR/BISECT_RUN" &&
|
||||
rm -f "$GIT_DIR/BISECT_TERMS" &&
|
||||
# Cleanup head-name if it got left by an old version of git-bisect
|
||||
rm -f "$GIT_DIR/head-name" &&
|
||||
git update-ref -d --no-deref BISECT_HEAD &&
|
||||
@ -417,11 +443,13 @@ bisect_replay () {
|
||||
rev="$command"
|
||||
command="$bisect"
|
||||
fi
|
||||
get_terms
|
||||
check_and_set_terms "$command"
|
||||
case "$command" in
|
||||
start)
|
||||
cmd="bisect_start $rev"
|
||||
eval "$cmd" ;;
|
||||
good|bad|skip)
|
||||
"$TERM_GOOD"|"$TERM_BAD"|skip)
|
||||
bisect_write "$command" "$rev" ;;
|
||||
*)
|
||||
die "$(gettext "?? what are you talking about?")" ;;
|
||||
@ -455,9 +483,9 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
|
||||
state='skip'
|
||||
elif [ $res -gt 0 ]
|
||||
then
|
||||
state='bad'
|
||||
state="$TERM_BAD"
|
||||
else
|
||||
state='good'
|
||||
state="$TERM_GOOD"
|
||||
fi
|
||||
|
||||
# We have to use a subshell because "bisect_state" can exit.
|
||||
@ -466,7 +494,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
|
||||
|
||||
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
|
||||
then
|
||||
gettextln "bisect run cannot continue any more" >&2
|
||||
@ -480,7 +508,7 @@ exit code \$res from '\$command' is < 0 or >= 128" >&2
|
||||
exit $res
|
||||
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
|
||||
gettextln "bisect run success"
|
||||
exit 0;
|
||||
@ -494,18 +522,62 @@ bisect_log () {
|
||||
cat "$GIT_DIR/BISECT_LOG"
|
||||
}
|
||||
|
||||
get_terms () {
|
||||
if test -s "$GIT_DIR/BISECT_TERMS"
|
||||
then
|
||||
{
|
||||
read TERM_BAD
|
||||
read TERM_GOOD
|
||||
} <"$GIT_DIR/BISECT_TERMS"
|
||||
fi
|
||||
}
|
||||
|
||||
write_terms () {
|
||||
TERM_BAD=$1
|
||||
TERM_GOOD=$2
|
||||
printf '%s\n%s\n' "$TERM_BAD" "$TERM_GOOD" >"$GIT_DIR/BISECT_TERMS"
|
||||
}
|
||||
|
||||
check_and_set_terms () {
|
||||
cmd="$1"
|
||||
case "$cmd" in
|
||||
skip|start|terms) ;;
|
||||
*)
|
||||
if test -s "$GIT_DIR/BISECT_TERMS" && test "$cmd" != "$TERM_BAD" && test "$cmd" != "$TERM_GOOD"
|
||||
then
|
||||
die "$(eval_gettext "Invalid command: you're currently in a \$TERM_BAD/\$TERM_GOOD bisect.")"
|
||||
fi
|
||||
case "$cmd" in
|
||||
bad|good)
|
||||
if ! test -s "$GIT_DIR/BISECT_TERMS"
|
||||
then
|
||||
write_terms bad good
|
||||
fi
|
||||
;;
|
||||
esac ;;
|
||||
esac
|
||||
}
|
||||
|
||||
bisect_voc () {
|
||||
case "$1" in
|
||||
bad) echo "bad" ;;
|
||||
good) echo "good" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$#" in
|
||||
0)
|
||||
usage ;;
|
||||
*)
|
||||
cmd="$1"
|
||||
get_terms
|
||||
shift
|
||||
case "$cmd" in
|
||||
help)
|
||||
git bisect -h ;;
|
||||
start)
|
||||
bisect_start "$@" ;;
|
||||
bad|good)
|
||||
bad|good|"$TERM_BAD"|"$TERM_GOOD")
|
||||
bisect_state "$cmd" "$@" ;;
|
||||
skip)
|
||||
bisect_skip "$@" ;;
|
||||
|
18
revision.c
18
revision.c
@ -18,9 +18,13 @@
|
||||
#include "commit-slab.h"
|
||||
#include "dir.h"
|
||||
#include "cache-tree.h"
|
||||
#include "bisect.h"
|
||||
|
||||
volatile show_early_output_fn_t show_early_output;
|
||||
|
||||
static const char *term_bad;
|
||||
static const char *term_good;
|
||||
|
||||
char *path_name(const struct name_path *path, const char *name)
|
||||
{
|
||||
const struct name_path *p;
|
||||
@ -2076,14 +2080,23 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
|
||||
ctx->argc -= n;
|
||||
}
|
||||
|
||||
static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data, const char *term) {
|
||||
struct strbuf bisect_refs = STRBUF_INIT;
|
||||
int status;
|
||||
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
|
||||
status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
|
||||
strbuf_release(&bisect_refs);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
|
||||
{
|
||||
return for_each_ref_in_submodule(submodule, "refs/bisect/bad", fn, cb_data);
|
||||
return for_each_bisect_ref(submodule, fn, cb_data, term_bad);
|
||||
}
|
||||
|
||||
static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
|
||||
{
|
||||
return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
|
||||
return for_each_bisect_ref(submodule, fn, cb_data, term_good);
|
||||
}
|
||||
|
||||
static int handle_revision_pseudo_opt(const char *submodule,
|
||||
@ -2112,6 +2125,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
|
||||
handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
|
||||
clear_ref_exclusion(&revs->ref_excludes);
|
||||
} else if (!strcmp(arg, "--bisect")) {
|
||||
read_bisect_terms(&term_bad, &term_good);
|
||||
handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
|
||||
handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);
|
||||
revs->bisect = 1;
|
||||
|
@ -362,7 +362,7 @@ test_expect_success 'bisect starting with a detached HEAD' '
|
||||
test_expect_success 'bisect errors out if bad and good are mistaken' '
|
||||
git bisect reset &&
|
||||
test_must_fail git bisect start $HASH2 $HASH4 2> rev_list_error &&
|
||||
grep "mistake good and bad" rev_list_error &&
|
||||
grep "mistook good and bad" rev_list_error &&
|
||||
git bisect reset
|
||||
'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user