summaryrefslogtreecommitdiff
path: root/xdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2016-05-28 15:02:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-05-31 20:08:56 (GMT)
commit392f6d316623e8ecd6210248ba9ae2cabf07352b (patch)
tree1991158ad53833e30253d96de495625b9173cf80 /xdiff
parent6d5badb2389d5d1d0752a230cd7ee74bb4043893 (diff)
downloadgit-392f6d316623e8ecd6210248ba9ae2cabf07352b.zip
git-392f6d316623e8ecd6210248ba9ae2cabf07352b.tar.gz
git-392f6d316623e8ecd6210248ba9ae2cabf07352b.tar.bz2
xdiff: ignore empty lines before added functions with -W
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. Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff')
-rw-r--r--xdiff/xemit.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 969100d..29cec12 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, long ri)
+{
+ const char *rec;
+ long len = xdl_get_rec(xdf, ri, &rec);
+
+ while (len > 0 && XDL_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, i2))
+ i2++;
+ if (i2 < xe->xdf2.nrec &&
+ match_func_rec(&xe->xdf2, xecfg, i2,
dummy, sizeof(dummy)) >= 0)
goto post_context_calculation;