diff options
author | Junio C Hamano <junkio@cox.net> | 2005-10-02 21:40:51 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-10-03 18:50:06 -0700 |
commit | 0bc458902020b705fa913ca340aa40fea0f87096 (patch) | |
tree | 52c945002cbd00b8fa72792ee4cd1c94d862abf7 /sha1_name.c | |
parent | 619e5a0ed4a53653085961b7aefe1f93ed879949 (diff) | |
download | git-0bc458902020b705fa913ca340aa40fea0f87096.tar.gz git-0bc458902020b705fa913ca340aa40fea0f87096.tar.xz |
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>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/sha1_name.c b/sha1_name.c index 8920de1c4..f64755fbc 100644 --- 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; } @@ -121,7 +130,7 @@ static int find_unique_short_object(int len, char *canonical, 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; |