mirror of
https://github.com/git/git.git
synced 2024-11-27 20:14:30 +08:00
Add --relative-date option to the revision interface
Exposes the infrastructure from 9a8e35e987
.
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
b17fda5c07
commit
3dfb9278df
@ -128,6 +128,11 @@ OPTIONS
|
|||||||
After a failed merge, show refs that touch files having a
|
After a failed merge, show refs that touch files having a
|
||||||
conflict and don't exist on all heads to merge.
|
conflict and don't exist on all heads to merge.
|
||||||
|
|
||||||
|
--relative-date::
|
||||||
|
Show dates relative to the current time, e.g. "2 hours ago".
|
||||||
|
Only takes effect for dates shown in human-readable format,
|
||||||
|
such as when using "--pretty".
|
||||||
|
|
||||||
Author
|
Author
|
||||||
------
|
------
|
||||||
Written by Linus Torvalds <torvalds@osdl.org>
|
Written by Linus Torvalds <torvalds@osdl.org>
|
||||||
|
@ -85,7 +85,7 @@ static void show_commit(struct commit *commit)
|
|||||||
static char pretty_header[16384];
|
static char pretty_header[16384];
|
||||||
pretty_print_commit(revs.commit_format, commit, ~0,
|
pretty_print_commit(revs.commit_format, commit, ~0,
|
||||||
pretty_header, sizeof(pretty_header),
|
pretty_header, sizeof(pretty_header),
|
||||||
revs.abbrev, NULL, NULL);
|
revs.abbrev, NULL, NULL, revs.relative_date);
|
||||||
printf("%s%c", pretty_header, hdr_termination);
|
printf("%s%c", pretty_header, hdr_termination);
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
@ -261,7 +261,7 @@ static void show_one_commit(struct commit *commit, int no_name)
|
|||||||
struct commit_name *name = commit->util;
|
struct commit_name *name = commit->util;
|
||||||
if (commit->object.parsed)
|
if (commit->object.parsed)
|
||||||
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
|
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
|
||||||
pretty, sizeof(pretty), 0, NULL, NULL);
|
pretty, sizeof(pretty), 0, NULL, NULL, 0);
|
||||||
else
|
else
|
||||||
strcpy(pretty, "(unavailable)");
|
strcpy(pretty, "(unavailable)");
|
||||||
if (!strncmp(pretty, "[PATCH] ", 8))
|
if (!strncmp(pretty, "[PATCH] ", 8))
|
||||||
|
20
commit.c
20
commit.c
@ -467,7 +467,8 @@ static int add_rfc2047(char *buf, const char *line, int len)
|
|||||||
return bp - buf;
|
return bp - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const char *line)
|
static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf,
|
||||||
|
const char *line, int relative_date)
|
||||||
{
|
{
|
||||||
char *date;
|
char *date;
|
||||||
int namelen;
|
int namelen;
|
||||||
@ -507,14 +508,16 @@ static int add_user_info(const char *what, enum cmit_fmt fmt, char *buf, const c
|
|||||||
}
|
}
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case CMIT_FMT_MEDIUM:
|
case CMIT_FMT_MEDIUM:
|
||||||
ret += sprintf(buf + ret, "Date: %s\n", show_date(time, tz, 0));
|
ret += sprintf(buf + ret, "Date: %s\n",
|
||||||
|
show_date(time, tz, relative_date));
|
||||||
break;
|
break;
|
||||||
case CMIT_FMT_EMAIL:
|
case CMIT_FMT_EMAIL:
|
||||||
ret += sprintf(buf + ret, "Date: %s\n",
|
ret += sprintf(buf + ret, "Date: %s\n",
|
||||||
show_rfc2822_date(time, tz));
|
show_rfc2822_date(time, tz));
|
||||||
break;
|
break;
|
||||||
case CMIT_FMT_FULLER:
|
case CMIT_FMT_FULLER:
|
||||||
ret += sprintf(buf + ret, "%sDate: %s\n", what, show_date(time, tz, 0));
|
ret += sprintf(buf + ret, "%sDate: %s\n", what,
|
||||||
|
show_date(time, tz, relative_date));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* notin' */
|
/* notin' */
|
||||||
@ -557,7 +560,10 @@ static int add_merge_info(enum cmit_fmt fmt, char *buf, const struct commit *com
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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, int relative_date)
|
||||||
{
|
{
|
||||||
int hdr = 1, body = 0;
|
int hdr = 1, body = 0;
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
@ -646,12 +652,14 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
|
|||||||
if (!memcmp(line, "author ", 7))
|
if (!memcmp(line, "author ", 7))
|
||||||
offset += add_user_info("Author", fmt,
|
offset += add_user_info("Author", fmt,
|
||||||
buf + offset,
|
buf + offset,
|
||||||
line + 7);
|
line + 7,
|
||||||
|
relative_date);
|
||||||
if (!memcmp(line, "committer ", 10) &&
|
if (!memcmp(line, "committer ", 10) &&
|
||||||
(fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
|
(fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
|
||||||
offset += add_user_info("Commit", fmt,
|
offset += add_user_info("Commit", fmt,
|
||||||
buf + offset,
|
buf + offset,
|
||||||
line + 10);
|
line + 10,
|
||||||
|
relative_date);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
commit.h
2
commit.h
@ -52,7 +52,7 @@ enum cmit_fmt {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern enum cmit_fmt get_commit_format(const char *arg);
|
extern enum cmit_fmt get_commit_format(const char *arg);
|
||||||
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);
|
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);
|
||||||
|
|
||||||
/** Removes the first commit from a list sorted by date, and adds all
|
/** Removes the first commit from a list sorted by date, and adds all
|
||||||
* of its parents.
|
* of its parents.
|
||||||
|
@ -194,7 +194,9 @@ void show_log(struct rev_info *opt, const char *sep)
|
|||||||
/*
|
/*
|
||||||
* And then the pretty-printed message itself
|
* And then the pretty-printed message itself
|
||||||
*/
|
*/
|
||||||
len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header, sizeof(this_header), abbrev, subject, extra_headers);
|
len = pretty_print_commit(opt->commit_format, commit, ~0u, this_header,
|
||||||
|
sizeof(this_header), abbrev, subject,
|
||||||
|
extra_headers, opt->relative_date);
|
||||||
|
|
||||||
if (opt->add_signoff)
|
if (opt->add_signoff)
|
||||||
len = append_signoff(this_header, sizeof(this_header), len,
|
len = append_signoff(this_header, sizeof(this_header), len,
|
||||||
|
@ -816,6 +816,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
|
|||||||
revs->simplify_history = 0;
|
revs->simplify_history = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(arg, "--relative-date")) {
|
||||||
|
revs->relative_date = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
|
opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
|
||||||
if (opts > 0) {
|
if (opts > 0) {
|
||||||
revs->diff = 1;
|
revs->diff = 1;
|
||||||
|
@ -55,7 +55,8 @@ struct rev_info {
|
|||||||
|
|
||||||
/* Format info */
|
/* Format info */
|
||||||
unsigned int shown_one:1,
|
unsigned int shown_one:1,
|
||||||
abbrev_commit:1;
|
abbrev_commit:1,
|
||||||
|
relative_date:1;
|
||||||
unsigned int abbrev;
|
unsigned int abbrev;
|
||||||
enum cmit_fmt commit_format;
|
enum cmit_fmt commit_format;
|
||||||
struct log_info *loginfo;
|
struct log_info *loginfo;
|
||||||
|
Loading…
Reference in New Issue
Block a user