Code

mv: be quiet about overwriting
[git.git] / builtin / log.c
index c6dce9b8950410b08e13c11aa940404a7fcd2b78..5c2af590047d92554d87acc5d7113a2f1f730a96 100644 (file)
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
 
+static int default_abbrev_commit;
 static int default_show_root = 1;
 static int decoration_style;
+static int decoration_given;
 static const char *fmt_patch_subject_prefix = "PATCH";
 static const char *fmt_pretty;
 
-static const char * const builtin_log_usage =
+static const char * const builtin_log_usage[] = {
        "git log [<options>] [<since>..<until>] [[--] <path>...]\n"
-       "   or: git show [options] <object>...";
+       "   or: git show [options] <object>...",
+       NULL
+};
 
 static int parse_decoration_style(const char *var, const char *value)
 {
@@ -49,6 +53,23 @@ static int parse_decoration_style(const char *var, const char *value)
        return -1;
 }
 
+static int decorate_callback(const struct option *opt, const char *arg, int unset)
+{
+       if (unset)
+               decoration_style = 0;
+       else if (arg)
+               decoration_style = parse_decoration_style("command line", arg);
+       else
+               decoration_style = DECORATE_SHORT_REFS;
+
+       if (decoration_style < 0)
+               die("invalid --decorate option: %s", arg);
+
+       decoration_given = 1;
+
+       return 0;
+}
+
 static void cmd_log_init_defaults(struct rev_info *rev)
 {
        rev->abbrev = DEFAULT_ABBREV;
@@ -57,6 +78,7 @@ static void cmd_log_init_defaults(struct rev_info *rev)
                get_commit_format(fmt_pretty, rev);
        rev->verbose_header = 1;
        DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
+       rev->abbrev_commit = default_abbrev_commit;
        rev->show_root_diff = default_show_root;
        rev->subject_prefix = fmt_patch_subject_prefix;
        DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
@@ -68,16 +90,29 @@ static void cmd_log_init_defaults(struct rev_info *rev)
 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.
-        */
-       if (argc == 2 && !strcmp(argv[1], "-h"))
-               usage(builtin_log_usage);
+       int quiet = 0, source = 0;
+
+       const struct option builtin_log_options[] = {
+               OPT_BOOLEAN(0, "quiet", &quiet, "suppress diff output"),
+               OPT_BOOLEAN(0, "source", &source, "show source"),
+               { OPTION_CALLBACK, 0, "decorate", NULL, NULL, "decorate options",
+                 PARSE_OPT_OPTARG, decorate_callback},
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix,
+                            builtin_log_options, builtin_log_usage,
+                            PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
+                            PARSE_OPT_KEEP_DASHDASH);
+
        argc = setup_revisions(argc, argv, rev, opt);
+       if (quiet)
+               rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
+
+       /* Any arguments at this point are not recognized */
+       if (argc > 1)
+               die("unrecognized argument: %s", argv[1]);
 
        memset(&w, 0, sizeof(w));
        userformat_find_requirements(NULL, &w);
@@ -94,35 +129,21 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
                if (rev->diffopt.pathspec.nr != 1)
                        usage("git logs can only follow renames on one pathname at a time");
        }
-       for (i = 1; i < argc; i++) {
-               const char *arg = argv[i];
-               if (!strcmp(arg, "--decorate")) {
-                       decoration_style = DECORATE_SHORT_REFS;
-                       decoration_given = 1;
-               } else if (!prefixcmp(arg, "--decorate=")) {
-                       const char *v = skip_prefix(arg, "--decorate=");
-                       decoration_style = parse_decoration_style(arg, v);
-                       if (decoration_style < 0)
-                               die(_("invalid --decorate option: %s"), arg);
-                       decoration_given = 1;
-               } else if (!strcmp(arg, "--no-decorate")) {
+
+       if (source)
+               rev->show_source = 1;
+
+       if (rev->pretty_given && rev->commit_format == CMIT_FMT_RAW) {
+               /*
+                * "log --pretty=raw" is special; ignore UI oriented
+                * configuration variables such as decoration.
+                */
+               if (!decoration_given)
                        decoration_style = 0;
-               } else if (!strcmp(arg, "--source")) {
-                       rev->show_source = 1;
-               } else if (!strcmp(arg, "-h")) {
-                       usage(builtin_log_usage);
-               } else
-                       die(_("unrecognized argument: %s"), arg);
+               if (!rev->abbrev_commit_given)
+                       rev->abbrev_commit = 0;
        }
 
-       /*
-        * defeat log.decorate configuration interacting with --pretty=raw
-        * from the command line.
-        */
-       if (!decoration_given && rev->pretty_given
-           && rev->commit_format == CMIT_FMT_RAW)
-               decoration_style = 0;
-
        if (decoration_style) {
                rev->show_decorations = 1;
                load_ref_decorations(decoration_style);
@@ -256,6 +277,8 @@ static void finish_early_output(struct rev_info *rev)
 static int cmd_log_walk(struct rev_info *rev)
 {
        struct commit *commit;
+       int saved_nrl = 0;
+       int saved_dcctc = 0;
 
        if (rev->early_output)
                setup_early_output(rev);
@@ -286,7 +309,14 @@ static int cmd_log_walk(struct rev_info *rev)
                }
                free_commit_list(commit->parents);
                commit->parents = NULL;
+               if (saved_nrl < rev->diffopt.needed_rename_limit)
+                       saved_nrl = rev->diffopt.needed_rename_limit;
+               if (rev->diffopt.degraded_cc_to_c)
+                       saved_dcctc = 1;
        }
+       rev->diffopt.degraded_cc_to_c = saved_dcctc;
+       rev->diffopt.needed_rename_limit = saved_nrl;
+
        if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
            DIFF_OPT_TST(&rev->diffopt, CHECK_FAILED)) {
                return 02;
@@ -300,6 +330,10 @@ static int git_log_config(const char *var, const char *value, void *cb)
                return git_config_string(&fmt_pretty, var, value);
        if (!strcmp(var, "format.subjectprefix"))
                return git_config_string(&fmt_patch_subject_prefix, var, value);
+       if (!strcmp(var, "log.abbrevcommit")) {
+               default_abbrev_commit = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "log.date"))
                return git_config_string(&default_date_mode, var, value);
        if (!strcmp(var, "log.decorate")) {
@@ -342,9 +376,11 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
 static void show_tagger(char *buf, int len, struct rev_info *rev)
 {
        struct strbuf out = STRBUF_INIT;
+       struct pretty_print_context pp = {0};
 
-       pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode,
-               get_log_output_encoding());
+       pp.fmt = rev->commit_format;
+       pp.date_mode = rev->date_mode;
+       pp_user_info(&pp, "Tagger", &out, buf, get_log_output_encoding());
        printf("%s", out.buf);
        strbuf_release(&out);
 }
