From 437224b4b912176ac0992aa56790142e3ba5bb8f Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Mon, 5 Aug 2013 21:46:32 -0700 Subject: [PATCH] More tests for ambiguous OIDs across packs The test coverage for ambiguous OIDs was pretty thin. This adds a bunch of new objects both in packs, across packs, and loose that match to 8 characters so that we can test various cases of ambiguous lookups. --- include/git2/odb.h | 2 +- tests-clar/odb/mixed.c | 64 ++++++++++++++++++ tests-clar/resources/duplicate.git/config | 2 +- .../0d/deadede9e6d6ccddce0ee1e5749eed0485e5ea | Bin 0 -> 22 bytes ...a4896f0a0b9c9947b0927c57a5c03dcae052e3.idx | Bin 0 -> 1184 bytes ...4896f0a0b9c9947b0927c57a5c03dcae052e3.pack | Bin 0 -> 249 bytes ...8eeacbd65cbd30a365d7564b45a468e8bd43d6.idx | Bin 0 -> 1268 bytes ...eeacbd65cbd30a365d7564b45a468e8bd43d6.pack | Bin 0 -> 369 bytes .../duplicate.git/refs/heads/dummy-marker.txt | 1 + 9 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 tests-clar/resources/duplicate.git/objects/0d/deadede9e6d6ccddce0ee1e5749eed0485e5ea create mode 100644 tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.idx create mode 100644 tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.pack create mode 100644 tests-clar/resources/duplicate.git/objects/pack/pack-b18eeacbd65cbd30a365d7564b45a468e8bd43d6.idx create mode 100644 tests-clar/resources/duplicate.git/objects/pack/pack-b18eeacbd65cbd30a365d7564b45a468e8bd43d6.pack create mode 100644 tests-clar/resources/duplicate.git/refs/heads/dummy-marker.txt diff --git a/include/git2/odb.h b/include/git2/odb.h index b64436c4d..b3e9a57a6 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -120,7 +120,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i * @param db database to search for the object in. * @param short_id a prefix of the id of the object to read. * @param len the length of the prefix - * @return + * @return * - 0 if the object was read; * - GIT_ENOTFOUND if the object is not in the database. * - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix) diff --git a/tests-clar/odb/mixed.c b/tests-clar/odb/mixed.c index da0ed97d7..7f7120a6e 100644 --- a/tests-clar/odb/mixed.c +++ b/tests-clar/odb/mixed.c @@ -18,8 +18,72 @@ void test_odb_mixed__dup_oid(void) { const char hex[] = "ce013625030ba8dba906f756967f9e9ca394464a"; git_oid oid; git_odb_object *obj; + cl_git_pass(git_oid_fromstr(&oid, hex)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ)); git_odb_object_free(obj); } +/* some known sha collisions of file content: + * 'aabqhq' and 'aaazvc' with prefix 'dea509d0' (+ '9' and + 'b') + * 'aaeufo' and 'aaaohs' with prefix '81b5bff5' (+ 'f' and + 'b') + * 'aafewy' and 'aaepta' with prefix '739e3c4c' + * 'aahsyn' and 'aadrjg' with prefix '0ddeaded' (+ '9' and + 'e') + */ + +void test_odb_mixed__dup_oid_prefix_0(void) { + char hex[10]; + git_oid oid; + git_odb_object *obj; + + /* ambiguous in the same pack file */ + + strncpy(hex, "dea509d0", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_assert_equal_i( + GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + + strncpy(hex, "dea509d09", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); + + strncpy(hex, "dea509d0b", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); + + /* ambiguous in different pack files */ + + strncpy(hex, "81b5bff5", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_assert_equal_i( + GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + + strncpy(hex, "81b5bff5b", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); + + strncpy(hex, "81b5bff5f", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); + + /* ambiguous in pack file and loose */ + + strncpy(hex, "0ddeaded", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_assert_equal_i( + GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + + strncpy(hex, "0ddeaded9", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); + + strncpy(hex, "0ddeadede", sizeof(hex)); + cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); + git_odb_object_free(obj); +} diff --git a/tests-clar/resources/duplicate.git/config b/tests-clar/resources/duplicate.git/config index 515f48362..a4ef456cb 100644 --- a/tests-clar/resources/duplicate.git/config +++ b/tests-clar/resources/duplicate.git/config @@ -1,5 +1,5 @@ [core] repositoryformatversion = 0 filemode = true - bare = false + bare = true logallrefupdates = true diff --git a/tests-clar/resources/duplicate.git/objects/0d/deadede9e6d6ccddce0ee1e5749eed0485e5ea b/tests-clar/resources/duplicate.git/objects/0d/deadede9e6d6ccddce0ee1e5749eed0485e5ea new file mode 100644 index 0000000000000000000000000000000000000000..47c2a631abd12d79b08f6d17d28995b531874f30 GIT binary patch literal 22 dcmbU|EC5~E2V?*M literal 0 HcmV?d00001 diff --git a/tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.idx b/tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.idx new file mode 100644 index 0000000000000000000000000000000000000000..acbed82b6fb447c68800127d296625d0bd8babe5 GIT binary patch literal 1184 zcmexg;-AdGz`z8=qhR=i03*;VaGC@!97;}bY>_WB(E(C5qj zV;8+%qP3xM>;A918|0+AWm^K8o=iQnT!Q)8qF&|NehG%CP_-*vig^o9-Z~>~d;e2W zQ)z6P{*pO8mnHtp$mps(8R{f#w`%6WrbBm(8dh^W<2?xU-%%jG3dB4>+`Q{U(mRiW o-}Wrc^4Vb@-d{a3Rh~m{*TbU9KNlW9x?i!bT~Y2+iQDl90Qwh9m;e9( literal 0 HcmV?d00001 diff --git a/tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.pack b/tests-clar/resources/duplicate.git/objects/pack/pack-29a4896f0a0b9c9947b0927c57a5c03dcae052e3.pack new file mode 100644 index 0000000000000000000000000000000000000000..652b0c91fe9e5fd36849d0f6cd0656036636fba9 GIT binary patch literal 249 zcmVCOc7%Or9tpM|Mty(YM;*JdhET+|5JUd`T_1rFwv?5c$_mdFfcPQQK)1no@e6| zIC1v+9RJYg%l%^)y2ahQB32R&*5o;D_YP?t}S3J+gXHS^dywmgJit^ik z@N4)tF*R=8|Mg4zekX&zpm(#XuWn18-raEf_i=G|ednZ-e80utUOYFPzG33!drLVl zOh1>YCsz9>%VYVXhBI;Pbs(|Lr~4kH^5-lP*wg$ay(4f}cYEDyc`m_yv-SVFzl@#s z)Bb#I#f>(88>OC9dth@As5jMnpy6Tp@*S*ESDqBfO$o4aG7l)uWpO?*=l6Bd zU%w82&lYa1bXN2GEM!x4+)Q0XzSZD}%<|US2?94eJ7d3ZKDax6`V}tymGYS%GG6}F z-SxfX{PT@XvpF))=o~sbX=~b*#VbzzFS-zQTJ0J87B{1!g`5?0j7g z^7+uS%eDMLKa0gU-(>!qbWd={X#u5~EYs%H=>_|*`Q|_E_$OE1^hdW|FPLip1lIlLujBo%rnVwQi~0TD zt@+E1e5Y6c|Ij(-Wb5*@wPF1~7z1Y72AfyR@%Hi2I-~J~iGk}FQzeAIM$7vdkpG#f z5yIE?J^dWWzs*zw;d|?@2dRI~)B)z7(O7rpF%tu~BvXHy?SuDw%B>@k|J-f6n`zkA I^l)1f0Gki4jsO4v literal 0 HcmV?d00001 diff --git a/tests-clar/resources/duplicate.git/refs/heads/dummy-marker.txt b/tests-clar/resources/duplicate.git/refs/heads/dummy-marker.txt new file mode 100644 index 000000000..421376db9 --- /dev/null +++ b/tests-clar/resources/duplicate.git/refs/heads/dummy-marker.txt @@ -0,0 +1 @@ +dummy