Re: [PATCH v2] builtin-commit: Include the diff in the commit message when verbose.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2] builtin-commit: Include the diff in the commit message when verbose.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:53

Johannes Schindelin [off-list ref] writes:
On Wed, 21 Nov 2007, Kristian Høgsberg wrote:
quoted
+
+	/* 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);
+
Is this related to the change in wt_status?  If so, wouldn't we want to 
suppress the diff, instead of generating it, and then killing it later?
This corresponds to the sed script near l.545 in git-commit.sh.

I've been wondering if it would be better not to have this logic
but instead "git commit -v" to show the diff text prefixed with
'# ' to make it a proper comment, by the way.
Besides, you'd want to leave the \n there: strbuf_setlen(&sb, p + 1 - 
sb.buf);
Yup.
quoted
+	/* Sigh, the entire diff machinery is hardcoded to output to
+	 * stdout.  Do the dup-dance...*/
I wonder how much effort it would be to change that.  Not that it would 
help too much, since we want the output in a strbuf anyway.
The codepath is preparing COMMIT_EDITMSG file for the user to
edit (or to the standard output, if this is "git status -v").

I do not know about "strbuf" part; resulting patch text could be
large and in most cases the callers would rather flush it to
outside (either pipe or file) as soon as possible than having to
keep it all in core.

I was trying to do the stdout -> FILE *fp conversion of diff.c
last night but dropped it halfway, after finding one puts()
misconversion and fixing it.  The changes should mostly be
straightforward but the result felt ugly.

Re: [PATCH v2] builtin-commit: Include the diff in the commit message when verbose.

From: Kristian Høgsberg <hidden>
Date: 2016-06-15 22:43:53

On Thu, 2007-11-22 at 11:14 -0800, Junio C Hamano wrote:
Johannes Schindelin [off-list ref] writes:
quoted
On Wed, 21 Nov 2007, Kristian Høgsberg wrote:
quoted
+
+	/* 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);
+
Is this related to the change in wt_status?  If so, wouldn't we want to 
suppress the diff, instead of generating it, and then killing it later?
This corresponds to the sed script near l.545 in git-commit.sh.

I've been wondering if it would be better not to have this logic
but instead "git commit -v" to show the diff text prefixed with
'# ' to make it a proper comment, by the way.
Yeah, that would be nicer... I think the best way to do this is to do a
formatting callback for the diff machinery as Jeff suggests, which can
then prefix '# ' and write it to a FILE *.
quoted
Besides, you'd want to leave the \n there: strbuf_setlen(&sb, p + 1 - 
sb.buf);
Yup.
Right, off-by-one.  Effectively it doesn't make a difference, since
there will always be a comment line above the diff,  When stripspace
removes the comments it fixes up the end-of-line problem.  Patch below.

cheers,
Kristian

From 58eac54a00d3eb6a311c6fb4faa67eb831c60e01 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Kristian=20H=C3=B8gsberg?= <redacted>
Date: Mon, 26 Nov 2007 10:16:08 -0500
Subject: [PATCH] Fix off-by-one error when truncating the diff out of the commit message.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Kristian Høgsberg <redacted>
---
 builtin-commit.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 45e51b1..330f778 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -762,7 +762,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	/* 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);
+		strbuf_setlen(&sb, p - sb.buf + 1);
 
 	stripspace(&sb, 1);
 	if (sb.len < header_len || message_is_empty(&sb, header_len)) {
-- 
1.5.3.4.206.g58ba4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help