All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git-push: forced update of tag shows unabbreviated SHA1
Date: Thu, 31 Jan 2008 05:27:16 -0500	[thread overview]
Message-ID: <20080131102716.GC25546@coredump.intra.peff.net> (raw)
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)

  parent reply	other threads:[~2008-01-31 10:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-31  9:27 git-push: forced update of tag shows unabbreviated SHA1 Johannes Sixt
2008-01-31  9:37 ` Junio C Hamano
2008-01-31 10:01   ` Johannes Sixt
2008-01-31 10:06 ` Jeff King
2008-01-31 10:21   ` Junio C Hamano
2008-01-31 10:39     ` Jeff King
2008-01-31 10:27   ` Jeff King [this message]
2008-01-31 10:38     ` Junio C Hamano
2008-01-31 10:41       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080131102716.GC25546@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.