@matheusbsbs / matheus-bagliano / commits / 3dfb9278df
Fork 0

Add --relative-date option to the revision interface

Exposes the infrastructure from 9a8e35e98793af086f05d1ca9643052df9b44a74. Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jonas Fonseca committed Aug 28, 2006 at 15:52 UTC 3dfb9278dff6d81fcc062e9a56edab9ece38ea7d
8 files changed +31 -11
Documentation/git-rev-list.txt
+5
@@ -128,6 +128,11 @@ OPTIONS
128 After a failed merge, show refs that touch files having a
129 conflict and don't exist on all heads to merge.
130
131 +--relative-date::
132 + Show dates relative to the current time, e.g. "2 hours ago".
133 + Only takes effect for dates shown in human-readable format,
134 + such as when using "--pretty".
135 +
136 Author
137 ------
138 Written by Linus Torvalds <torvalds@osdl.org>
builtin-rev-list.c
+1 -1
@@ -85,7 +85,7 @@ static void show_commit(struct commit *commit)
85 static char pretty_header[16384];
86 pretty_print_commit(revs.commit_format, commit, ~0,
87 pretty_header, sizeof(pretty_header),
88 - revs.abbrev, NULL, NULL);
88 + revs.abbrev, NULL, NULL, revs.relative_date);
89 printf("%s%c", pretty_header, hdr_termination);
90 }
91 fflush(stdout);
builtin-show-branch.c
+1 -1
@@ -261,7 +261,7 @@ static void show_one_commit(struct commit *commit, int no_name)
261 struct commit_name *name = commit->util;
262 if (commit->object.parsed)
263 pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
264 - pretty, sizeof(pretty), 0, NULL, NULL);
264 + pretty, sizeof(pretty), 0, NULL, NULL, 0);
265 else
266 strcpy(pretty, "(unavailable)");
267 if (!strncmp(pretty, "[PATCH] ", 8))
commit.c
+14 -6
@@ -467,7 +467,8 @@ static int add_rfc2047(char *buf, const char *line, int len)
467 return bp - buf;
468 }
469
470 -static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const char *line)
470 +static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
471 + const char *line, int relative_date)
472 {
473 char *date;
474 int namelen;
@@ -507,14 +508,16 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
508 }
509 switch (fmt) {
510 case CMIT_FMT_MEDIUM:
510 - ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz, 0));
511 + ret += sprintf(buf + ret, "Date: %s\n",
512 + show_date(time, tz, relative_date));
513 break;
514 case CMIT_FMT_EMAIL:
515 ret += sprintf(buf + ret, "Date: %s\n",
516 show_rfc2822_date(time, tz));
517 break;
518 case CMIT_FMT_FULLER:
517 - ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz, 0));
519 + ret += sprintf(buf + ret, "%sDate: %s\n", what,
520 + show_date(time, tz, relative_date));
521 break;
522 default:
523 /* notin' */
@@ -557,7 +560,10 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
560 return offset;
561 }
562
560 -unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject)
563 +unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
564 + unsigned long len, char *buf, unsigned long space,
565 + int abbrev, const char *subject,
566 + const char *after_subject, int relative_date)
567 {
568 int hdr = 1, body = 0;
569 unsigned long offset = 0;
@@ -646,12 +652,14 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
652 if (!memcmp(line, "author ", 7))
653 offset += add_user_info("Author", fmt,
654 buf + offset,
649 - line + 7);
655 + line + 7,
656 + relative_date);
657 if (!memcmp(line, "committer ", 10) &&
658 (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
659 offset += add_user_info("Commit", fmt,
660 buf + offset,
654 - line + 10);
661 + line + 10,
662 + relative_date);
663 continue;
664 }
665
commit.h
+1 -1
@@ -52,7 +52,7 @@ enum cmit_fmt {
52 };
53
54 extern enum cmit_fmt get_commit_format(const char *arg);
55 -extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject);
55 +extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char *buf, unsigned long space, int abbrev, const char *subject, const char *after_subject, int relative_date);
56
57 /** Removes the first commit from a list sorted by date, and adds all
58 * of its parents.
log-tree.c
+3 -1
@@ -194,7 +194,9 @@ void show_log(struct rev_info *opt, const char *sep)
194 /*
195 * And then the pretty-printed message itself
196 */
197 - len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, extra_headers);
197 + len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header,
198 + sizeof(this_header), abbrev, subject,
199 + extra_headers, opt->relative_date);
200
201 if (opt->add_signoff)
202 len = append_signoff(this_header, sizeof(this_header), len,
revision.c
+4
@@ -816,6 +816,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
816 revs->simplify_history = 0;
817 continue;
818 }
819 + if (!strcmp(arg, "--relative-date")) {
820 + revs->relative_date = 1;
821 + continue;
822 + }
823 opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
824 if (opts > 0) {
825 revs->diff = 1;
revision.h
+2 -1
@@ -55,7 +55,8 @@ struct rev_info {
55
56 /* Format info */
57 unsigned int shown_one:1,
58 - abbrev_commit:1;
58 + abbrev_commit:1,
59 + relative_date:1;
60 unsigned int abbrev;
61 enum cmit_fmt commit_format;
62 struct log_info *loginfo;