mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 17:20:22 +00:00
Merge pull request #1765 from arrbee/ambiguous-oids
More tests for ambiguous OIDs across packs
This commit is contained in:
commit
c5780abb02
@ -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 db database to search for the object in.
|
||||||
* @param short_id a prefix of the id of the object to read.
|
* @param short_id a prefix of the id of the object to read.
|
||||||
* @param len the length of the prefix
|
* @param len the length of the prefix
|
||||||
* @return
|
* @return
|
||||||
* - 0 if the object was read;
|
* - 0 if the object was read;
|
||||||
* - GIT_ENOTFOUND if the object is not in the database.
|
* - GIT_ENOTFOUND if the object is not in the database.
|
||||||
* - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
|
* - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
|
||||||
|
@ -18,8 +18,72 @@ void test_odb_mixed__dup_oid(void) {
|
|||||||
const char hex[] = "ce013625030ba8dba906f756967f9e9ca394464a";
|
const char hex[] = "ce013625030ba8dba906f756967f9e9ca394464a";
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
git_odb_object *obj;
|
git_odb_object *obj;
|
||||||
|
|
||||||
cl_git_pass(git_oid_fromstr(&oid, hex));
|
cl_git_pass(git_oid_fromstr(&oid, hex));
|
||||||
cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ));
|
cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ));
|
||||||
git_odb_object_free(obj);
|
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);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[core]
|
[core]
|
||||||
repositoryformatversion = 0
|
repositoryformatversion = 0
|
||||||
filemode = true
|
filemode = true
|
||||||
bare = false
|
bare = true
|
||||||
logallrefupdates = true
|
logallrefupdates = true
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
dummy
|
Loading…
Reference in New Issue
Block a user