summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 619e5a0)
raw | patch | inline | side by side (parent: 619e5a0)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 3 Oct 2005 04:40:51 +0000 (21:40 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 4 Oct 2005 01:50:06 +0000 (18:50 -0700) |
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>
ensure the found SHA1 is at least unique within the same pack.
Restore the check.
Signed-off-by: Junio C Hamano <junkio@cox.net>
sha1_name.c | patch | blob | history |
diff --git a/sha1_name.c b/sha1_name.c
index 8920de1c45ce0a094fbc0b5ea2ca744ef27c6393..f64755fbceea617c424b9b83999eeaa91bf76af1 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -91,14 +91,23 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
last = mid;
}
if (first < num) {
- unsigned char now[20];
+ unsigned char now[20], next[20];
nth_packed_object_sha1(p, first, now);
if (match_sha(len, match, now)) {
- if (!found) {
- memcpy(found_sha1, now, 20);
- found++;
+ if (nth_packed_object_sha1(p, first+1, next) ||
+ !match_sha(len, match, next)) {
+ /* unique within this pack */
+ if (!found) {
+ memcpy(found_sha1, now, 20);
+ found++;
+ }
+ else if (memcmp(found_sha1, now, 20)) {
+ found = 2;
+ break;
+ }
}
- else if (memcmp(found_sha1, now, 20)) {
+ else {
+ /* not even unique within this pack */
found = 2;
break;
}
if (!has_unpacked && !has_packed)
return -1;
if (1 < has_unpacked || 1 < has_packed)
- return -1;
+ return error("short SHA1 %.*s is ambiguous.", len, canonical);
if (has_unpacked != has_packed) {
memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20);
return 0;