From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>
Subject: [PATCH 4/5] commit: refer to commit template as s->fp
Date: Fri, 25 Feb 2011 23:10:49 -0600 [thread overview]
Message-ID: <20110226051049.GD27887@elie> (raw)
In-Reply-To: <20110226050723.GA27864@elie>
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 <jrnieder@gmail.com>
---
builtin/commit.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index d7f55e3..ef5f0b2 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))) {
--
1.7.4.1
next prev parent reply other threads:[~2011-02-26 5:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-26 5:07 [PATCH/RFC 0/5] status, commit: separate "# " from the translatable part of output Jonathan Nieder
2011-02-26 5:08 ` [PATCH 1/5] compat: provide a fallback va_copy definition Jonathan Nieder
2011-02-26 5:08 ` [PATCH 2/5] strbuf: add strbuf_vaddf Jonathan Nieder
2011-02-26 5:09 ` [PATCH 3/5] wt-status: add helpers for printing wt-status lines Jonathan Nieder
2011-02-26 5:10 ` Jonathan Nieder [this message]
2011-02-26 5:11 ` [PATCH 5/5] commit, status: use status_printf{,_ln,_more} helpers Jonathan Nieder
2011-02-27 9:11 ` Junio C Hamano
2011-02-27 9:50 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110226051049.GD27887@elie \
--to=jrnieder@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).