From ef803fd4b09bca707c7c27669a2789bb050b488c Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Fri, 1 Apr 2011 11:20:31 +0200 Subject: [PATCH 1/3] builtin/log.c: separate default and setup of cmd_log_init() cmd_log_init() sets up some default rev options and then calls setup_revisions(), so that a caller cannot set up own defaults: Either they get overriden by cmd_log_init() (if set before) or they override the command line (if set after). We even complain about this in a comment to cmd_log_reflog(). Therefore, separate the two steps so that one can still call cmd_log_init() or, alternatively, cmd_log_init_defaults() followed by cmd_log_init_finish() (and set defaults in between). No functional change so far. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/log.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 0f43d2ec78..59fe588559 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -49,13 +49,8 @@ static int parse_decoration_style(const char *var, const char *value) return -1; } -static void cmd_log_init(int argc, const char **argv, const char *prefix, - struct rev_info *rev, struct setup_revision_opt *opt) +static void cmd_log_init_defaults(struct rev_info *rev) { - int i; - int decoration_given = 0; - struct userformat_want w; - rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; if (fmt_pretty) @@ -68,7 +63,14 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, if (default_date_mode) rev->date_mode = parse_date_format(default_date_mode); +} +static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, + struct rev_info *rev, struct setup_revision_opt *opt) +{ + int i; + int decoration_given = 0; + struct userformat_want w; /* * Check for -h before setup_revisions(), or "git log -h" will * fail when run without a git directory. @@ -128,6 +130,13 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, setup_pager(); } +static void cmd_log_init(int argc, const char **argv, const char *prefix, + struct rev_info *rev, struct setup_revision_opt *opt) +{ + cmd_log_init_defaults(rev); + cmd_log_init_finish(argc, argv, prefix, rev, opt); +} + /* * This gives a rough estimate for how many commits we * will print out in the list. From 21d2616a7181472ae43e33d762a2733827cff9e9 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Fri, 1 Apr 2011 11:20:32 +0200 Subject: [PATCH 2/3] t/t1411: test reflog with formats "git reflog --format=short" does not work because "reflog" overrides the format option. This is documented in code. Document this by a test (known failure) also. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index ba25ff354d..88dc6a781b 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -28,6 +28,24 @@ test_expect_success 'oneline reflog format' ' test_cmp expect actual ' +test_expect_success 'reflog default format' ' + git reflog -1 >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +commit e46513e +Reflog: HEAD@{0} (C O Mitter ) +Reflog message: commit (initial): one +Author: A U Thor + + one +EOF +test_expect_failure 'override reflog default format' ' + git reflog --format=short -1 >actual && + test_cmp expect actual +' + cat >expect <<'EOF' Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter ) Reflog message: commit (initial): one From 4b56cf58a9ee684d47e01d815eccd75252d61da5 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Fri, 1 Apr 2011 11:20:33 +0200 Subject: [PATCH 3/3] reflog: fix overriding of command line options Currently, "git reflog" overrides some command line options such as "--format". Fix this by using the new 2-phase version of cmd_log_init(). Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/log.c | 9 ++------- t/t1411-reflog-show.sh | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 59fe588559..9cb5b70d17 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -489,16 +489,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) rev.verbose_header = 1; memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; - cmd_log_init(argc, argv, prefix, &rev, &opt); - - /* - * This means that we override whatever commit format the user gave - * on the cmd line. Sad, but cmd_log_init() currently doesn't - * allow us to set a different default. - */ + cmd_log_init_defaults(&rev); rev.commit_format = CMIT_FMT_ONELINE; rev.use_terminator = 1; rev.always_show_header = 1; + cmd_log_init_finish(argc, argv, prefix, &rev, &opt); return cmd_log_walk(&rev); } diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 88dc6a781b..caa687b5b4 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -41,7 +41,7 @@ Author: A U Thor one EOF -test_expect_failure 'override reflog default format' ' +test_expect_success 'override reflog default format' ' git reflog --format=short -1 >actual && test_cmp expect actual '