Code

reflog: fix overriding of command line options
[git.git] / builtin / log.c
index d8c6c28d2fcc3bd0744f071da536215141dc0d0b..9cb5b70d17f05bfa14854161c970ac73cd8ad2e5 100644 (file)
@@ -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.
@@ -480,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);
 }
@@ -1352,6 +1356,23 @@ static const char * const cherry_usage[] = {
        NULL
 };
 
+static void print_commit(char sign, struct commit *commit, int verbose,
+                        int abbrev)
+{
+       if (!verbose) {
+               printf("%c %s\n", sign,
+                      find_unique_abbrev(commit->object.sha1, abbrev));
+       } else {
+               struct strbuf buf = STRBUF_INIT;
+               struct pretty_print_context ctx = {0};
+               pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
+               printf("%c %s %s\n", sign,
+                      find_unique_abbrev(commit->object.sha1, abbrev),
+                      buf.buf);
+               strbuf_release(&buf);
+       }
+}
+
 int cmd_cherry(int argc, const char **argv, const char *prefix)
 {
        struct rev_info revs;
@@ -1436,22 +1457,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
                commit = list->item;
                if (has_commit_patch_id(commit, &ids))
                        sign = '-';
-
-               if (verbose) {
-                       struct strbuf buf = STRBUF_INIT;
-                       struct pretty_print_context ctx = {0};
-                       pretty_print_commit(CMIT_FMT_ONELINE, commit,
-                                           &buf, &ctx);
-                       printf("%c %s %s\n", sign,
-                              find_unique_abbrev(commit->object.sha1, abbrev),
-                              buf.buf);
-                       strbuf_release(&buf);
-               }
-               else {
-                       printf("%c %s\n", sign,
-                              find_unique_abbrev(commit->object.sha1, abbrev));
-               }
-
+               print_commit(sign, commit, verbose, abbrev);
                list = list->next;
        }