for-each-ref: refactor refname handling
This code handles some special magic like *-deref and the :short formatting specifier. The next patch will add another field which outputs a ref and wants to use the same code. This patch splits the "which ref are we outputting" from the actual formatting. There should be no behavioral change. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
3d4ecc0e23
commit
8db9a4b85d
|
@ -672,22 +672,28 @@ static void populate_value(struct refinfo *ref)
|
||||||
const char *name = used_atom[i];
|
const char *name = used_atom[i];
|
||||||
struct atom_value *v = &ref->value[i];
|
struct atom_value *v = &ref->value[i];
|
||||||
int deref = 0;
|
int deref = 0;
|
||||||
|
const char *refname;
|
||||||
|
const char *formatp;
|
||||||
|
|
||||||
if (*name == '*') {
|
if (*name == '*') {
|
||||||
deref = 1;
|
deref = 1;
|
||||||
name++;
|
name++;
|
||||||
}
|
}
|
||||||
if (!prefixcmp(name, "refname")) {
|
|
||||||
const char *formatp = strchr(name, ':');
|
|
||||||
const char *refname = ref->refname;
|
|
||||||
|
|
||||||
|
if (!prefixcmp(name, "refname"))
|
||||||
|
refname = ref->refname;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
formatp = strchr(name, ':');
|
||||||
/* look for "short" refname format */
|
/* look for "short" refname format */
|
||||||
if (formatp) {
|
if (formatp) {
|
||||||
formatp++;
|
formatp++;
|
||||||
if (!strcmp(formatp, "short"))
|
if (!strcmp(formatp, "short"))
|
||||||
refname = get_short_ref(ref->refname);
|
refname = get_short_ref(refname);
|
||||||
else
|
else
|
||||||
die("unknown refname format %s",
|
die("unknown %.*s format %s",
|
||||||
formatp);
|
(int)(formatp - name), name, formatp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deref)
|
if (!deref)
|
||||||
|
@ -699,7 +705,6 @@ static void populate_value(struct refinfo *ref)
|
||||||
v->s = s;
|
v->s = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
grab_values(ref->value, 0, obj, buf, size);
|
grab_values(ref->value, 0, obj, buf, size);
|
||||||
if (!eaten)
|
if (!eaten)
|
||||||
|
|
Loading…
Reference in New Issue