Merge branch 'sg/complete-untracked-filter'
[gitweb.git] / builtin / commit.c
index 80d886ab3af371a003ae026c19bd76ea83df9690..6ab4605cf5c2e6ef5efb37518c9c215bf8895f97 100644 (file)
@@ -30,6 +30,7 @@
 #include "column.h"
 #include "sequencer.h"
 #include "notes-utils.h"
+#include "mailmap.h"
 
 static const char * const builtin_commit_usage[] = {
        N_("git commit [options] [--] <pathspec>..."),
@@ -163,6 +164,15 @@ static void determine_whence(struct wt_status *s)
                s->whence = whence;
 }
 
+static void status_init_config(struct wt_status *s, config_fn_t fn)
+{
+       wt_status_prepare(s);
+       gitmodules_config();
+       git_config(fn, s);
+       determine_whence(s);
+       s->hints = advice_status_hints; /* must come after git_config() */
+}
+
 static void rollback_index_files(void)
 {
        switch (commit_style) {
@@ -597,6 +607,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        const char *hook_arg2 = NULL;
        int ident_shown = 0;
        int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
+       int old_display_comment_prefix;
 
        /* This checks and barfs if author is badly specified */
        determine_author_info(author_ident);
@@ -694,6 +705,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (s->fp == NULL)
                die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 
+       /* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */
+       old_display_comment_prefix = s->display_comment_prefix;
+       s->display_comment_prefix = 1;
+
+       /*
+        * Most hints are counter-productive when the commit has
+        * already started.
+        */
+       s->hints = 0;
+
        if (clean_message_contents)
                stripspace(&sb, 0);
 
@@ -819,6 +840,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
         */
        if (!commitable && whence != FROM_MERGE && !allow_empty &&
            !(amend && is_a_merge(current_head))) {
+               s->display_comment_prefix = old_display_comment_prefix;
                run_status(stdout, index_file, prefix, 0, s);
                if (amend)
                        fputs(_(empty_amend_advice), stderr);
@@ -933,6 +955,7 @@ static const char *find_author_by_nickname(const char *name)
        struct rev_info revs;
        struct commit *commit;
        struct strbuf buf = STRBUF_INIT;
+       struct string_list mailmap = STRING_LIST_INIT_NODUP;
        const char *av[20];
        int ac = 0;
 
@@ -943,13 +966,17 @@ static const char *find_author_by_nickname(const char *name)
        av[++ac] = buf.buf;
        av[++ac] = NULL;
        setup_revisions(ac, av, &revs, NULL);
+       revs.mailmap = &mailmap;
+       read_mailmap(revs.mailmap, NULL);
+
        prepare_revision_walk(&revs);
        commit = get_revision(&revs);
        if (commit) {
                struct pretty_print_context ctx = {0};
                ctx.date_mode = DATE_NORMAL;
                strbuf_release(&buf);
-               format_commit_message(commit, "%an <%ae>", &buf, &ctx);
+               format_commit_message(commit, "%aN <%aE>", &buf, &ctx);
+               clear_mailmap(&mailmap);
                return strbuf_detach(&buf, NULL);
        }
        die(_("No existing author found with '%s'"), name);
@@ -1180,6 +1207,10 @@ static int git_status_config(const char *k, const char *v, void *cb)
                s->use_color = git_config_colorbool(k, v);
                return 0;
        }
+       if (!strcmp(k, "status.displaycommentprefix")) {
+               s->display_comment_prefix = git_config_bool(k, v);
+               return 0;
+       }
        if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
                int slot = parse_status_slot(k, 13);
                if (slot < 0)
@@ -1244,10 +1275,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_status_usage, builtin_status_options);
 
-       wt_status_prepare(&s);
-       gitmodules_config();
-       git_config(git_status_config, &s);
-       determine_whence(&s);
+       status_init_config(&s, git_status_config);
        argc = parse_options(argc, argv, prefix,
                             builtin_status_options,
                             builtin_status_usage, 0);
@@ -1489,11 +1517,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_commit_usage, builtin_commit_options);
 
-       wt_status_prepare(&s);
-       gitmodules_config();
-       git_config(git_commit_config, &s);
+       status_init_config(&s, git_commit_config);
        status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
-       determine_whence(&s);
        s.colopts = 0;
 
        if (get_sha1("HEAD", sha1))
@@ -1615,7 +1640,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
                                           !current_head
                                           ? NULL
                                           : current_head->object.sha1,
-                                          0);
+                                          0, NULL);
 
        nl = strchr(sb.buf, '\n');
        if (nl)