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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Antoine Pelisse <apelisse@xxxxxxxxx> writes:

> 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]