for-each-ref: "creator" and "creatordate" fields
authorJunio C Hamano <junkio@cox.net>
Sat, 28 Oct 2006 20:33:46 +0000 (13:33 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 3 Nov 2006 02:04:40 +0000 (18:04 -0800)
This adds "creator" (which is parallel to "tagger" or "committer")
and "creatordate" (corresponds to "taggerdate" and
"committerdate").

As other "date" fields, "creatordate" sorts numerically
and displays human readably. This allows for example for
sorting together heavyweigth and lightweight tags.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Acked-by: Jakub Narebski <jnareb@gmail.com>
builtin-for-each-ref.c
index 93d3d7eef06315c598952761a7f2755a2f95be2c..173bf38735315a1c299f1f2e3db76a7795a2305c 100644 (file)
@@ -59,6 +59,8 @@ static struct {
        { "taggername" },
        { "taggeremail" },
        { "taggerdate", FIELD_TIME },
+       { "creator" },
+       { "creatordate", FIELD_TIME },
        { "subject" },
        { "body" },
        { "contents" },
@@ -401,6 +403,29 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
                else if (!strcmp(name + wholen, "date"))
                        grab_date(wholine, v);
        }
+
+       /* For a tag or a commit object, if "creator" or "creatordate" is
+        * requested, do something special.
+        */
+       if (strcmp(who, "tagger") && strcmp(who, "committer"))
+               return; /* "author" for commit object is not wanted */
+       if (!wholine)
+               wholine = find_wholine(who, wholen, buf, sz);
+       if (!wholine)
+               return;
+       for (i = 0; i < used_atom_cnt; i++) {
+               const char *name = used_atom[i];
+               struct atom_value *v = &val[i];
+               if (!!deref != (*name == '*'))
+                       continue;
+               if (deref)
+                       name++;
+
+               if (!strcmp(name, "creatordate"))
+                       grab_date(wholine, v);
+               else if (!strcmp(name, "creator"))
+                       v->s = copy_line(wholine);
+       }
 }
 
 static void find_subpos(const char *buf, unsigned long sz, const char **sub, const char **body)