Skip to content

Commit a69f8c9

Browse files
committed
Merge branch 'ak/maint-for-each-ref-no-lookup' into maint
* ak/maint-for-each-ref-no-lookup: for-each-ref: Do not lookup objects when they will not be used
2 parents be273c7 + b7dd2d2 commit a69f8c9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

builtin-for-each-ref.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,6 @@ static void populate_value(struct refinfo *ref)
561561

562562
ref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);
563563

564-
buf = get_obj(ref->objectname, &obj, &size, &eaten);
565-
if (!buf)
566-
die("missing object %s for %s",
567-
sha1_to_hex(ref->objectname), ref->refname);
568-
if (!obj)
569-
die("parse_object_buffer failed on %s for %s",
570-
sha1_to_hex(ref->objectname), ref->refname);
571-
572564
/* Fill in specials first */
573565
for (i = 0; i < used_atom_cnt; i++) {
574566
const char *name = used_atom[i];
@@ -621,6 +613,22 @@ static void populate_value(struct refinfo *ref)
621613
}
622614
}
623615

616+
for (i = 0; i < used_atom_cnt; i++) {
617+
struct atom_value *v = &ref->value[i];
618+
if (v->s == NULL)
619+
goto need_obj;
620+
}
621+
return;
622+
623+
need_obj:
624+
buf = get_obj(ref->objectname, &obj, &size, &eaten);
625+
if (!buf)
626+
die("missing object %s for %s",
627+
sha1_to_hex(ref->objectname), ref->refname);
628+
if (!obj)
629+
die("parse_object_buffer failed on %s for %s",
630+
sha1_to_hex(ref->objectname), ref->refname);
631+
624632
grab_values(ref->value, 0, obj, buf, size);
625633
if (!eaten)
626634
free(buf);
@@ -926,7 +934,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
926934

927935
memset(&cbdata, 0, sizeof(cbdata));
928936
cbdata.grab_pattern = argv;
929-
for_each_ref(grab_single_ref, &cbdata);
937+
for_each_rawref(grab_single_ref, &cbdata);
930938
refs = cbdata.grab_array;
931939
num_refs = cbdata.grab_cnt;
932940

0 commit comments

Comments
 (0)