git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org
Subject: [PATCH 3/5] diff: ignore empty lines before added functions with -W
Date: Sat, 21 May 2016 20:46:13 +0200	[thread overview]
Message-ID: <5740ACF5.4060107@web.de> (raw)
In-Reply-To: <5740AC28.6010202@web.de>

If a new function and a preceding empty line is appended, diff -W shows
the previous function in full in order to provide context for that empty
line.  In most languages empty lines between sections are not 
interesting in and off themselves and showing a whole extra function for
them is not what we want.

Skip empty lines when checking of the appended chunk starts with a
function line, thereby avoiding to extend the context just for them.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 xdiff/xemit.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 969100d..087956a 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -155,6 +155,18 @@ static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
 	return -1;
 }
 
+static int is_empty_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
+{
+	const char *rec;
+	long len = xdl_get_rec(xdf, ri, &rec);
+
+	while (len > 0 && isspace(*rec)) {
+		rec++;
+		len--;
+	}
+	return !len;
+}
+
 int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 		  xdemitconf_t const *xecfg) {
 	long s1, s2, e1, e2, lctx;
@@ -176,12 +188,18 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
 			/* Appended chunk? */
 			if (i1 >= xe->xdf1.nrec) {
 				char dummy[1];
+				long i2 = xch->i2;
 
 				/*
 				 * We don't need additional context if
-				 * a whole function was added.
+				 * a whole function was added, possibly
+				 * starting with empty lines.
 				 */
-				if (match_func_rec(&xe->xdf2, xecfg, xch->i2,
+				while (i2 < xe->xdf2.nrec &&
+				       is_empty_rec(&xe->xdf2, xecfg, i2))
+					i2++;
+				if (i2 < xe->xdf2.nrec &&
+				    match_func_rec(&xe->xdf2, xecfg, i2,
 						   dummy, sizeof(dummy)) >= 0)
 					goto post_context_calculation;
 
-- 
2.8.3

  parent reply	other threads:[~2016-05-21 18:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10 21:51 [Bug?] log -p -W showing the whole file for a patch that adds to the end? Junio C Hamano
2016-05-10 22:51 ` Junio C Hamano
2016-05-12 22:12   ` René Scharfe
2016-05-21 18:42   ` René Scharfe
2016-05-21 18:45     ` [PATCH 1/5] diff: factor out match_func_rec() René Scharfe
2016-05-21 18:45     ` [PATCH 2/5] diff: handle appended chunks better with -W René Scharfe
2016-05-21 18:46     ` René Scharfe [this message]
2016-05-21 18:46     ` [PATCH 4/5] diff: don't include common trailing empty lines " René Scharfe
2016-05-21 18:47     ` [PATCH 5/5] grep: don't extend context to " René Scharfe
2016-05-24 18:16     ` [Bug?] log -p -W showing the whole file for a patch that adds to the end? Junio C Hamano
2016-05-26  8:54       ` René Scharfe
2016-05-26 17:05         ` Junio C Hamano
2016-05-27 17:13           ` René Scharfe
2016-05-28 14:46     ` René Scharfe
2016-05-28 14:57       ` [PATCH v2 1/8] t4051: rewrite, add more tests René Scharfe
2016-05-29 23:55         ` Junio C Hamano
2016-05-30 20:55           ` René Scharfe
2016-05-31 20:00           ` [PATCH v2.5 " René Scharfe
2016-05-31 20:15             ` René Scharfe
2016-05-31 21:23             ` Junio C Hamano
2016-05-28 14:58       ` [PATCH v2 2/8] xdiff: factor out match_func_rec() René Scharfe
2016-05-28 15:00       ` [PATCH v2 3/8] xdiff: handle appended chunks better with -W René Scharfe
2016-05-28 15:02       ` [PATCH v2 4/8] xdiff: ignore empty lines before added functions " René Scharfe
2016-05-28 15:03       ` [PATCH v2 5/8] xdiff: -W: don't include common trailing empty lines in context René Scharfe
2016-05-28 15:04       ` [PATCH v2 6/8] xdiff: don't trim common tail with -W René Scharfe
2016-05-28 15:05       ` [PATCH v2 7/8] t7810: add test for grep -W and trailing empty context lines René Scharfe
2016-05-28 15:06       ` [PATCH v2 8/8] grep: -W: don't extend context to trailing empty lines René Scharfe

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5740ACF5.4060107@web.de \
    --to=l.s.r@web.de \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).