diff options
author | Russell Belfer <rb@github.com> | 2014-03-10 10:53:39 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2014-03-10 11:34:50 -0700 |
commit | 894990788771bef6ca20398e46b217817b8e0db8 (patch) | |
tree | 70f93107a116e6a81cee68abb4b2b526fc6c760c /tests/odb | |
parent | 9af14886a94ca4d08c7af1ba84b21cba40fce34c (diff) | |
download | libgit2-894990788771bef6ca20398e46b217817b8e0db8.tar.gz |
Fix a number of git_odb_exists_prefix bugs
The git_odb_exists_prefix API was not dealing correctly when a
later backend returned GIT_ENOTFOUND even if an earlier backend
had found the object.
Additionally, the unit tests were not properly exercising the API
and had a couple mistakes in checking the results.
Lastly, since the backends are not expected to behavior correctly
unless all bytes of the short id are zero except for the prefix,
this makes the ODB prefix APIs explicitly clear out the extra
bytes so the user doesn't have to be as careful.
Diffstat (limited to 'tests/odb')
-rw-r--r-- | tests/odb/loose.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/odb/loose.c b/tests/odb/loose.c index ef7136e36..c91927c4a 100644 --- a/tests/odb/loose.c +++ b/tests/odb/loose.c @@ -66,23 +66,25 @@ void test_odb_loose__cleanup(void) void test_odb_loose__exists(void) { - git_oid id, id2; + git_oid id, id2; git_odb *odb; - write_object_files(&one); + write_object_files(&one); cl_git_pass(git_odb_open(&odb, "test-objects")); - cl_git_pass(git_oid_fromstr(&id, one.id)); + cl_git_pass(git_oid_fromstr(&id, one.id)); + cl_assert(git_odb_exists(odb, &id)); - cl_assert(git_odb_exists(odb, &id)); + cl_git_pass(git_oid_fromstrp(&id, "8b137891")); + cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); + cl_assert_equal_i(0, git_oid_streq(&id2, one.id)); - cl_assert(git_odb_exists_prefix(&id2, odb, &id, 8)); - cl_assert(git_oid_equal(&id, &id2)); + /* Test for a missing object */ + cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa")); + cl_assert(!git_odb_exists(odb, &id)); - /* Test for a non-existant object */ - cl_git_pass(git_oid_fromstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa")); - cl_assert(!git_odb_exists(odb, &id2)); - cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(NULL, odb, &id2, 8)); + cl_git_pass(git_oid_fromstrp(&id, "8b13789a")); + cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); git_odb_free(odb); } |