Code

Merge branch 'jk/pull-into-empty'
[git.git] / builtin / commit.c
index 82092e5c82cd48c7e3bfc97acadc7f7173b756bf..54b20497b120bc2bf5ee6e4904eca0ca5d83ff4f 100644 (file)
@@ -612,7 +612,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        int commitable, saved_color_setting;
        struct strbuf sb = STRBUF_INIT;
        char *buffer;
-       FILE *fp;
        const char *hook_arg1 = NULL;
        const char *hook_arg2 = NULL;
        int ident_shown = 0;
@@ -705,8 +704,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                hook_arg2 = "";
        }
 
-       fp = fopen(git_path(commit_editmsg), "w");
-       if (fp == NULL)
+       s->fp = fopen(git_path(commit_editmsg), "w");
+       if (s->fp == NULL)
                die_errno("could not open '%s'", git_path(commit_editmsg));
 
        if (cleanup_mode != CLEANUP_NONE)
@@ -730,7 +729,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                strbuf_release(&sob);
        }
 
-       if (fwrite(sb.buf, 1, sb.len, fp) < sb.len)
+       if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
                die_errno("could not write commit template");
 
        strbuf_release(&sb);
@@ -743,56 +742,58 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (use_editor && include_status) {
                char *ai_tmp, *ci_tmp;
                if (whence != FROM_COMMIT)
-                       fprintf(fp,
-                               "#\n"
-                               "It looks like you may be committing a %s.\n"
-                               "If this is not correct, please remove the file\n"
-                               "#      %s\n"
-                               "and try again.\n"
-                               "#\n",
+                       status_printf_ln(s, GIT_COLOR_NORMAL,
+                               "\n"
+                               "It looks like you may be committing a %s.\n"
+                               "If this is not correct, please remove the file\n"
+                               "       %s\n"
+                               "and try again.\n"
+                               "",
                                whence_s(),
                                git_path(whence == FROM_MERGE
                                         ? "MERGE_HEAD"
                                         : "CHERRY_PICK_HEAD"));
-               fprintf(fp,
-                       "\n"
-                       "# Please enter the commit message for your changes.");
+
+               fprintf(s->fp, "\n");
+               status_printf(s, GIT_COLOR_NORMAL,
+                       "Please enter the commit message for your changes.");
                if (cleanup_mode == CLEANUP_ALL)
-                       fprintf(fp,
+                       status_printf_more(s, GIT_COLOR_NORMAL,
                                " Lines starting\n"
-                               "with '#' will be ignored, and an empty"
+                               "with '#' will be ignored, and an empty"
                                " message aborts the commit.\n");
                else /* CLEANUP_SPACE, that is. */
-                       fprintf(fp,
+                       status_printf_more(s, GIT_COLOR_NORMAL,
                                " Lines starting\n"
-                               "with '#' will be kept; you may remove them"
+                               "with '#' will be kept; you may remove them"
                                " yourself if you want to.\n"
-                               "An empty message aborts the commit.\n");
+                               "An empty message aborts the commit.\n");
                if (only_include_assumed)
-                       fprintf(fp, "# %s\n", only_include_assumed);
+                       status_printf_ln(s, GIT_COLOR_NORMAL,
+                                       "%s", only_include_assumed);
 
                ai_tmp = cut_ident_timestamp_part(author_ident->buf);
                ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
                if (strcmp(author_ident->buf, committer_ident.buf))
-                       fprintf(fp,
+                       status_printf_ln(s, GIT_COLOR_NORMAL,
                                "%s"
-                               "# Author:    %s\n",
-                               ident_shown++ ? "" : "#\n",
+                               "Author:    %s",
+                               ident_shown++ ? "" : "\n",
                                author_ident->buf);
 
                if (!user_ident_sufficiently_given())
-                       fprintf(fp,
+                       status_printf_ln(s, GIT_COLOR_NORMAL,
                                "%s"
-                               "# Committer: %s\n",
-                               ident_shown++ ? "" : "#\n",
+                               "Committer: %s",
+                               ident_shown++ ? "" : "\n",
                                committer_ident.buf);
 
                if (ident_shown)
-                       fprintf(fp, "#\n");
+                       status_printf_ln(s, GIT_COLOR_NORMAL, "");
 
                saved_color_setting = s->use_color;
                s->use_color = 0;
-               commitable = run_status(fp, index_file, prefix, 1, s);
+               commitable = run_status(s->fp, index_file, prefix, 1, s);
                s->use_color = saved_color_setting;
 
                *ai_tmp = ' ';
@@ -814,7 +815,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        }
        strbuf_release(&committer_ident);
 
-       fclose(fp);
+       fclose(s->fp);
 
        /*
         * Reject an attempt to record a non-merge empty commit without
@@ -1202,13 +1203,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
 
        fd = hold_locked_index(&index_lock, 0);
-       if (0 <= fd) {
-               if (active_cache_changed &&
-                   !write_cache(fd, active_cache, active_nr))
-                       commit_locked_index(&index_lock);
-               else
-                       rollback_lock_file(&index_lock);
-       }
+       if (0 <= fd)
+               update_index_if_able(&the_index, &index_lock);
 
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.ignore_submodule_arg = ignore_submodule_arg;
@@ -1285,7 +1281,6 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
        get_commit_format(format.buf, &rev);
        rev.always_show_header = 0;
        rev.diffopt.detect_rename = 1;
-       rev.diffopt.rename_limit = 100;
        rev.diffopt.break_opt = 0;
        diff_setup_done(&rev.diffopt);