summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0cfeed2)
raw | patch | inline | side by side (parent: 0cfeed2)
author | Jeff King <peff@peff.net> | |
Fri, 29 Aug 2008 00:54:59 +0000 (20:54 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 29 Aug 2008 07:14:29 +0000 (00:14 -0700) |
When running a command like:
git log --pretty=format:%ad --date=short
the date option was ignored. This patch causes it to use whatever
format was specified by --date (or by --relative-date, etc), just
as the non-user formats would do.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git log --pretty=format:%ad --date=short
the date option was ignored. This patch causes it to use whatever
format was specified by --date (or by --relative-date, etc), just
as the non-user formats would do.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index c11d4957714db202a012209e2437b9e050a28ae0..388d4925e6bc4bacb708f75437e9aaa216fcb9cc 100644 (file)
- '%an': author name
- '%aN': author name (respecting .mailmap)
- '%ae': author email
-- '%ad': author date
+- '%ad': author date (format respects --date= option)
- '%aD': author date, RFC2822 style
- '%ar': author date, relative
- '%at': author date, UNIX timestamp
diff --git a/archive.c b/archive.c
index 5b40e261f10e42b9f9ee9b4dbfe231765156bf64..e2280df56723809c5af1d566f0721e2639fff10c 100644 (file)
--- a/archive.c
+++ b/archive.c
strbuf_add(&fmt, b + 8, c - b - 8);
strbuf_add(buf, src, b - src);
- format_commit_message(commit, fmt.buf, buf);
+ format_commit_message(commit, fmt.buf, buf, DATE_NORMAL);
len -= c + 1 - src;
src = c + 1;
}
diff --git a/builtin-commit.c b/builtin-commit.c
index 649c8beb3e716dd5797787ced61d2fee23b7140f..c870037b07ca00aeeeb369fdae98c9b828be0af2 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
if (!log_tree_commit(&rev, commit)) {
struct strbuf buf = STRBUF_INIT;
- format_commit_message(commit, "%h: %s", &buf);
+ format_commit_message(commit, "%h: %s", &buf, DATE_NORMAL);
printf("%s\n", buf.buf);
strbuf_release(&buf);
}
diff --git a/commit.h b/commit.h
index 77de9621d9c926c6fb8a2bf9ca81c6c376a2ad41..ecdd5733f989f5931a0af05b387321da7068e9f9 100644 (file)
--- a/commit.h
+++ b/commit.h
struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
extern void get_commit_format(const char *arg, struct rev_info *);
extern void format_commit_message(const struct commit *commit,
- const void *format, struct strbuf *sb);
+ const void *format, struct strbuf *sb,
+ enum date_mode dmode);
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
struct strbuf *,
int abbrev, const char *subject,
diff --git a/pretty.c b/pretty.c
index 33ef34a4119812674726254fee3f391fb5734fdb..a29c290009587a12cdc6aec335d508d29481e697 100644 (file)
--- a/pretty.c
+++ b/pretty.c
}
static size_t format_person_part(struct strbuf *sb, char part,
- const char *msg, int len)
+ const char *msg, int len, enum date_mode dmode)
{
/* currently all placeholders have same length */
const int placeholder_len = 2;
switch (part) {
case 'd': /* date */
- strbuf_addstr(sb, show_date(date, tz, DATE_NORMAL));
+ strbuf_addstr(sb, show_date(date, tz, dmode));
return placeholder_len;
case 'D': /* date, RFC2822 style */
strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822));
struct format_commit_context {
const struct commit *commit;
+ enum date_mode dmode;
/* These offsets are relative to the start of the commit message. */
int commit_header_parsed;
return 1;
case 'a': /* author ... */
return format_person_part(sb, placeholder[1],
- msg + c->author.off, c->author.len);
+ msg + c->author.off, c->author.len,
+ c->dmode);
case 'c': /* committer ... */
return format_person_part(sb, placeholder[1],
- msg + c->committer.off, c->committer.len);
+ msg + c->committer.off, c->committer.len,
+ c->dmode);
case 'e': /* encoding */
strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
return 1;
}
void format_commit_message(const struct commit *commit,
- const void *format, struct strbuf *sb)
+ const void *format, struct strbuf *sb,
+ enum date_mode dmode)
{
struct format_commit_context context;
memset(&context, 0, sizeof(context));
context.commit = commit;
+ context.dmode = dmode;
strbuf_expand(sb, format, format_commit_item, &context);
}
const char *encoding;
if (fmt == CMIT_FMT_USERFORMAT) {
- format_commit_message(commit, user_format, sb);
+ format_commit_message(commit, user_format, sb, dmode);
return;
}
index 9176484db2f78122f71c0f11889e01382effcfb9..485ad4d44a6b9714c1986d6cff9c02263e1eb0f1 100755 (executable)
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
EOF
+test_expect_success '%ad respects --date=' '
+ echo 2005-04-07 >expect.ad-short &&
+ git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
+ test_cmp expect.ad-short output.ad-short
+'
+
test_expect_success 'empty email' '
test_tick &&
C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&