From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: git-push: forced update of tag shows unabbreviated SHA1
Date: Thu, 31 Jan 2008 05:39:48 -0500 [thread overview]
Message-ID: <20080131103947.GD25546@coredump.intra.peff.net> (raw)
In-Reply-To: <7vodb2cn2a.fsf@gitster.siamese.dyndns.org>
On Thu, Jan 31, 2008 at 02:21:49AM -0800, Junio C Hamano wrote:
> I think that needs to be done carefully. I recall some callers
> do expect it to return NULL for nonexistant objects, so the bug
> you noted above as "rare case" may need to be fixed, which I
> think is more important than coming up with a potentially too
> short abbreviation.
The patch I just posted just figures out ahead of time whether the
object exists. We can easily have it default to returning NULL but allow
a special flag for the new behavior. Something like:
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 8afb1d0..454ad8f 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -263,9 +263,8 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
static const char *status_abbrev(unsigned char sha1[20])
{
- const char *abbrev;
- abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
- return abbrev ? abbrev : sha1_to_hex(sha1);
+ return find_unique_abbrev_flags(sha1, DEFAULT_ABBREV,
+ FIND_UNIQUE_ABBREV_MISSING);
}
static void print_ok_ref_status(struct ref *ref)
diff --git a/cache.h b/cache.h
index 7a38511..0bcbf54 100644
--- a/cache.h
+++ b/cache.h
@@ -383,7 +383,14 @@ extern char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)
extern char *sha1_file_name(const unsigned char *sha1);
extern char *sha1_pack_name(const unsigned char *sha1);
extern char *sha1_pack_index_name(const unsigned char *sha1);
-extern const char *find_unique_abbrev(const unsigned char *sha1, int);
+
+#define FIND_UNIQUE_ABBREV_MISSING 1
+extern const char *find_unique_abbrev_flags(const unsigned char *sha1, int len, int flags);
+static inline const char *find_unique_abbrev(const unsigned char *sha1, int len)
+{
+ return find_unique_abbrev_flags(sha1, len, 0);
+}
+
extern const unsigned char null_sha1[20];
static inline int is_null_sha1(const unsigned char *sha1)
{
diff --git a/sha1_name.c b/sha1_name.c
index a99aff3..666d36c 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -190,12 +190,15 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
return status;
}
-const char *find_unique_abbrev(const unsigned char *sha1, int len)
+const char *find_unique_abbrev_flags(const unsigned char *sha1, int len,
+ int flags)
{
int status, missing;
static char hex[41];
missing = !has_sha1_file(sha1);
+ if (missing && !(flags & FIND_UNIQUE_ABBREV_MISSING))
+ return NULL;
memcpy(hex, sha1_to_hex(sha1), 40);
if (len == 40 || !len)
return hex;
next prev parent reply other threads:[~2008-01-31 10:40 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 [this message]
2008-01-31 10:27 ` Jeff King
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=20080131103947.GD25546@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).