git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kristian Høgsberg" <krh@redhat.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, "Kristian Høgsberg" <krh@redhat.com>
Subject: [PATCH v2] builtin-commit: Include the diff in the commit message when verbose.
Date: Wed, 21 Nov 2007 21:54:49 -0500	[thread overview]
Message-ID: <1195700089-8326-1-git-send-email-krh@redhat.com> (raw)

run_diff_index() and the entire diff machinery is hard coded to output
to stdout, so just redirect that and restore it when done.

Signed-off-by: Kristian Høgsberg <krh@redhat.com>
---

Thinking about this, the dup-dance really belongs in wt-status.c since
that interface promises that it can redirect to a FILE *.  Also the
fflush()'es in the earlier patch could go wrong if stdout ends up flushing
during run_diff_index() and fp has unflushed data.

 builtin-commit.c |    8 +++++++-
 wt-status.c      |   16 ++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index e8893f8..39764ae 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -662,7 +662,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	int header_len;
 	struct strbuf sb;
 	const char *index_file, *reflog_msg;
-	char *nl;
+	char *nl, *p;
 	unsigned char commit_sha1[20];
 	struct ref_lock *ref_lock;
 
@@ -758,6 +758,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		rollback_index_files();
 		exit(1);
 	}
+
+	/* Truncate the message just before the diff, if any. */
+	p = strstr(sb.buf, "\ndiff --git a/");
+	if (p != NULL)
+		strbuf_setlen(&sb, p - sb.buf);
+
 	stripspace(&sb, 1);
 	if (sb.len < header_len || message_is_empty(&sb, header_len)) {
 		rollback_index_files();
diff --git a/wt-status.c b/wt-status.c
index d3c10b8..0e0439f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -315,12 +315,28 @@ static void wt_status_print_untracked(struct wt_status *s)
 static void wt_status_print_verbose(struct wt_status *s)
 {
 	struct rev_info rev;
+	int saved_stdout;
+
+	fflush(s->fp);
+
+	/* Sigh, the entire diff machinery is hardcoded to output to
+	 * stdout.  Do the dup-dance...*/
+	saved_stdout = dup(STDOUT_FILENO);
+	if (saved_stdout < 0 ||dup2(fileno(s->fp), STDOUT_FILENO) < 0)
+		die("couldn't redirect stdout\n");
+
 	init_revisions(&rev, NULL);
 	setup_revisions(0, NULL, &rev, s->reference);
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 	rev.diffopt.detect_rename = 1;
 	wt_read_cache(s);
 	run_diff_index(&rev, 1);
+
+	fflush(stdout);
+
+	if (dup2(saved_stdout, STDOUT_FILENO) < 0)
+		die("couldn't restore stdout\n");
+	close(saved_stdout);
 }
 
 void wt_status_print(struct wt_status *s)
-- 
1.5.3.4

             reply	other threads:[~2007-11-22  2:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-22  2:54 Kristian Høgsberg [this message]
2007-11-22 10:52 ` [PATCH v2] builtin-commit: Include the diff in the commit message when verbose Johannes Schindelin
2007-11-22 11:13   ` Jeff King
2007-11-22 19:14   ` Junio C Hamano
2007-11-26 15:21     ` Kristian Høgsberg

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=1195700089-8326-1-git-send-email-krh@redhat.com \
    --to=krh@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).