From 37f3012ff2a1a23dc7f8d390fde959d292fcc4e8 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:10:49 -0600 Subject: commit: refer to commit template as s->fp Instead of maintaining a local variable for it, use s->fp to keep track of where the commit message template should be written. This prepares us to take advantage of the status_printf functions, which use a struct wt_status instead of a FILE pointer to determine where to send their output. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/commit.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index d7f55e3d4..ef5f0b24c 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -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,7 +694,7 @@ 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, + fprintf(s->fp, "#\n" "# It looks like you may be committing a MERGE.\n" "# If this is not correct, please remove the file\n" @@ -704,45 +703,45 @@ static int prepare_to_commit(const char *index_file, const char *prefix, "#\n", git_path("MERGE_HEAD")); - fprintf(fp, + fprintf(s->fp, "\n" "# Please enter the commit message for your changes."); if (cleanup_mode == CLEANUP_ALL) - fprintf(fp, + fprintf(s->fp, " Lines starting\n" "# with '#' will be ignored, and an empty" " message aborts the commit.\n"); else /* CLEANUP_SPACE, that is. */ - fprintf(fp, + fprintf(s->fp, " Lines starting\n" "# with '#' will be kept; you may remove them" " yourself if you want to.\n" "# An empty message aborts the commit.\n"); if (only_include_assumed) - fprintf(fp, "# %s\n", only_include_assumed); + fprintf(s->fp, "# %s\n", 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, + fprintf(s->fp, "%s" "# Author: %s\n", ident_shown++ ? "" : "#\n", author_ident->buf); if (!user_ident_sufficiently_given()) - fprintf(fp, + fprintf(s->fp, "%s" "# Committer: %s\n", ident_shown++ ? "" : "#\n", committer_ident.buf); if (ident_shown) - fprintf(fp, "#\n"); + fprintf(s->fp, "#\n"); 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 +763,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))) { -- cgit v1.2.1 From b926c0d10df6c5bdc8bf9a2fc1431e8edb673e4d Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 25 Feb 2011 23:11:37 -0600 Subject: commit, status: use status_printf{,_ln,_more} helpers wt-status code is used to provide a reminder of changes included and not included for the commit message template opened in the operator's text editor by "git commit". Therefore each line of its output begins with the comment character "#": # Please enter the commit message for your changes. Lines starting Use the new status_printf{,_ln,_more} functions to take care of adding "#" to the beginning of such status lines automatically. Using these will have two advantages over the current code: - The obvious one is to force separation of the "#" from the translatable part of the message when git learns to translate its output. - Another advantage is that this makes it easier for us to drop "#" prefix in "git status" output in later versions of git if we want to. Explained-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/commit.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'builtin') diff --git a/builtin/commit.c b/builtin/commit.c index ef5f0b24c..ae62a25f5 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -694,50 +694,51 @@ 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(s->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(s->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(s->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(s->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(s->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(s->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(s->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(s->fp, "#\n"); + status_printf_ln(s, GIT_COLOR_NORMAL, ""); saved_color_setting = s->use_color; s->use_color = 0; -- cgit v1.2.1