Skip to content

Commit af61c6e

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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 7271328^ would work, and return 87c6aeb. 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>
1 parent 343d35c commit af61c6e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

sha1_name.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
8484
return 0;
8585
}
8686

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)
8888
{
8989
int i;
9090
char canonical[40];
9191
unsigned char res[20];
9292

93+
if (len < 4)
94+
return -1;
9395
memset(res, 0, 20);
9496
memset(canonical, 'x', 40);
95-
for (i = 0;;i++) {
97+
for (i = 0; i < len ;i++) {
9698
unsigned char c = name[i];
9799
unsigned char val;
98-
if (!c || i > 40)
99-
break;
100100
if (c >= '0' && c <= '9')
101101
val = c - '0';
102102
else if (c >= 'a' && c <= 'f')
@@ -112,8 +112,6 @@ static int get_short_sha1(const char *name, unsigned char *sha1)
112112
val <<= 4;
113113
res[i >> 1] |= val;
114114
}
115-
if (i < 4)
116-
return -1;
117115
if (find_short_object_filename(i, canonical, sha1))
118116
return 0;
119117
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)
254252
ret = get_sha1_basic(name, len, sha1);
255253
if (!ret)
256254
return 0;
257-
return get_short_sha1(name, sha1);
255+
return get_short_sha1(name, len, sha1);
258256
}
259257

260258
/*

0 commit comments

Comments
 (0)