Commit 3f849902e4b20216c80ec69714d6a6a0fdd332d2

Vicent Martí 2012-09-28T11:48:43

Merge pull request #958 from schu/fix-merge-base revwalk: fix off-by-one error

diff --git a/src/revwalk.c b/src/revwalk.c
index 8141d17..4fff238 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -274,7 +274,8 @@ static int commit_parse(git_revwalk *walk, commit_object *commit)
 static int interesting(git_pqueue *list)
 {
 	unsigned int i;
-	for (i = 1; i < git_pqueue_size(list); i++) {
+	/* element 0 isn't used - we need to start at 1 */
+	for (i = 1; i < list->size; i++) {
 		commit_object *commit = list->d[i];
 		if ((commit->flags & STALE) == 0)
 			return 1;
diff --git a/tests-clar/odb/foreach.c b/tests-clar/odb/foreach.c
index c1304a2..bf52cc1 100644
--- a/tests-clar/odb/foreach.c
+++ b/tests-clar/odb/foreach.c
@@ -42,7 +42,7 @@ void test_odb_foreach__foreach(void)
 	git_repository_odb(&_odb, _repo);
 
 	cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
-	cl_assert_equal_i(43 + 1640, nobj); /* count + in-pack */
+	cl_assert_equal_i(46 + 1640, nobj); /* count + in-pack */
 }
 
 void test_odb_foreach__one_pack(void)
diff --git a/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd b/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd
new file mode 100644
index 0000000..3ec5412
Binary files /dev/null and b/tests-clar/resources/testrepo.git/objects/1a/443023183e3f2bfbef8ac923cd81c1018a18fd differ
diff --git a/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2 b/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
new file mode 100644
index 0000000..7f1cfb2
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/objects/9f/13f7d0a9402c681f91dc590cf7b5470e6a77d2
@@ -0,0 +1,2 @@
+xM
+0F]d2<A~&`Vmҡ7U$JL9yM!GuH&U>;XEȎ5R AE&n}Z<E}=O[Ӽ^,^#ɿ]P`>A
\ No newline at end of file
diff --git a/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09 b/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09
new file mode 100644
index 0000000..158aef2
Binary files /dev/null and b/tests-clar/resources/testrepo.git/objects/fd/4959ce7510db09d4d8217fa2d1780413e05a09 differ
diff --git a/tests-clar/revwalk/mergebase.c b/tests-clar/revwalk/mergebase.c
index a210c1f..8434901 100644
--- a/tests-clar/revwalk/mergebase.c
+++ b/tests-clar/revwalk/mergebase.c
@@ -67,6 +67,15 @@ void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void)
 	cl_assert_equal_i(GIT_ENOTFOUND, error);
 }
 
+void test_revwalk_mergebase__no_off_by_one_missing(void)
+{
+	git_oid result, one, two;
+
+	cl_git_pass(git_oid_fromstr(&one, "1a443023183e3f2bfbef8ac923cd81c1018a18fd"));
+	cl_git_pass(git_oid_fromstr(&two, "9f13f7d0a9402c681f91dc590cf7b5470e6a77d2"));
+	cl_git_pass(git_merge_base(&result, _repo, &one, &two));
+}
+
 static void assert_mergebase_many(const char *expected_sha, int count, ...)
 {
 	va_list ap;