]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/commit.c
commit, status: use status_printf{,_ln,_more} helpers
[thirdparty/git.git] / builtin / commit.c
index 03cff5af631fec975442c528b1ffba264b879c8e..ae62a25f52a2a500f4f27f9b03b2279c2197ef31 100644 (file)
@@ -118,10 +118,10 @@ static struct option builtin_commit_options[] = {
        OPT__VERBOSE(&verbose, "show diff in commit message template"),
 
        OPT_GROUP("Commit message options"),
-       OPT_FILENAME('F', "file", &logfile, "read log from file"),
+       OPT_FILENAME('F', "file", &logfile, "read message from file"),
        OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
        OPT_STRING(0, "date", &force_date, "DATE", "override date for commit"),
-       OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
+       OPT_CALLBACK('m', "message", &message, "MESSAGE", "commit message", opt_parse_m),
        OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
        OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
        OPT_STRING(0, "fixup", &fixup_message, "COMMIT", "use autosquash formatted message to fixup specified commit"),
@@ -145,12 +145,12 @@ static struct option builtin_commit_options[] = {
                    STATUS_FORMAT_SHORT),
        OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
        OPT_SET_INT(0, "porcelain", &status_format,
-                   "show porcelain output format", STATUS_FORMAT_PORCELAIN),
+                   "machine-readable output", STATUS_FORMAT_PORCELAIN),
        OPT_BOOLEAN('z', "null", &null_termination,
                    "terminate entries with NUL"),
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
        OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
-       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+       { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
        /* end commit contents options */
 
        { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
@@ -568,7 +568,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;
@@ -657,8 +656,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)
@@ -682,7 +681,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);
@@ -695,54 +694,55 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (use_editor && include_status) {
                char *ai_tmp, *ci_tmp;
                if (in_merge)
-                       fprintf(fp,
-                               "#\n"
-                               "It looks like you may be committing a MERGE.\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 MERGE.\n"
+                               "If this is not correct, please remove the file\n"
+                               "       %s\n"
+                               "and try again.\n"
+                               "",
                                git_path("MERGE_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 = ' ';
@@ -764,7 +764,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        }
        strbuf_release(&committer_ident);
 
-       fclose(fp);
+       fclose(s->fp);
 
        if (!commitable && !in_merge && !allow_empty &&
            !(amend && is_a_merge(head_sha1))) {
@@ -1092,7 +1092,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN('b', "branch", &status_show_branch,
                            "show branch information"),
                OPT_SET_INT(0, "porcelain", &status_format,
-                           "show porcelain output format",
+                           "machine-readable output",
                            STATUS_FORMAT_PORCELAIN),
                OPT_BOOLEAN('z', "null", &null_termination,
                            "terminate entries with NUL"),