summaryrefslogtreecommitdiff
path: root/ref-filter.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-05-29 03:34:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-29 03:34:51 (GMT)
commit8d3abeada9e1be49be75115f49f2af76506c0746 (patch)
tree72e6bd04e4277e3cbda4e565e5ea4fbf3e604be4 /ref-filter.c
parentee7daf6c1eeaf5640fd7029779b1b49f8903cd50 (diff)
parent613a0e52ea11c4496e3e154de192486a18eac2e4 (diff)
downloadgit-8d3abeada9e1be49be75115f49f2af76506c0746.zip
git-8d3abeada9e1be49be75115f49f2af76506c0746.tar.gz
git-8d3abeada9e1be49be75115f49f2af76506c0746.tar.bz2
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
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 6cc93dc..3742abb 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -93,6 +93,7 @@ static struct used_atom {
unsigned int length;
} objectname;
struct refname_atom refname;
+ char *head;
} u;
} *used_atom;
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)
}
}
+static void head_atom_parser(struct used_atom *atom, const char *arg)
+{
+ struct object_id unused;
+
+ atom->u.head = resolve_refdup("HEAD", RESOLVE_REF_READING, unused.hash, NULL);
+}
static struct {
const char *name;
@@ -325,7 +332,7 @@ static struct {
{ "push", FIELD_STR, remote_ref_atom_parser },
{ "symref", FIELD_STR, refname_atom_parser },
{ "flag" },
- { "HEAD" },
+ { "HEAD", FIELD_STR, head_atom_parser },
{ "color", FIELD_STR, color_atom_parser },
{ "align", FIELD_STR, align_atom_parser },
{ "end" },
@@ -1369,12 +1376,7 @@ static void populate_value(struct ref_array_item *ref)
} else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) {
continue;
} else if (!strcmp(name, "HEAD")) {
- const char *head;
- struct object_id oid;
-
- head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
- oid.hash, NULL);
- if (head && !strcmp(ref->refname, head))
+ if (atom->u.head && !strcmp(ref->refname, atom->u.head))
v->s = "*";
else
v->s = " ";