Skip to content

Commit 8d3abea

Browse files
committed
Merge branch 'kn/ref-filter-branch-list'
"git for-each-ref --format=..." with %(HEAD) in the format used to resolve the HEAD symref as many times as it had processed refs, which was wasteful, and "git branch" shared the same problem. * kn/ref-filter-branch-list: ref-filter: resolve HEAD when parsing %(HEAD) atom
2 parents ee7daf6 + 613a0e5 commit 8d3abea

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

ref-filter.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ static struct used_atom {
9393
unsigned int length;
9494
} objectname;
9595
struct refname_atom refname;
96+
char *head;
9697
} u;
9798
} *used_atom;
9899
static int used_atom_cnt, need_tagged, need_symref;
@@ -287,6 +288,12 @@ static void if_atom_parser(struct used_atom *atom, const char *arg)
287288
}
288289
}
289290

291+
static void head_atom_parser(struct used_atom *atom, const char *arg)
292+
{
293+
struct object_id unused;
294+
295+
atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, unused.hash, NULL);
296+
}
290297

291298
static struct {
292299
const char *name;
@@ -325,7 +332,7 @@ static struct {
325332
{ "push", FIELD_STR, remote_ref_atom_parser },
326333
{ "symref", FIELD_STR, refname_atom_parser },
327334
{ "flag" },
328-
{ "HEAD" },
335+
{ "HEAD", FIELD_STR, head_atom_parser },
329336
{ "color", FIELD_STR, color_atom_parser },
330337
{ "align", FIELD_STR, align_atom_parser },
331338
{ "end" },
@@ -1369,12 +1376,7 @@ static void populate_value(struct ref_array_item *ref)
13691376
} else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) {
13701377
continue;
13711378
} else if (!strcmp(name, "HEAD")) {
1372-
const char *head;
1373-
struct object_id oid;
1374-
1375-
head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
1376-
oid.hash, NULL);
1377-
if (head && !strcmp(ref->refname, head))
1379+
if (atom->u.head && !strcmp(ref->refname, atom->u.head))
13781380
v->s = "*";
13791381
else
13801382
v->s = " ";

0 commit comments

Comments
 (0)