aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2005-09-19 15:16:03 -0700
committerJunio C Hamano <junkio@cox.net>2005-09-20 15:04:19 -0700
commitaf61c6e008c39ee9f61af33bb48850230f503443 (patch)
tree13120b0878ce98f84ac569ac9bea904e2b4ded61
parent343d35c9166cf1713eb2787c3506fd2663466262 (diff)
downloadgit-af61c6e008c39ee9f61af33bb48850230f503443.tar.gz
git-af61c6e008c39ee9f61af33bb48850230f503443.tar.xz
Fix extended short SHA1 name completion
get_sha1() would not do sha1 completion of short SHA1's when they were part of a more complex expression. So doing git-rev-parse 727132834e6be48a93c1bd6458a29d474ce7d5d5^ would work, and return 87c6aeb4efdd4355918d127a91bd0adc5a02f8ff. But using the shorthand version git-rev-list 72713^ wouldn't work. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--sha1_name.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 133af3b6c..b4fed924f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -84,19 +84,19 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
return 0;
}
-static int get_short_sha1(const char *name, unsigned char *sha1)
+static int get_short_sha1(const char *name, int len, unsigned char *sha1)
{
int i;
char canonical[40];
unsigned char res[20];
+ if (len < 4)
+ return -1;
memset(res, 0, 20);
memset(canonical, 'x', 40);
- for (i = 0;;i++) {
+ for (i = 0; i < len ;i++) {
unsigned char c = name[i];
unsigned char val;
- if (!c || i > 40)
- break;
if (c >= '0' && c <= '9')
val = c - '0';
else if (c >= 'a' && c <= 'f')
@@ -112,8 +112,6 @@ static int get_short_sha1(const char *name, unsigned char *sha1)
val <<= 4;
res[i >> 1] |= val;
}
- if (i < 4)
- return -1;
if (find_short_object_filename(i, canonical, sha1))
return 0;
if (find_short_packed_object(i, res, sha1))
@@ -254,7 +252,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
ret = get_sha1_basic(name, len, sha1);
if (!ret)
return 0;
- return get_short_sha1(name, sha1);
+ return get_short_sha1(name, len, sha1);
}
/*