Skip to content

Commit 61e704e

Browse files
glandiumgitster
authored andcommitted
sha1_name: avoid unnecessary sha1 lookup in find_unique_abbrev
An example where this happens is when doing an ls-tree on a tree that contains a commit link. In that case, find_unique_abbrev is called to get a non-abbreviated hex sha1, but still, a lookup is done as to whether the sha1 is in the repository (which ends up looking for a loose object in .git/objects), while the result of that lookup is not used when returning a non-abbreviated hex sha1. Signed-off-by: Mike Hommey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f93541 commit 61e704e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sha1_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ const char *find_unique_abbrev(const unsigned char *sha1, int len)
373373
int status, exists;
374374
static char hex[41];
375375

376-
exists = has_sha1_file(sha1);
377376
memcpy(hex, sha1_to_hex(sha1), 40);
378377
if (len == 40 || !len)
379378
return hex;
379+
exists = has_sha1_file(sha1);
380380
while (len < 40) {
381381
unsigned char sha1_ret[20];
382382
status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY);

0 commit comments

Comments
 (0)