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

make oneline reflog dates more consistent with multiline format

The multiline reflog format (e.g., as shown by "git log -g") will show HEAD@{<date>} rather than HEAD@{<count>} in two situations: 1. If the user gave branch@{<date>} syntax to specify the reflog 2. If the user gave a --date=<format> specifier It uses the "normal" date format in case 1, and the user-specified format in case 2. The oneline reflog format (e.g., "git reflog show" or "git log -g --oneline") will show the date in the same two circumstances. However, it _always_ shows the date as a relative date, and it always ignores the timezone. In case 2, it seems ridiculous to trigger the date but use a format totally different from what the user requested. For case 1, it is arguable that the user might want to see the relative date by default; however, the multiline version shows the normal format. This patch does three things: - refactors the "relative_date" parameter to show_reflog_message to be an actual date_mode enum, since this is how it is used (it is passed to show_date) - uses the passed date_mode parameter in the oneline format (making it consistent with the multiline format) - does not ignore the timezone parameter in oneline mode Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Mar 20, 2009 at 02:00 UTC cd4371208a0e9f882f6fd4b4dd28d6911848ec79
3 files changed +78 -6
reflog-walk.c
+7 -5
@@ -242,7 +242,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
242 }
243
244 void show_reflog_message(struct reflog_walk_info* info, int oneline,
245 - int relative_date)
245 + enum date_mode dmode)
246 {
247 if (info && info->last_commit_reflog) {
248 struct commit_reflog *commit_reflog = info->last_commit_reflog;
@@ -251,8 +251,10 @@ void show_reflog_message(struct reflog_walk_info* info, int oneline,
251 info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
252 if (oneline) {
253 printf("%s@{", commit_reflog->reflogs->ref);
254 - if (commit_reflog->flag || relative_date)
255 - printf("%s", show_date(info->timestamp, 0, 1));
254 + if (commit_reflog->flag || dmode)
255 + printf("%s", show_date(info->timestamp,
256 + info->tz,
257 + dmode));
258 else
259 printf("%d", commit_reflog->reflogs->nr
260 - 2 - commit_reflog->recno);
@@ -260,10 +262,10 @@ void show_reflog_message(struct reflog_walk_info* info, int oneline,
262 }
263 else {
264 printf("Reflog: %s@{", commit_reflog->reflogs->ref);
263 - if (commit_reflog->flag || relative_date)
265 + if (commit_reflog->flag || dmode)
266 printf("%s", show_date(info->timestamp,
267 info->tz,
266 - relative_date));
268 + dmode));
269 else
270 printf("%d", commit_reflog->reflogs->nr
271 - 2 - commit_reflog->recno);
reflog-walk.h
+4 -1
@@ -1,11 +1,14 @@
1 #ifndef REFLOG_WALK_H
2 #define REFLOG_WALK_H
3
4 +#include "cache.h"
5 +
6 extern void init_reflog_walk(struct reflog_walk_info** info);
7 extern int add_reflog_for_walk(struct reflog_walk_info *info,
8 struct commit *commit, const char *name);
9 extern void fake_reflog_parent(struct reflog_walk_info *info,
10 struct commit *commit);
9 -extern void show_reflog_message(struct reflog_walk_info *info, int, int);
11 +extern void show_reflog_message(struct reflog_walk_info *info, int,
12 + enum date_mode);
13
14 #endif
t/t1411-reflog-show.sh new
+67
@@ -0,0 +1,67 @@
1 +#!/bin/sh
2 +
3 +test_description='Test reflog display routines'
4 +. ./test-lib.sh
5 +
6 +test_expect_success 'setup' '
7 + echo content >file &&
8 + git add file &&
9 + test_tick &&
10 + git commit -m one
11 +'
12 +
13 +cat >expect <<'EOF'
14 +Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
15 +Reflog message: commit (initial): one
16 +EOF
17 +test_expect_success 'log -g shows reflog headers' '
18 + git log -g -1 >tmp &&
19 + grep ^Reflog <tmp >actual &&
20 + test_cmp expect actual
21 +'
22 +
23 +cat >expect <<'EOF'
24 +e46513e HEAD@{0}: commit (initial): one
25 +EOF
26 +test_expect_success 'oneline reflog format' '
27 + git log -g -1 --oneline >actual &&
28 + test_cmp expect actual
29 +'
30 +
31 +cat >expect <<'EOF'
32 +Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
33 +Reflog message: commit (initial): one
34 +EOF
35 +test_expect_success 'using @{now} syntax shows reflog date (multiline)' '
36 + git log -g -1 HEAD@{now} >tmp &&
37 + grep ^Reflog <tmp >actual &&
38 + test_cmp expect actual
39 +'
40 +
41 +cat >expect <<'EOF'
42 +e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
43 +EOF
44 +test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
45 + git log -g -1 --oneline HEAD@{now} >actual &&
46 + test_cmp expect actual
47 +'
48 +
49 +cat >expect <<'EOF'
50 +Reflog: HEAD@{1112911993 -0700} (C O Mitter <committer@example.com>)
51 +Reflog message: commit (initial): one
52 +EOF
53 +test_expect_success 'using --date= shows reflog date (multiline)' '
54 + git log -g -1 --date=raw >tmp &&
55 + grep ^Reflog <tmp >actual &&
56 + test_cmp expect actual
57 +'
58 +
59 +cat >expect <<'EOF'
60 +e46513e HEAD@{1112911993 -0700}: commit (initial): one
61 +EOF
62 +test_expect_success 'using --date= shows reflog date (oneline)' '
63 + git log -g -1 --oneline --date=raw >actual &&
64 + test_cmp expect actual
65 +'
66 +
67 +test_done