@matheusbsbs / matheus-bagliano / commits / b64265ca8d
Fork 0

Make for-each-ref allow atom names like "<name>:<something>"

In anticipation of supplying a per-field date format specifier, this patch makes parse_atom() in builtin-for-each-ref.c allow atoms that have a valid atom name (as determined by the valid_atom[] table) followed by a colon, followed by an arbitrary string. The arbitrary string is where the format for the atom will be specified. Note, if different formats are specified for the same atom, multiple entries will be made in the used_atoms table to allow them to be distinguished by the grab_XXXX() functions. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Andy Parkins committed Sep 28, 2007 at 15:17 UTC b64265ca8da17d30561febf62a13990a2dc96d2f
1 file changed +10 -1
builtin-for-each-ref.c
+10 -1
@@ -106,7 +106,16 @@ static int parse_atom(const char *atom, const char *ep)
106 /* Is the atom a valid one? */
107 for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
108 int len = strlen(valid_atom[i].name);
109 - if (len == ep - sp && !memcmp(valid_atom[i].name, sp, len))
109 + /*
110 + * If the atom name has a colon, strip it and everything after
111 + * it off - it specifies the format for this entry, and
112 + * shouldn't be used for checking against the valid_atom
113 + * table.
114 + */
115 + const char *formatp = strchr(sp, ':');
116 + if (!formatp)
117 + formatp = ep;
118 + if (len == formatp - sp && !memcmp(valid_atom[i].name, sp, len))
119 break;
120 }
121