Merge branch 'jk/reflog-date'

* jk/reflog-date:
  make oneline reflog dates more consistent with multiline format
maint
Junio C Hamano 2009-03-26 00:27:37 -07:00
commit f504fa2acb
3 changed files with 78 additions and 6 deletions

View File

@ -242,7 +242,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
} }


void show_reflog_message(struct reflog_walk_info* info, int oneline, void show_reflog_message(struct reflog_walk_info* info, int oneline,
int relative_date) enum date_mode dmode)
{ {
if (info && info->last_commit_reflog) { if (info && info->last_commit_reflog) {
struct commit_reflog *commit_reflog = info->last_commit_reflog; struct commit_reflog *commit_reflog = info->last_commit_reflog;
@ -251,8 +251,10 @@ void show_reflog_message(struct reflog_walk_info* info, int oneline,
info = &commit_reflog->reflogs->items[commit_reflog->recno+1]; info = &commit_reflog->reflogs->items[commit_reflog->recno+1];
if (oneline) { if (oneline) {
printf("%s@{", commit_reflog->reflogs->ref); printf("%s@{", commit_reflog->reflogs->ref);
if (commit_reflog->flag || relative_date) if (commit_reflog->flag || dmode)
printf("%s", show_date(info->timestamp, 0, 1)); printf("%s", show_date(info->timestamp,
info->tz,
dmode));
else else
printf("%d", commit_reflog->reflogs->nr printf("%d", commit_reflog->reflogs->nr
- 2 - commit_reflog->recno); - 2 - commit_reflog->recno);
@ -260,10 +262,10 @@ void show_reflog_message(struct reflog_walk_info* info, int oneline,
} }
else { else {
printf("Reflog: %s@{", commit_reflog->reflogs->ref); printf("Reflog: %s@{", commit_reflog->reflogs->ref);
if (commit_reflog->flag || relative_date) if (commit_reflog->flag || dmode)
printf("%s", show_date(info->timestamp, printf("%s", show_date(info->timestamp,
info->tz, info->tz,
relative_date)); dmode));
else else
printf("%d", commit_reflog->reflogs->nr printf("%d", commit_reflog->reflogs->nr
- 2 - commit_reflog->recno); - 2 - commit_reflog->recno);

View File

@ -1,11 +1,14 @@
#ifndef REFLOG_WALK_H #ifndef REFLOG_WALK_H
#define REFLOG_WALK_H #define REFLOG_WALK_H


#include "cache.h"

extern void init_reflog_walk(struct reflog_walk_info** info); extern void init_reflog_walk(struct reflog_walk_info** info);
extern int add_reflog_for_walk(struct reflog_walk_info *info, extern int add_reflog_for_walk(struct reflog_walk_info *info,
struct commit *commit, const char *name); struct commit *commit, const char *name);
extern void fake_reflog_parent(struct reflog_walk_info *info, extern void fake_reflog_parent(struct reflog_walk_info *info,
struct commit *commit); struct commit *commit);
extern void show_reflog_message(struct reflog_walk_info *info, int, int); extern void show_reflog_message(struct reflog_walk_info *info, int,
enum date_mode);


#endif #endif

67
t/t1411-reflog-show.sh Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh

test_description='Test reflog display routines'
. ./test-lib.sh

test_expect_success 'setup' '
echo content >file &&
git add file &&
test_tick &&
git commit -m one
'

cat >expect <<'EOF'
Reflog: HEAD@{0} (C O Mitter <committer@example.com>)
Reflog message: commit (initial): one
EOF
test_expect_success 'log -g shows reflog headers' '
git log -g -1 >tmp &&
grep ^Reflog <tmp >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
e46513e HEAD@{0}: commit (initial): one
EOF
test_expect_success 'oneline reflog format' '
git log -g -1 --oneline >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>)
Reflog message: commit (initial): one
EOF
test_expect_success 'using @{now} syntax shows reflog date (multiline)' '
git log -g -1 HEAD@{now} >tmp &&
grep ^Reflog <tmp >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
e46513e HEAD@{Thu Apr 7 15:13:13 2005 -0700}: commit (initial): one
EOF
test_expect_success 'using @{now} syntax shows reflog date (oneline)' '
git log -g -1 --oneline HEAD@{now} >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
Reflog: HEAD@{1112911993 -0700} (C O Mitter <committer@example.com>)
Reflog message: commit (initial): one
EOF
test_expect_success 'using --date= shows reflog date (multiline)' '
git log -g -1 --date=raw >tmp &&
grep ^Reflog <tmp >actual &&
test_cmp expect actual
'

cat >expect <<'EOF'
e46513e HEAD@{1112911993 -0700}: commit (initial): one
EOF
test_expect_success 'using --date= shows reflog date (oneline)' '
git log -g -1 --oneline --date=raw >actual &&
test_cmp expect actual
'

test_done