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>
Linus Torvalds committed
Sep 19, 2005 at 15:16 UTC
af61c6e008c39ee9f61af33bb48850230f503443
1 file changed
+5
-7
sha1_name.c
+5
-7
@@ -84,19 +84,19 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
84
return 0;
85
}
86
87
-static int get_short_sha1(const char *name, unsigned char *sha1)
87
+static int get_short_sha1(const char *name, int len, unsigned char *sha1)
88
{
89
int i;
90
char canonical[40];
91
unsigned char res[20];
92
93
+ if (len < 4)
94
+ return -1;
95
memset(res, 0, 20);
96
memset(canonical, 'x', 40);
95
- for (i = 0;;i++) {
97
+ for (i = 0; i < len ;i++) {
98
unsigned char c = name[i];
99
unsigned char val;
98
- if (!c || i > 40)
99
- break;
100
if (c >= '0' && c <= '9')
101
val = c - '0';
102
else if (c >= 'a' && c <= 'f')
@@ -112,8 +112,6 @@ static int get_short_sha1(const char *name, unsigned char *sha1)
112
val <<= 4;
113
res[i >> 1] |= val;
114
}
115
- if (i < 4)
116
- return -1;
115
if (find_short_object_filename(i, canonical, sha1))
116
return 0;
117
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)
252
ret = get_sha1_basic(name, len, sha1);
253
if (!ret)
254
return 0;
257
- return get_short_sha1(name, sha1);
255
+ return get_short_sha1(name, len, sha1);
256
}
257
258
/*