@@ -405,6 +441,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
        struct object_array_entry *objects;
        struct setup_revision_opt opt;
+       struct pathspec match_all;
        int i, count, ret = 0;
 
        git_config(git_log_config, NULL);
@@ -412,6 +449,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        if (diff_use_color_default == -1)
                diff_use_color_default = git_use_color_default;
 
+       init_pathspec(&match_all, NULL);
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.always_show_header = 1;
@@ -458,7 +496,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
                                        diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
                                        name,
                                        diff_get_color_opt(&rev.diffopt, DIFF_RESET));
-                       read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
+                       read_tree_recursive((struct tree *)o, "", 0, 0, &match_all,
                                        show_tree_object, NULL);
                        rev.shown_one = 1;
                        break;
@@ -491,11 +529,11 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
 
        init_revisions(&rev, prefix);
        init_reflog_walk(&rev.reflog_info);
-       rev.abbrev_commit = 1;
        rev.verbose_header = 1;
        memset(&opt, 0, sizeof(opt));
        opt.def = "HEAD";
        cmd_log_init_defaults(&rev);
+       rev.abbrev_commit = 1;
        rev.commit_format = CMIT_FMT_ONELINE;
        rev.use_terminator = 1;
        rev.always_show_header = 1;
@@ -726,10 +764,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              int quiet)
 {
        const char *committer;
-       const char *subject_start = NULL;
        const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
        const char *msg;
-       const char *extra_headers = rev->extra_headers;
        struct shortlog log;
        struct strbuf sb = STRBUF_INIT;
        int i;
@@ -737,6 +773,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
        struct diff_options opts;
        int need_8bit_cte = 0;
        struct commit *commit = NULL;
+       struct pretty_print_context pp = {0};
 
        if (rev->commit_format != CMIT_FMT_EMAIL)
                die(_("Cover letter needs email format"));
@@ -768,7 +805,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                free(commit);
        }
 
-       log_write_email_headers(rev, head, &subject_start, &extra_headers,
+       log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
                                &need_8bit_cte);
 
        for (i = 0; !need_8bit_cte && i < nr; i++)
@@ -776,11 +813,11 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                        need_8bit_cte = 1;
 
        msg = body;
-       pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
-                    encoding);
-       pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
-                     encoding, need_8bit_cte);
-       pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);
+       pp.fmt = CMIT_FMT_EMAIL;
+       pp.date_mode = DATE_RFC2822;
+       pp_user_info(&pp, NULL, &sb, committer, encoding);
+       pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
+       pp_remainder(&pp, &msg, &sb, 0);
        printf("%s\n", sb.buf);
 
        strbuf_release(&sb);
@@ -1144,6 +1181,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                die (_("-n and -k are mutually exclusive."));
        if (keep_subject && subject_prefix)
                die (_("--subject-prefix and -k are mutually exclusive."));
+       rev.preserve_subject = keep_subject;
 
        argc = setup_revisions(argc, argv, &rev, &s_r_opt);
        if (argc > 1)
@@ -1374,8 +1412,7 @@ static void print_commit(char sign, struct commit *commit, int verbose,
                       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);
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
                printf("%c %s %s\n", sign,
                       find_unique_abbrev(commit->object.sha1, abbrev),
                       buf.buf);