Skip to content

Commit f6bfe76

Browse files
committed
Merge branch 'mg/reflog-with-options' into maint
* mg/reflog-with-options: reflog: fix overriding of command line options t/t1411: test reflog with formats builtin/log.c: separate default and setup of cmd_log_init()
2 parents 0752000 + 4b56cf5 commit f6bfe76

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

builtin/log.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,8 @@ static int parse_decoration_style(const char *var, const char *value)
4949
return -1;
5050
}
5151

52-
static void cmd_log_init(int argc, const char **argv, const char *prefix,
53-
struct rev_info *rev, struct setup_revision_opt *opt)
52+
static void cmd_log_init_defaults(struct rev_info *rev)
5453
{
55-
int i;
56-
int decoration_given = 0;
57-
struct userformat_want w;
58-
5954
rev->abbrev = DEFAULT_ABBREV;
6055
rev->commit_format = CMIT_FMT_DEFAULT;
6156
if (fmt_pretty)
@@ -68,7 +63,14 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
6863

6964
if (default_date_mode)
7065
rev->date_mode = parse_date_format(default_date_mode);
66+
}
7167

68+
static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
69+
struct rev_info *rev, struct setup_revision_opt *opt)
70+
{
71+
int i;
72+
int decoration_given = 0;
73+
struct userformat_want w;
7274
/*
7375
* Check for -h before setup_revisions(), or "git log -h" will
7476
* fail when run without a git directory.
@@ -128,6 +130,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
128130
setup_pager();
129131
}
130132

133+
static void cmd_log_init(int argc, const char **argv, const char *prefix,
134+
struct rev_info *rev, struct setup_revision_opt *opt)
135+
{
136+
cmd_log_init_defaults(rev);
137+
cmd_log_init_finish(argc, argv, prefix, rev, opt);
138+
}
139+
131140
/*
132141
* This gives a rough estimate for how many commits we
133142
* will print out in the list.
@@ -486,16 +495,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
486495
rev.verbose_header = 1;
487496
memset(&opt, 0, sizeof(opt));
488497
opt.def = "HEAD";
489-
cmd_log_init(argc, argv, prefix, &rev, &opt);
490-
491-
/*
492-
* This means that we override whatever commit format the user gave
493-
* on the cmd line. Sad, but cmd_log_init() currently doesn't
494-
* allow us to set a different default.
495-
*/
498+
cmd_log_init_defaults(&rev);
496499
rev.commit_format = CMIT_FMT_ONELINE;
497500
rev.use_terminator = 1;
498501
rev.always_show_header = 1;
502+
cmd_log_init_finish(argc, argv, prefix, &rev, &opt);
499503

500504
return cmd_log_walk(&rev);
501505
}

t/t1411-reflog-show.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ test_expect_success 'oneline reflog format' '
2828
test_cmp expect actual
2929
'
3030

31+
test_expect_success 'reflog default format' '
32+
git reflog -1 >actual &&
33+
test_cmp expect actual
34+
'
35+
36+
cat >expect <<'EOF'
37+
commit e46513e
38+
Reflog: HEAD@{0} (C O Mitter <[email protected]>)
39+
Reflog message: commit (initial): one
40+
Author: A U Thor <[email protected]>
41+
42+
one
43+
EOF
44+
test_expect_success 'override reflog default format' '
45+
git reflog --format=short -1 >actual &&
46+
test_cmp expect actual
47+
'
48+
3149
cat >expect <<'EOF'
3250
Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <[email protected]>)
3351
Reflog message: commit (initial): one

0 commit comments

Comments
 (0)