Skip to content

Commit 2d938fc

Browse files
chriscoolgitster
authored andcommitted
bisect: check ancestors without forking a "git rev-list" process
We must save the pending commits that will be used during revision walking and unparse them after, because we want to leave a clean state for the next revision walking that will try to find the best bisection point. As we don't fork a process anymore to call "git rev-list", we need to remove the use of GIT_TRACE to check how "git rev-list" is called from the t6030 test that uses it. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 836a3fd commit 2d938fc

File tree

2 files changed

+23
-44
lines changed

2 files changed

+23
-44
lines changed

bisect.c

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -750,42 +750,31 @@ static void check_merge_bases(void)
750750
free_commit_list(result);
751751
}
752752

753-
/*
754-
* This function runs the command "git rev-list $_good ^$_bad"
755-
* and returns 1 if it produces some output, 0 otherwise.
756-
*/
757-
static int check_ancestors(void)
753+
static int check_ancestors(const char *prefix)
758754
{
759-
struct argv_array rev_argv = { NULL, 0, 0 };
760-
struct strbuf str = STRBUF_INIT;
761-
int i, result = 0;
762-
struct child_process rls;
763-
FILE *rls_fout;
755+
struct rev_info revs;
756+
struct object_array pending_copy;
757+
int i, res;
764758

765-
argv_array_push(&rev_argv, xstrdup("rev-list"));
766-
argv_array_push_sha1(&rev_argv, current_bad_sha1, "^%s");
767-
for (i = 0; i < good_revs.sha1_nr; i++)
768-
argv_array_push_sha1(&rev_argv, good_revs.sha1[i], "%s");
769-
argv_array_push(&rev_argv, NULL);
759+
bisect_rev_setup(&revs, prefix, "^%s", "%s", 0);
770760

771-
memset(&rls, 0, sizeof(rls));
772-
rls.argv = rev_argv.argv;
773-
rls.out = -1;
774-
rls.git_cmd = 1;
775-
if (start_command(&rls))
776-
die("Could not launch 'git rev-list' command.");
777-
rls_fout = fdopen(rls.out, "r");
778-
while (strbuf_getline(&str, rls_fout, '\n') != EOF) {
779-
strbuf_trim(&str);
780-
if (*str.buf) {
781-
result = 1;
782-
break;
783-
}
761+
/* Save pending objects, so they can be cleaned up later. */
762+
memset(&pending_copy, 0, sizeof(pending_copy));
763+
for (i = 0; i < revs.pending.nr; i++)
764+
add_object_array(revs.pending.objects[i].item,
765+
revs.pending.objects[i].name,
766+
&pending_copy);
767+
768+
bisect_common(&revs);
769+
res = (revs.commits != NULL);
770+
771+
/* Clean up objects used, as they will be reused. */
772+
for (i = 0; i < pending_copy.nr; i++) {
773+
struct object *o = pending_copy.objects[i].item;
774+
unparse_commit((struct commit *)o);
784775
}
785-
fclose(rls_fout);
786-
finish_command(&rls);
787776

788-
return result;
777+
return res;
789778
}
790779

791780
/*
@@ -813,7 +802,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
813802
if (good_revs.sha1_nr == 0)
814803
return;
815804

816-
if (check_ancestors())
805+
/* Check if all good revs are ancestor of the bad rev. */
806+
if (check_ancestors(prefix))
817807
check_merge_bases();
818808

819809
/* Create file BISECT_ANCESTORS_OK. */

t/t6030-bisect-porcelain.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -482,28 +482,17 @@ test_expect_success 'good merge bases when good and bad are siblings' '
482482
git bisect reset
483483
'
484484

485-
check_trace() {
486-
grep "$1" "$GIT_TRACE" | grep "\^$2" | grep "$3" >/dev/null
487-
}
488-
489485
test_expect_success 'optimized merge base checks' '
490-
GIT_TRACE="$(pwd)/trace.log" &&
491-
export GIT_TRACE &&
492486
git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
493487
grep "merge base must be tested" my_bisect_log.txt &&
494488
grep "$HASH4" my_bisect_log.txt &&
495-
check_trace "rev-list" "$HASH7" "$SIDE_HASH7" &&
496489
git bisect good > my_bisect_log2.txt &&
497490
test -f ".git/BISECT_ANCESTORS_OK" &&
498491
test "$HASH6" = $(git rev-parse --verify HEAD) &&
499-
: > "$GIT_TRACE" &&
500492
git bisect bad > my_bisect_log3.txt &&
501-
test_must_fail check_trace "rev-list" "$HASH6" "$SIDE_HASH7" &&
502493
git bisect good "$A_HASH" > my_bisect_log4.txt &&
503494
grep "merge base must be tested" my_bisect_log4.txt &&
504-
test_must_fail test -f ".git/BISECT_ANCESTORS_OK" &&
505-
check_trace "rev-list" "$HASH6" "$A_HASH" &&
506-
unset GIT_TRACE
495+
test_must_fail test -f ".git/BISECT_ANCESTORS_OK"
507496
'
508497

509498
# This creates another side branch called "parallel" with some files

0 commit comments

Comments
 (0)