]>
Commit | Line | Data |
---|---|---|
24634c6f HWN |
1 | #include "clar_libgit2.h" |
2 | #include "odb.h" | |
24634c6f HWN |
3 | |
4 | static git_odb *_odb; | |
5 | ||
6 | void test_odb_mixed__initialize(void) | |
7 | { | |
8 | cl_git_pass(git_odb_open(&_odb, cl_fixture("duplicate.git/objects"))); | |
9 | } | |
10 | ||
11 | void test_odb_mixed__cleanup(void) | |
12 | { | |
13 | git_odb_free(_odb); | |
9094d30b | 14 | _odb = NULL; |
24634c6f HWN |
15 | } |
16 | ||
17 | void test_odb_mixed__dup_oid(void) { | |
18 | const char hex[] = "ce013625030ba8dba906f756967f9e9ca394464a"; | |
d19bcb33 | 19 | const char short_hex[] = "ce01362"; |
24634c6f HWN |
20 | git_oid oid; |
21 | git_odb_object *obj; | |
437224b4 | 22 | |
24634c6f HWN |
23 | cl_git_pass(git_oid_fromstr(&oid, hex)); |
24 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ)); | |
e54cfb9b | 25 | git_odb_object_free(obj); |
f5753999 RB |
26 | |
27 | cl_git_pass(git_odb_exists_prefix(NULL, _odb, &oid, GIT_OID_HEXSZ)); | |
28 | ||
d19bcb33 BR |
29 | cl_git_pass(git_oid_fromstrn(&oid, short_hex, sizeof(short_hex) - 1)); |
30 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, sizeof(short_hex) - 1)); | |
24634c6f | 31 | git_odb_object_free(obj); |
f5753999 RB |
32 | |
33 | cl_git_pass(git_odb_exists_prefix(NULL, _odb, &oid, sizeof(short_hex) - 1)); | |
24634c6f HWN |
34 | } |
35 | ||
437224b4 RB |
36 | /* some known sha collisions of file content: |
37 | * 'aabqhq' and 'aaazvc' with prefix 'dea509d0' (+ '9' and + 'b') | |
38 | * 'aaeufo' and 'aaaohs' with prefix '81b5bff5' (+ 'f' and + 'b') | |
39 | * 'aafewy' and 'aaepta' with prefix '739e3c4c' | |
40 | * 'aahsyn' and 'aadrjg' with prefix '0ddeaded' (+ '9' and + 'e') | |
41 | */ | |
42 | ||
43 | void test_odb_mixed__dup_oid_prefix_0(void) { | |
44 | char hex[10]; | |
f5753999 | 45 | git_oid oid, found; |
437224b4 RB |
46 | git_odb_object *obj; |
47 | ||
48 | /* ambiguous in the same pack file */ | |
49 | ||
50 | strncpy(hex, "dea509d0", sizeof(hex)); | |
51 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
52 | cl_assert_equal_i( | |
53 | GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 RB |
54 | cl_assert_equal_i( |
55 | GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); | |
437224b4 RB |
56 | |
57 | strncpy(hex, "dea509d09", sizeof(hex)); | |
58 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
59 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 | 60 | cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); |
0cee70eb | 61 | cl_assert_equal_oid(&found, git_odb_object_id(obj)); |
437224b4 RB |
62 | git_odb_object_free(obj); |
63 | ||
64 | strncpy(hex, "dea509d0b", sizeof(hex)); | |
65 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
66 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
67 | git_odb_object_free(obj); | |
68 | ||
69 | /* ambiguous in different pack files */ | |
70 | ||
71 | strncpy(hex, "81b5bff5", sizeof(hex)); | |
72 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
73 | cl_assert_equal_i( | |
74 | GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 RB |
75 | cl_assert_equal_i( |
76 | GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); | |
437224b4 RB |
77 | |
78 | strncpy(hex, "81b5bff5b", sizeof(hex)); | |
79 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
80 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 | 81 | cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); |
0cee70eb | 82 | cl_assert_equal_oid(&found, git_odb_object_id(obj)); |
437224b4 RB |
83 | git_odb_object_free(obj); |
84 | ||
85 | strncpy(hex, "81b5bff5f", sizeof(hex)); | |
86 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
87 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
88 | git_odb_object_free(obj); | |
89 | ||
90 | /* ambiguous in pack file and loose */ | |
91 | ||
92 | strncpy(hex, "0ddeaded", sizeof(hex)); | |
93 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
94 | cl_assert_equal_i( | |
95 | GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 RB |
96 | cl_assert_equal_i( |
97 | GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); | |
437224b4 RB |
98 | |
99 | strncpy(hex, "0ddeaded9", sizeof(hex)); | |
100 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
101 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
f5753999 | 102 | cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); |
0cee70eb | 103 | cl_assert_equal_oid(&found, git_odb_object_id(obj)); |
437224b4 RB |
104 | git_odb_object_free(obj); |
105 | ||
106 | strncpy(hex, "0ddeadede", sizeof(hex)); | |
107 | cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); | |
108 | cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); | |
109 | git_odb_object_free(obj); | |
110 | } |