git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] diff: add --ignore-blank-lines option

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 9, 2013, 21:28 UTC
Message-ID
<7vtxl7nfcd.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CALWbr2xijB+UD9gwc+HmMdHM9OT+2Lzr9w3h22=CegKHK-Ocng@mail.gmail.com>
Antoine Pelisse <apelisse@gmail.com> writes:
Show 10 quoted lines
> It might be kind of noisy, but I think trying to improve the solution
> might lead to over-engineering.
> How would we compute the "minimal distance between interesting and
> blank" so that the blank becomes interesting ?
> Using the context size for that is quite convenient, while creating
> another variable would probably become overkill..
>
> The original goal is to remove hunks created solely for
> addition/suppression, and I think it's what it should do for the
> moment.

Something like this on top of your original one is what I had in mind as a starting point.

 t/t4015-diff-whitespace.sh |  5 +----
 xdiff/xemit.c              | 45 ++++++++++++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index b3c4fcc..acc2159 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -185,7 +185,7 @@ test_expect_success 'ignore-blank-lines: with changes' '
 	git diff --ignore-blank-lines >out.tmp &&
 	sed -e "1,/^+++ b\/x/d" <out.tmp >out &&
 	cat <<-\EOF >expect &&
-	@@ -1,6 +2,7 @@
+	@@ -1,11 +2,14 @@
 	 1
 	 2
 	 3
@@ -193,9 +193,6 @@ test_expect_success 'ignore-blank-lines: with changes' '
 	 4
 	 5
 	 6
-	@@ -5,7 +7,9 @@
-	 5
-	 6
 	 7
 	+
 	 8
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 52dfef8..27e1105 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -59,32 +59,39 @@ static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *
  * Also advance xscr if the first changes must be discareded.
  */
 xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg) {
-	xdchange_t *xch, *xchp;
+	xdchange_t *xch, *xchp = NULL, *xch_start = NULL;
 	long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;
-	long ignorable_context = max_common / 2 - 1;
-	int interesting = 0;
 
-	for (xchp = *xscr, xch = (*xscr)->next; xch; xchp = xch, xch = xch->next) {
-		long thresh;
-		if (xchp->ignore || xch->ignore)
-			thresh = ignorable_context;
-		else
-			thresh = max_common;
-
-		if (!xchp->ignore)
-			interesting = 1;
+	/* Skip the ones that can be ignored from the beginning */
+	for (xch = *xscr; xch; xch = xch->next) {
+		if (xch->ignore)
+			continue;
+		xch_start = xch;
+		break;
+	}
 
-		if (xch->i1 - (xchp->i1 + xchp->chg1) > thresh) {
-			if (interesting)
+	for (xchp = xch_start; xchp; ) {
+		/* Find the next one that is not ignored */
+		for (xch = xchp->next; xch; xch = xch->next)
+			if (!xch->ignore)
 				break;
-			else
-				*xscr = xch;
+		if (!xch)
+			break; /* show xch_start thru xchp */
+
+		/* are these hunks close enough? */
+		if ((xchp->i1 + xchp->chg1) - xch->i1 < max_common) {
+			xchp = xch;
+			continue;
 		}
-	}
 
-	if (!interesting && xchp->ignore)
-		*xscr = NULL;
+		/*
+		 * otherwise, xchp is the last one (inclusive) we want
+		 * to coalesce into a single output hunk.
+		 */
+		break;
+	}
 
+	*xscr = xch_start;
 	return xchp;
 }
 
-- 
1.8.3-477-gc2fede3
Previous: Antoine PelisseNext: Antoine Pelisse
Message 13 of 26 in “diff: add --ignore-blank-lines option”
  1. diff: add --ignore-blank-lines optionAntoine Pelisse, May 26, 2013
  2. Johannes SixtMay 26, 2013
  3. Antoine PelisseMay 27, 2013
  4. Antoine PelisseJun 1, 2013
  5. Junio C HamanoJun 4, 2013
  6. Antoine PelisseJun 4, 2013
  7. Junio C HamanoJun 4, 2013
  8. Antoine PelisseJun 4, 2013
  9. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 8, 2013
  10. Eric SunshineJun 9, 2013
  11. Junio C HamanoJun 9, 2013
  12. Antoine PelisseJun 9, 2013
  13. Junio C HamanoJun 9, 2013
  14. Antoine PelisseJun 10, 2013
  15. Junio C HamanoJun 10, 2013
  16. Antoine PelisseJun 12, 2013
  17. Junio C HamanoJun 12, 2013
  18. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 15, 2013
  19. Junio C HamanoJun 17, 2013
  20. Antoine PelisseJun 17, 2013
  21. Antoine PelisseJun 17, 2013
  22. Junio C HamanoJun 17, 2013
  23. Antoine PelisseJun 17, 2013
  24. Junio C HamanoJun 17, 2013
  25. diff: add --ignore-blank-lines optionAntoine Pelisse, Jun 19, 2013
  26. Junio C HamanoJun 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.