From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/2] sha1_name: stop hard-coding 40-character hex checks
Date: Sat, 15 Jun 2013 23:08:25 +0530 [thread overview]
Message-ID: <1371317906-3991-2-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1371317906-3991-1-git-send-email-artagnon@gmail.com>
In two places, get_sha1_basic() assumes that strings are possibly sha1
hexes if they are 40 characters long, and calls get_sha1_hex() in these
two cases. This 40-character check is ugly and wrong: there is nothing
preventing a revision or branch name from being exactly 40 characters.
Replace it with a call to the more robust get_short_sha1().
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
sha1_name.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 90419ef..d862af3 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -451,7 +451,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
int refs_found = 0;
int at, reflog_len, nth_prior = 0;
- if (len == 40 && !get_sha1_hex(str, sha1)) {
+ if (!get_short_sha1(str, strlen(str), sha1, GET_SHA1_QUIETLY)) {
refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
if (refs_found > 0 && warn_ambiguous_refs) {
warning(warn_msg, len, str);
@@ -492,9 +492,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
int detached;
if (interpret_nth_prior_checkout(str, &buf) > 0) {
- detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
+ detached = get_short_sha1(buf.buf, buf.len, sha1, GET_SHA1_QUIETLY);
strbuf_release(&buf);
- if (detached)
+ if (detached != SHORT_NAME_NOT_FOUND)
return 0;
}
}
--
1.8.3.1.438.g96d34e8
next prev parent reply other threads:[~2013-06-15 17:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-15 17:38 [PATCH 0/2] Slightly prettier reflog message from checkout Ramkumar Ramachandra
2013-06-15 17:38 ` Ramkumar Ramachandra [this message]
2013-06-16 13:28 ` [PATCH 1/2] sha1_name: stop hard-coding 40-character hex checks Phil Hord
2013-06-18 7:03 ` Ramkumar Ramachandra
2013-06-18 14:27 ` Junio C Hamano
2013-06-15 17:38 ` [PATCH 2/2] checkout: do not write full sha1 to reflog Ramkumar Ramachandra
2013-06-15 17:42 ` [PATCH 0/2] Slightly prettier reflog message from checkout Ramkumar Ramachandra
2013-06-16 1:24 ` Junio C Hamano
2013-06-16 9:21 ` Ramkumar Ramachandra
2013-06-17 2:59 ` Junio C Hamano
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=1371317906-3991-2-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).