summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0a79807)
raw | patch | inline | side by side (parent: 0a79807)
author | Junio C Hamano <junkio@cox.net> | |
Fri, 10 Feb 2006 09:51:12 +0000 (01:51 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 10 Feb 2006 09:51:12 +0000 (01:51 -0800) |
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>
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>
combine-diff.c | patch | blob | history | |
diff.c | patch | blob | history | |
sha1_name.c | patch | blob | history |
diff --git a/combine-diff.c b/combine-diff.c
index 9aa099b061add3eb9a7adb763f0195e2c534f1ac..8ba69492037f65d73ae73504d2c0062d41591434 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
if (show_hunks || mode_differs) {
const char *abb;
- char null_abb[DEFAULT_ABBREV + 1];
- memset(null_abb, '0', DEFAULT_ABBREV);
- null_abb[DEFAULT_ABBREV] = 0;
if (header) {
shown_header++;
puts(header);
for (i = 0; i < num_parent; i++) {
if (elem->parent[i].mode != elem->mode)
mode_differs = 1;
- if (memcmp(elem->parent[i].sha1, null_sha1, 20))
- abb = find_unique_abbrev(elem->parent[i].sha1,
- DEFAULT_ABBREV);
- else
- abb = null_abb;
+ abb = find_unique_abbrev(elem->parent[i].sha1,
+ DEFAULT_ABBREV);
printf("%s%s", i ? "," : "", abb);
}
- if (memcmp(elem->sha1, null_sha1, 20))
- abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
- else
- abb = null_abb;
+ abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
printf("..%s\n", abb);
if (mode_differs) {
index ec51e7dd1832013cda561fa803668b1f2213c96a..890bdaa6b8a22dad667807cc3d835ccd9fb8056a 100644 (file)
--- a/diff.c
+++ b/diff.c
}
/* This is different from find_unique_abbrev() in that
- * it needs to deal with 0{40} SHA1.
+ * it stuffs the result with dots for alignment.
*/
const char *diff_unique_abbrev(const unsigned char *sha1, int len)
{
return sha1_to_hex(sha1);
abbrev = find_unique_abbrev(sha1, len);
- if (!abbrev) {
- if (!memcmp(sha1, null_sha1, 20)) {
- char *buf = sha1_to_hex(null_sha1);
- if (len < 37)
- strcpy(buf + len, "...");
- return buf;
- }
- else
- return sha1_to_hex(sha1);
- }
+ if (!abbrev)
+ return sha1_to_hex(sha1);
abblen = strlen(abbrev);
if (abblen < 37) {
static char hex[41];
diff --git a/sha1_name.c b/sha1_name.c
index fa85d8a88d31219cef5bed195044327459f9162b..d67de18ba5f5aa1f5b3dd1c5c81e75618d12e330 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
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;
}