summaryrefslogtreecommitdiff
path: root/builtin-for-each-ref.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-04-07 03:06:51 -0400
committerJunio C Hamano <gitster@pobox.com>2009-04-07 23:18:14 -0700
commit8db9a4b85d6b0d7424c8a19b77a5baa8529ab64c (patch)
treefe1f9697c242bf36fc0b364a01bc3c41bb3c79d2 /builtin-for-each-ref.c
parent3d4ecc0e23b2b2f555e7d33b5623fd4e67cc2ac7 (diff)
downloadgit-8db9a4b85d6b0d7424c8a19b77a5baa8529ab64c.tar.gz
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>
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r--builtin-for-each-ref.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index 4aaf75c779..653dca9a57 100644
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
@@ -672,32 +672,37 @@ static void populate_value(struct refinfo *ref)
const char *name = used_atom[i];
struct atom_value *v = &ref->value[i];
int deref = 0;
+ const char *refname;
+ const char *formatp;
+
if (*name == '*') {
deref = 1;
name++;
}
- if (!prefixcmp(name, "refname")) {
- const char *formatp = strchr(name, ':');
- const char *refname = ref->refname;
-
- /* look for "short" refname format */
- if (formatp) {
- formatp++;
- if (!strcmp(formatp, "short"))
- refname = get_short_ref(ref->refname);
- else
- die("unknown refname format %s",
- formatp);
- }
- if (!deref)
- v->s = refname;
- else {
- int len = strlen(refname);
- char *s = xmalloc(len + 4);
- sprintf(s, "%s^{}", refname);
- v->s = s;
- }
+ if (!prefixcmp(name, "refname"))
+ refname = ref->refname;
+ else
+ continue;
+
+ formatp = strchr(name, ':');
+ /* look for "short" refname format */
+ if (formatp) {
+ formatp++;
+ if (!strcmp(formatp, "short"))
+ refname = get_short_ref(refname);
+ else
+ die("unknown %.*s format %s",
+ (int)(formatp - name), name, formatp);
+ }
+
+ if (!deref)
+ v->s = refname;
+ else {
+ int len = strlen(refname);
+ char *s = xmalloc(len + 4);
+ sprintf(s, "%s^{}", refname);
+ v->s = s;
}
}