diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-10-03 03:03:22 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-10-03 03:03:22 -0700 |
commit | 5e5b2b98c844c791c87a3a084d7748b9d6888a0a (patch) | |
tree | 08c211a872faf7738748578c03bfbce89cef8041 /builtin-for-each-ref.c | |
parent | fed276e7524d6a80ae5dec037d586bd28543fc79 (diff) | |
parent | 96b2d4fa927c5055adc5b1d08f10a5d7352e2989 (diff) | |
download | git-5e5b2b98c844c791c87a3a084d7748b9d6888a0a.tar.gz git-5e5b2b98c844c791c87a3a084d7748b9d6888a0a.tar.xz |
Merge branch 'ap/dateformat'
* ap/dateformat:
Add a test script for for-each-ref, including test of date formatting
dateformat: parse %(xxdate) %(yydate:format) correctly
Make for-each-ref's grab_date() support per-atom formatting
Make for-each-ref allow atom names like "<name>:<something>"
parse_date_format(): convert a format name to an enum date_mode
Diffstat (limited to 'builtin-for-each-ref.c')
-rw-r--r-- | builtin-for-each-ref.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 29f70aabc..5dbf3e59f 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -106,7 +106,16 @@ static int parse_atom(const char *atom, const char *ep) /* Is the atom a valid one? */ for (i = 0; i < ARRAY_SIZE(valid_atom); i++) { int len = strlen(valid_atom[i].name); - if (len == ep - sp && !memcmp(valid_atom[i].name, sp, len)) + /* + * If the atom name has a colon, strip it and everything after + * it off - it specifies the format for this entry, and + * shouldn't be used for checking against the valid_atom + * table. + */ + const char *formatp = strchr(sp, ':'); + if (!formatp || ep < formatp) + formatp = ep; + if (len == formatp - sp && !memcmp(valid_atom[i].name, sp, len)) break; } @@ -349,12 +358,26 @@ static const char *copy_email(const char *buf) return line; } -static void grab_date(const char *buf, struct atom_value *v) +static void grab_date(const char *buf, struct atom_value *v, const char *atomname) { const char *eoemail = strstr(buf, "> "); char *zone; unsigned long timestamp; long tz; + enum date_mode date_mode = DATE_NORMAL; + const char *formatp; + + /* + * We got here because atomname ends in "date" or "date<something>"; + * it's not possible that <something> is not ":<format>" because + * parse_atom() wouldn't have allowed it, so we can assume that no + * ":" means no format is specified, and use the default. + */ + formatp = strchr(atomname, ':'); + if (formatp != NULL) { + formatp++; + date_mode = parse_date_format(formatp); + } if (!eoemail) goto bad; @@ -364,7 +387,7 @@ static void grab_date(const char *buf, struct atom_value *v) tz = strtol(zone, NULL, 10); if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE) goto bad; - v->s = xstrdup(show_date(timestamp, tz, 0)); + v->s = xstrdup(show_date(timestamp, tz, date_mode)); v->ul = timestamp; return; bad: @@ -391,7 +414,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru if (name[wholen] != 0 && strcmp(name + wholen, "name") && strcmp(name + wholen, "email") && - strcmp(name + wholen, "date")) + prefixcmp(name + wholen, "date")) continue; if (!wholine) wholine = find_wholine(who, wholen, buf, sz); @@ -403,8 +426,8 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru v->s = copy_name(wholine); else if (!strcmp(name + wholen, "email")) v->s = copy_email(wholine); - else if (!strcmp(name + wholen, "date")) - grab_date(wholine, v); + else if (!prefixcmp(name + wholen, "date")) + grab_date(wholine, v, name); } /* For a tag or a commit object, if "creator" or "creatordate" is @@ -424,8 +447,8 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru if (deref) name++; - if (!strcmp(name, "creatordate")) - grab_date(wholine, v); + if (!prefixcmp(name, "creatordate")) + grab_date(wholine, v, name); else if (!strcmp(name, "creator")) v->s = copy_line(wholine); } |