for-each-ref --format='%(flag)'
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>
Junio C Hamano committed
Feb 13, 2010 at 12:05 UTC
88fb7f27f6036028b3470e0e2a0efed1d9c7ee78
1 file changed
+22
builtin-for-each-ref.c
+22
@@ -71,6 +71,7 @@ static struct {
71
{ "contents" },
72
{ "upstream" },
73
{ "symref" },
74
+ { "flag" },
75
};
76
77
/*
@@ -558,6 +559,13 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, v
559
}
560
}
561
562
+static inline char *copy_advance(char *dst, const char *src)
563
+{
564
+ while (*src)
565
+ *dst++ = *src++;
566
+ return dst;
567
+}
568
+
569
/*
570
* Parse the object referred by ref, and grab needed value.
571
*/
@@ -610,6 +618,20 @@ static void populate_value(struct refinfo *ref)
618
continue;
619
refname = branch->merge[0]->dst;
620
}
621
+ else if (!strcmp(name, "flag")) {
622
+ char buf[256], *cp = buf;
623
+ if (ref->flag & REF_ISSYMREF)
624
+ cp = copy_advance(cp, ",symref");
625
+ if (ref->flag & REF_ISPACKED)
626
+ cp = copy_advance(cp, ",packed");
627
+ if (cp == buf)
628
+ v->s = "";
629
+ else {
630
+ *cp = '\0';
631
+ v->s = xstrdup(buf + 1);
632
+ }
633
+ continue;
634
+ }
635
else
636
continue;
637