Skip to content

Commit 3175aa1

Browse files
author
Junio C Hamano
committed
for-each-ref: "creator" and "creatordate" fields
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>
1 parent 34eb334 commit 3175aa1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

builtin-for-each-ref.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static struct {
5959
{ "taggername" },
6060
{ "taggeremail" },
6161
{ "taggerdate", FIELD_TIME },
62+
{ "creator" },
63+
{ "creatordate", FIELD_TIME },
6264
{ "subject" },
6365
{ "body" },
6466
{ "contents" },
@@ -401,6 +403,29 @@ static void grab_person(const char *who, struct atom_value *val, int deref, stru
401403
else if (!strcmp(name + wholen, "date"))
402404
grab_date(wholine, v);
403405
}
406+
407+
/* For a tag or a commit object, if "creator" or "creatordate" is
408+
* requested, do something special.
409+
*/
410+
if (strcmp(who, "tagger") && strcmp(who, "committer"))
411+
return; /* "author" for commit object is not wanted */
412+
if (!wholine)
413+
wholine = find_wholine(who, wholen, buf, sz);
414+
if (!wholine)
415+
return;
416+
for (i = 0; i < used_atom_cnt; i++) {
417+
const char *name = used_atom[i];
418+
struct atom_value *v = &val[i];
419+
if (!!deref != (*name == '*'))
420+
continue;
421+
if (deref)
422+
name++;
423+
424+
if (!strcmp(name, "creatordate"))
425+
grab_date(wholine, v);
426+
else if (!strcmp(name, "creator"))
427+
v->s = copy_line(wholine);
428+
}
404429
}
405430

406431
static void find_subpos(const char *buf, unsigned long sz, const char **sub, const char **body)

0 commit comments

Comments
 (0)