Skip to content

Commit f504fa2

Browse files
committed
Merge branch 'jk/reflog-date'
* jk/reflog-date: make oneline reflog dates more consistent with multiline format
2 parents 6ba8b07 + cd43712 commit f504fa2

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

reflog-walk.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
242242
}
243243

244244
void show_reflog_message(struct reflog_walk_info* info, int oneline,
245-
int relative_date)
245+
enum date_mode dmode)
246246
{
247247
if (info && info->last_commit_reflog) {
248248
struct commit_reflog *commit_reflog = info->last_commit_reflog;
@@ -251,19 +251,21 @@ void show_reflog_message(struct reflog_walk_info* info, int oneline,
251251
info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
252252
if (oneline) {
253253
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));
256258
else
257259
printf("%d", commit_reflog->reflogs->nr
258260
- 2 - commit_reflog->recno);
259261
printf("}: %s", info->message);
260262
}
261263
else {
262264
printf("Reflog: %s@{", commit_reflog->reflogs->ref);
263-
if (commit_reflog->flag || relative_date)
265+
if (commit_reflog->flag || dmode)
264266
printf("%s", show_date(info->timestamp,
265267
info->tz,
266-
relative_date));
268+
dmode));
267269
else
268270
printf("%d", commit_reflog->reflogs->nr
269271
- 2 - commit_reflog->recno);

reflog-walk.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#ifndef REFLOG_WALK_H
22
#define REFLOG_WALK_H
33

4+
#include "cache.h"
5+
46
extern void init_reflog_walk(struct reflog_walk_info** info);
57
extern int add_reflog_for_walk(struct reflog_walk_info *info,
68
struct commit *commit, const char *name);
79
extern void fake_reflog_parent(struct reflog_walk_info *info,
810
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);
1013

1114
#endif

t/t1411-reflog-show.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>)
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 <[email protected]>)
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 <[email protected]>)
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

0 commit comments

Comments
 (0)