Skip to content

Commit

Permalink
for-each-ref --format='%(flag)'
Browse files Browse the repository at this point in the history
This expands to "symref" or "packed" or an empty string, exposing the
internal "flag" the for_each_ref() callback functions are called with.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Feb 13, 2010
1 parent 5cdd628 commit 88fb7f2
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions builtin-for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static struct {
{ "contents" },
{ "upstream" },
{ "symref" },
{ "flag" },
};

/*
Expand Down Expand Up @@ -558,6 +559,13 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, v
}
}

static inline char *copy_advance(char *dst, const char *src)
{
while (*src)
*dst++ = *src++;
return dst;
}

/*
* Parse the object referred by ref, and grab needed value.
*/
Expand Down Expand Up @@ -610,6 +618,20 @@ static void populate_value(struct refinfo *ref)
continue;
refname = branch->merge[0]->dst;
}
else if (!strcmp(name, "flag")) {
char buf[256], *cp = buf;
if (ref->flag & REF_ISSYMREF)
cp = copy_advance(cp, ",symref");
if (ref->flag & REF_ISPACKED)
cp = copy_advance(cp, ",packed");
if (cp == buf)
v->s = "";
else {
*cp = '\0';
v->s = xstrdup(buf + 1);
}
continue;
}
else
continue;

Expand Down

0 comments on commit 88fb7f2

Please sign in to comment.