@matheusbsbs / matheus-bagliano / commits / 0bc4589020
Fork 0

Make sure get_sha1 does not accept ambiguous sha1 prefix (again).

The earlier fix incorrectly dropped the code the original had to ensure the found SHA1 is at least unique within the same pack. Restore the check. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 2, 2005 at 21:40 UTC 0bc458902020b705fa913ca340aa40fea0f87096
1 file changed +15 -6
sha1_name.c
+15 -6
@@ -91,14 +91,23 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
91 last = mid;
92 }
93 if (first < num) {
94 - unsigned char now[20];
94 + unsigned char now[20], next[20];
95 nth_packed_object_sha1(p, first, now);
96 if (match_sha(len, match, now)) {
97 - if (!found) {
98 - memcpy(found_sha1, now, 20);
99 - found++;
97 + if (nth_packed_object_sha1(p, first+1, next) ||
98 + !match_sha(len, match, next)) {
99 + /* unique within this pack */
100 + if (!found) {
101 + memcpy(found_sha1, now, 20);
102 + found++;
103 + }
104 + else if (memcmp(found_sha1, now, 20)) {
105 + found = 2;
106 + break;
107 + }
108 }
101 - else if (memcmp(found_sha1, now, 20)) {
109 + else {
110 + /* not even unique within this pack */
111 found = 2;
112 break;
113 }
@@ -121,7 +130,7 @@ static int find_unique_short_object(int len, char *canonical,
130 if (!has_unpacked && !has_packed)
131 return -1;
132 if (1 < has_unpacked || 1 < has_packed)
124 - return -1;
133 + return error("short SHA1 %.*s is ambiguous.", len, canonical);
134 if (has_unpacked != has_packed) {
135 memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20);
136 return 0;