revwalk: fix off-by-one error Fixes #921.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
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;