]> git.ipfire.org Git - thirdparty/git.git/commitdiff
for-each-ref: refactor refname handling
authorJeff King <peff@peff.net>
Tue, 7 Apr 2009 07:06:51 +0000 (03:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 8 Apr 2009 06:18:14 +0000 (23:18 -0700)
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>
builtin-for-each-ref.c

index 4aaf75c779a281e0886d727aace9dc33f5ea3833..653dca9a5765d9a5873f5ac1b7345d2182ad7d01 100644 (file)
@@ -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;
                }
        }