diff options
author | Junio C Hamano <junkio@cox.net> | 2006-02-10 01:51:12 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-02-10 01:51:12 -0800 |
commit | 297a1aadbe22c978dca60d6512e5c851ebc6688c (patch) | |
tree | 496caac78acc8110d035162cc74b782f980ffd4d /sha1_name.c | |
parent | 0a798076b8d1a4a31bf2b24c564e2a99fd1c43a1 (diff) | |
download | git-297a1aadbe22c978dca60d6512e5c851ebc6688c.tar.gz git-297a1aadbe22c978dca60d6512e5c851ebc6688c.tar.xz |
find_unique_abbrev() simplification.
Earlier it did not grok the 0{40} SHA1 very well, but what it
needed to do was to find the shortest 0{N} that is not used as a
valid object name to be consistent with the way names of valid
objects are abbreviated. This makes some users simpler.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c index fa85d8a88..d67de18ba 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -186,16 +186,18 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1, const char *find_unique_abbrev(const unsigned char *sha1, int len) { - int status; + int status, is_null; static char hex[41]; + is_null = !memcmp(sha1, null_sha1, 20); memcpy(hex, sha1_to_hex(sha1), 40); if (len == 40) return hex; while (len < 40) { unsigned char sha1_ret[20]; status = get_short_sha1(hex, len, sha1_ret, 1); - if (!status) { + if (!status || + (is_null && status != SHORT_NAME_AMBIGUOUS)) { hex[len] = 0; return hex; } |