git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-push: forced update of tag shows unabbreviated SHA1

From
Jeff King <peff@peff.net>
Date
Jan 31, 2008, 10:27 UTC
Message-ID
<20080131102716.GC25546@coredump.intra.peff.net>
In-Reply-To
<20080131100625.GB25546@coredump.intra.peff.net>
On Thu, Jan 31, 2008 at 05:06:25AM -0500, Jeff King wrote:
> But getting back to your point: yes, I agree it is a little ugly.
> Rewriting find_unique_abbrev would be necessary for fixing it, and I'm
> not sure it is worth the trouble.

Actually, it looks like we already handle a similar case: the null sha1, so the change isn't that big (and the null sha1 case folds nicely into the "missing" case). With the (lightly tested) patch below, find_unique_abbrev _always_ returns an answer, and for missing objects will show enough characters that it doesn't match any existing object.

diff --git a/sha1_name.c b/sha1_name.c
index 13e1164..c0e6af1 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -192,26 +192,24 @@ 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, is_null;
+	int status, missing;
 	static char hex[41];
 
-	is_null = is_null_sha1(sha1);
+	missing = !has_sha1_file(sha1);
 	memcpy(hex, sha1_to_hex(sha1), 40);
 	if (len == 40 || !len)
 		return hex;
 	while (len < 40) {
 		unsigned char sha1_ret[20];
 		status = get_short_sha1(hex, len, sha1_ret, 1);
-		if (!status ||
-		    (is_null && status != SHORT_NAME_AMBIGUOUS)) {
+		if ((!missing && !status) ||
+		    (missing && status == SHORT_NAME_NOT_FOUND)) {
 			hex[len] = 0;
 			return hex;
 		}
-		if (status != SHORT_NAME_AMBIGUOUS)
-			return NULL;
 		len++;
 	}
-	return NULL;
+	return hex;
 }
 
 static int ambiguous_path(const char *path, int len)
Previous: Jeff KingNext: Junio C Hamano
Message 7 of 9 in “git-push: forced update of tag shows unabbreviated SHA1”
  1. Johannes SixtJan 31, 2008
  2. Junio C HamanoJan 31, 2008
  3. Johannes SixtJan 31, 2008
  4. Jeff KingJan 31, 2008
  5. Junio C HamanoJan 31, 2008
  6. Jeff KingJan 31, 2008
  7. Jeff KingJan 31, 2008
  8. Junio C HamanoJan 31, 2008
  9. Jeff KingJan 31, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.