Thread (2 messages) flat view 2 messages, 2 authors, 2016-06-15

Re: [PATCH] add boolean diff.suppress-blank-empty config option

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:10

Jim Meyering [off-list ref] writes:
GNU diff's --suppress-blank-empty option makes it so that diff does not
add a space or tab before each empty output line of context.  With this
option, empty context lines are empty also in "git diff" output.
Before (and without the option), they'd have a single trailing space.
quoted hunk ↗ jump to hunk
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 61dc5c5..5544e5a 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -66,6 +66,13 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
 	struct xdiff_emit_state *priv = priv_;
 	int i;

+	if (priv->suppress_blank_empty
+	    && mb[0].size == 1
+	    && mb[0].ptr[0] == ' '
+	    && mb[1].size == 1
+	    && mb[1].ptr[0] == '\n')
+	  mb[0].size = 0;
+
 	for (i = 0; i < nbuf; i++) {
 		if (mb[i].ptr[mb[i].size-1] != '\n') {
 			/* Incomplete line */
I do not have a fundamental objection to the optional behaviour, but from
technical point of view, I had to wonder if hooking to xdiff_outf() has
funny interactions with codepaths that use patch-id (namely, git-rebase,
git-format-patch, and git-cherry).  Luckily, patch-ids are computed over
non whitespaces, so it turns out to be Ok, but there may be other
unintended side effects that I haven't thought about.

I would have preferred the option to hook into a bit higher layer (namely,
the part that actually writes textual diff to the output stream).
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help