Skip to content

Commit 6c4a060

Browse files
peffgitster
authored andcommitted
peel_ref: check object type before loading
The point of peel_ref is to dereference tags; if the base object is not a tag, then we can return early without even loading the object into memory. This patch accomplishes that by checking sha1_object_info for the type. For a packed object, we can get away with just looking in the pack index. For a loose object, we only need to inflate the first couple of header bytes. This is a bit of a gamble; if we do find a tag object, then we will end up loading the content anyway, and the extra lookup will have been wasteful. However, if it is not a tag object, then we save loading the object entirely. Depending on the ratio of non-tags to tags in the input, this can be a minor win or minor loss. However, it does give us one potential major win: if a ref points to a large blob (e.g., via an unannotated tag), then we can avoid looking at it entirely. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6dbffa commit 6c4a060

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

refs.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,15 @@ int peel_ref(const char *refname, unsigned char *sha1)
12251225
}
12261226

12271227
fallback:
1228-
o = parse_object(base);
1229-
if (o && o->type == OBJ_TAG) {
1228+
o = lookup_unknown_object(base);
1229+
if (o->type == OBJ_NONE) {
1230+
int type = sha1_object_info(base, NULL);
1231+
if (type < 0)
1232+
return -1;
1233+
o->type = type;
1234+
}
1235+
1236+
if (o->type == OBJ_TAG) {
12301237
o = deref_tag_noverify(o);
12311238
if (o) {
12321239
hashcpy(sha1, o->sha1);

0 commit comments

Comments
 (0)