[PATCH 1/2] sha1_name: stop hard-coding 40-character hex checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]