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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 17, 2009 at 17:36 UTC
2d938fc7bcf2c8ce314c44955db5a4dd2e9b6adb
2 files changed
+23
-44
bisect.c
+22
-32
@@ -750,42 +750,31 @@ static void check_merge_bases(void)
750
free_commit_list(result);
751
}
752
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)
754
{
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;
758
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);
760
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);
775
}
785
- fclose(rls_fout);
786
- finish_command(&rls);
776
788
- return result;
777
+ return res;
778
}
779
780
/*
@@ -813,7 +802,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
802
if (good_revs.sha1_nr == 0)
803
return;
804
816
- if (check_ancestors())
805
+ /* Check if all good revs are ancestor of the bad rev. */
806
+ if (check_ancestors(prefix))
807
check_merge_bases();
808
809
/* Create file BISECT_ANCESTORS_OK. */
t/t6030-bisect-porcelain.sh
+1
-12
@@ -482,28 +482,17 @@ test_expect_success 'good merge bases when good and bad are siblings' '
482
git bisect reset
483
'
484
485
-check_trace() {
486
- grep "$1" "$GIT_TRACE" | grep "\^$2" | grep "$3" >/dev/null
487
-}
488
-
485
test_expect_success 'optimized merge base checks' '
490
- GIT_TRACE="$(pwd)/trace.log" &&
491
- export GIT_TRACE &&
486
git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt &&
487
grep "merge base must be tested" my_bisect_log.txt &&
488
grep "$HASH4" my_bisect_log.txt &&
495
- check_trace "rev-list" "$HASH7" "$SIDE_HASH7" &&
489
git bisect good > my_bisect_log2.txt &&
490
test -f ".git/BISECT_ANCESTORS_OK" &&
491
test "$HASH6" = $(git rev-parse --verify HEAD) &&
499
- : > "$GIT_TRACE" &&
492
git bisect bad > my_bisect_log3.txt &&
501
- test_must_fail check_trace "rev-list" "$HASH6" "$SIDE_HASH7" &&
493
git bisect good "$A_HASH" > my_bisect_log4.txt &&
494
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"
496
'
497
498
# This creates another side branch called "parallel" with some files