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

Add --pretty=fuller

git log without --pretty showed author and author-date, while with --pretty=full showed author and committer but no dates. The new formatting option, --pretty=fuller, shows both name and timestamp for author and committer. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 9, 2005 at 22:15 UTC ff56fe1ca7f43087fd84588af87179c2959d0cb3
2 files changed +31 -7
commit.c
+30 -7
@@ -34,6 +34,8 @@ enum cmit_fmt get_commit_format(const char *arg)
34 return CMIT_FMT_SHORT;
35 if (!strcmp(arg, "=full"))
36 return CMIT_FMT_FULL;
37 + if (!strcmp(arg, "=fuller"))
38 + return CMIT_FMT_FULLER;
39 if (!strcmp(arg, "=oneline"))
40 return CMIT_FMT_ONELINE;
41 die("invalid --pretty format");
@@ -361,6 +363,7 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
363 int namelen;
364 unsigned long time;
365 int tz, ret;
366 + const char *filler = " ";
367
368 if (fmt == CMIT_FMT_ONELINE)
369 return 0;
@@ -371,9 +374,20 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
374 time = strtoul(date, &date, 10);
375 tz = strtol(date, NULL, 10);
376
374 - ret = sprintf(buf, "%s: %.*s\n", what, namelen, line);
375 - if (fmt == CMIT_FMT_MEDIUM)
377 + ret = sprintf(buf, "%s: %.*s%.*s\n", what,
378 + (fmt == CMIT_FMT_FULLER) ? 4 : 0,
379 + filler, namelen, line);
380 + switch (fmt) {
381 + case CMIT_FMT_MEDIUM:
382 ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz));
383 + break;
384 + case CMIT_FMT_FULLER:
385 + ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz));
386 + break;
387 + default:
388 + /* notin' */
389 + break;
390 + }
391 return ret;
392 }
393
@@ -448,12 +462,21 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned l
462 die("bad parent line in commit");
463 offset += add_parent_info(fmt, buf + offset, line, ++parents);
464 }
465 +
466 + /*
467 + * MEDIUM == DEFAULT shows only author with dates.
468 + * FULL shows both authors but not dates.
469 + * FULLER shows both authors and dates.
470 + */
471 if (!memcmp(line, "author ", 7))
452 - offset += add_user_info("Author", fmt, buf + offset, line + 7);
453 - if (fmt == CMIT_FMT_FULL) {
454 - if (!memcmp(line, "committer ", 10))
455 - offset += add_user_info("Commit", fmt, buf + offset, line + 10);
456 - }
472 + offset += add_user_info("Author", fmt,
473 + buf + offset,
474 + line + 7);
475 + if (!memcmp(line, "committer ", 10) &&
476 + (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
477 + offset += add_user_info("Commit", fmt,
478 + buf + offset,
479 + line + 10);
480 continue;
481 }
482
commit.h
+1
@@ -43,6 +43,7 @@ enum cmit_fmt {
43 CMIT_FMT_DEFAULT = CMIT_FMT_MEDIUM,
44 CMIT_FMT_SHORT,
45 CMIT_FMT_FULL,
46 + CMIT_FMT_FULLER,
47 CMIT_FMT_ONELINE,
48 };
49