Skip to content

Commit 0871984

Browse files
chriscoolgitster
authored andcommitted
bisect: make "git bisect" use new "--next-all" bisect-helper function
This patch replace the "--next-exit" option of "git bisect--helper" with a "--next-all" option that does merge base checking using the "check_good_are_ancestors_of_bad" function implemented in "bisect.c" in a former patch. The new "--next-all" option is then used in "git-bisect.sh" instead of the "--next-exit" option, and all the shell functions in "git-bisect.sh" that are now unused are removed. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d937d4a commit 0871984

File tree

4 files changed

+13
-134
lines changed

4 files changed

+13
-134
lines changed

bisect.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
830830
* the bisection process finished successfully.
831831
* In this case the calling shell script should exit 0.
832832
*/
833-
int bisect_next_exit(const char *prefix)
833+
int bisect_next_all(const char *prefix)
834834
{
835835
struct rev_info revs;
836836
struct commit_list *tried;
@@ -841,6 +841,8 @@ int bisect_next_exit(const char *prefix)
841841
if (read_bisect_refs())
842842
die("reading bisect refs failed");
843843

844+
check_good_are_ancestors_of_bad(prefix);
845+
844846
bisect_rev_setup(&revs, prefix);
845847

846848
bisect_common(&revs, &reaches, &all);

bisect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct rev_list_info {
2727

2828
extern int show_bisect_vars(struct rev_list_info *info, int reaches, int all);
2929

30-
extern int bisect_next_exit(const char *prefix);
30+
extern int bisect_next_all(const char *prefix);
3131

3232
extern int estimate_bisect_steps(int all);
3333

builtin-bisect--helper.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
#include "bisect.h"
55

66
static const char * const git_bisect_helper_usage[] = {
7-
"git bisect--helper --next-exit",
7+
"git bisect--helper --next-all",
88
NULL
99
};
1010

1111
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1212
{
13-
int next_exit = 0;
13+
int next_all = 0;
1414
struct option options[] = {
15-
OPT_BOOLEAN(0, "next-exit", &next_exit,
16-
"output bisect result and exit instuctions"),
15+
OPT_BOOLEAN(0, "next-all", &next_all,
16+
"perform 'git bisect next'"),
1717
OPT_END()
1818
};
1919

2020
argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0);
2121

22-
if (!next_exit)
22+
if (!next_all)
2323
usage_with_options(git_bisect_helper_usage, options);
2424

25-
/* next-exit */
26-
return bisect_next_exit(prefix);
25+
/* next-all */
26+
return bisect_next_all(prefix);
2727
}

git-bisect.sh

Lines changed: 2 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ is_expected_rev() {
167167
test "$1" = $(cat "$GIT_DIR/BISECT_EXPECTED_REV")
168168
}
169169

170-
mark_expected_rev() {
171-
echo "$1" > "$GIT_DIR/BISECT_EXPECTED_REV"
172-
}
173-
174170
check_expected_revs() {
175171
for _rev in "$@"; do
176172
if ! is_expected_rev "$_rev"; then
@@ -269,132 +265,13 @@ bisect_auto_next() {
269265
bisect_next_check && bisect_next || :
270266
}
271267

272-
bisect_checkout() {
273-
_rev="$1"
274-
_msg="$2"
275-
echo "Bisecting: $_msg"
276-
mark_expected_rev "$_rev"
277-
git checkout -q "$_rev" -- || exit
278-
git show-branch "$_rev"
279-
}
280-
281-
is_among() {
282-
_rev="$1"
283-
_list="$2"
284-
case "$_list" in *$_rev*) return 0 ;; esac
285-
return 1
286-
}
287-
288-
handle_bad_merge_base() {
289-
_badmb="$1"
290-
_good="$2"
291-
if is_expected_rev "$_badmb"; then
292-
cat >&2 <<EOF
293-
The merge base $_badmb is bad.
294-
This means the bug has been fixed between $_badmb and [$_good].
295-
EOF
296-
exit 3
297-
else
298-
cat >&2 <<EOF
299-
Some good revs are not ancestor of the bad rev.
300-
git bisect cannot work properly in this case.
301-
Maybe you mistake good and bad revs?
302-
EOF
303-
exit 1
304-
fi
305-
}
306-
307-
handle_skipped_merge_base() {
308-
_mb="$1"
309-
_bad="$2"
310-
_good="$3"
311-
cat >&2 <<EOF
312-
Warning: the merge base between $_bad and [$_good] must be skipped.
313-
So we cannot be sure the first bad commit is between $_mb and $_bad.
314-
We continue anyway.
315-
EOF
316-
}
317-
318-
#
319-
# "check_merge_bases" checks that merge bases are not "bad".
320-
#
321-
# - If one is "good", that's good, we have nothing to do.
322-
# - If one is "bad", it means the user assumed something wrong
323-
# and we must exit.
324-
# - If one is "skipped", we can't know but we should warn.
325-
# - If we don't know, we should check it out and ask the user to test.
326-
#
327-
# In the last case we will return 1, and otherwise 0.
328-
#
329-
check_merge_bases() {
330-
_bad="$1"
331-
_good="$2"
332-
_skip="$3"
333-
for _mb in $(git merge-base --all $_bad $_good)
334-
do
335-
if is_among "$_mb" "$_good"; then
336-
continue
337-
elif test "$_mb" = "$_bad"; then
338-
handle_bad_merge_base "$_bad" "$_good"
339-
elif is_among "$_mb" "$_skip"; then
340-
handle_skipped_merge_base "$_mb" "$_bad" "$_good"
341-
else
342-
bisect_checkout "$_mb" "a merge base must be tested"
343-
return 1
344-
fi
345-
done
346-
return 0
347-
}
348-
349-
#
350-
# "check_good_are_ancestors_of_bad" checks that all "good" revs are
351-
# ancestor of the "bad" rev.
352-
#
353-
# If that's not the case, we need to check the merge bases.
354-
# If a merge base must be tested by the user we return 1 and
355-
# otherwise 0.
356-
#
357-
check_good_are_ancestors_of_bad() {
358-
test -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
359-
return
360-
361-
_bad="$1"
362-
_good=$(echo $2 | sed -e 's/\^//g')
363-
_skip="$3"
364-
365-
# Bisecting with no good rev is ok
366-
test -z "$_good" && return
367-
368-
_side=$(git rev-list $_good ^$_bad)
369-
if test -n "$_side"; then
370-
# Return if a checkout was done
371-
check_merge_bases "$_bad" "$_good" "$_skip" || return
372-
fi
373-
374-
: > "$GIT_DIR/BISECT_ANCESTORS_OK"
375-
376-
return 0
377-
}
378-
379268
bisect_next() {
380269
case "$#" in 0) ;; *) usage ;; esac
381270
bisect_autostart
382271
bisect_next_check good
383272

384-
# Get bad, good and skipped revs
385-
bad=$(git rev-parse --verify refs/bisect/bad) &&
386-
good=$(git for-each-ref --format='^%(objectname)' \
387-
"refs/bisect/good-*" | tr '\012' ' ') &&
388-
skip=$(git for-each-ref --format='%(objectname)' \
389-
"refs/bisect/skip-*" | tr '\012' ' ') || exit
390-
391-
# Maybe some merge bases must be tested first
392-
check_good_are_ancestors_of_bad "$bad" "$good" "$skip"
393-
# Return now if a checkout has already been done
394-
test "$?" -eq "1" && return
395-
396-
# Perform bisection computation, display and checkout
397-
git bisect--helper --next-exit
273+
# Perform all bisection computation, display and checkout
274+
git bisect--helper --next-all
398275
res=$?
399276

400277
# Check if we should exit because bisection is finished

0 commit comments

Comments
 (0)