diff options
author | René Scharfe <l.s.r@web.de> | 2016-05-28 17:04:31 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-05-31 13:08:56 -0700 |
commit | e0876bca4de44638a1cb51b03bdf0a40df631a80 (patch) | |
tree | eb3fd50f21adb94deee1823a68467b43cb002e3b | |
parent | 9e6a4cfc38aa81055d0b7d6fb94dc7b31809daa9 (diff) | |
download | git-e0876bca4de44638a1cb51b03bdf0a40df631a80.tar.gz git-e0876bca4de44638a1cb51b03bdf0a40df631a80.tar.xz |
xdiff: don't trim common tail with -W
The function trim_common_tail() exits early if context lines are
requested. If -U0 and -W are specified together then it can still trim
context lines that might belong to a changed function. As a result
that function is shown incompletely.
Fix that by calling trim_common_tail() only if no function context or
fixed context is requested. The parameter ctx is no longer needed now;
remove it.
While at it fix an outdated comment as well.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-x | t/t4051-diff-function-context.sh | 2 | ||||
-rw-r--r-- | xdiff-interface.c | 10 |
2 files changed, 5 insertions, 7 deletions
diff --git a/t/t4051-diff-function-context.sh b/t/t4051-diff-function-context.sh index 17616fe58..b6bb04ab8 100755 --- a/t/t4051-diff-function-context.sh +++ b/t/t4051-diff-function-context.sh @@ -145,7 +145,7 @@ test_expect_success ' context includes begin' ' grep "^ .*Begin of first part" long_common_tail.diff ' -test_expect_failure ' context includes end' ' +test_expect_success ' context includes end' ' grep "^ .*End of second part" long_common_tail.diff ' diff --git a/xdiff-interface.c b/xdiff-interface.c index 54236f24b..f34ea762e 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -100,9 +100,9 @@ static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) /* * Trim down common substring at the end of the buffers, - * but leave at least ctx lines at the end. + * but end on a complete line. */ -static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx) +static void trim_common_tail(mmfile_t *a, mmfile_t *b) { const int blk = 1024; long trimmed = 0, recovered = 0; @@ -110,9 +110,6 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx) char *bp = b->ptr + b->size; long smaller = (a->size < b->size) ? a->size : b->size; - if (ctx) - return; - while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) { trimmed += blk; ap -= blk; @@ -134,7 +131,8 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co if (mf1->size > MAX_XDIFF_SIZE || mf2->size > MAX_XDIFF_SIZE) return -1; - trim_common_tail(&a, &b, xecfg->ctxlen); + if (!xecfg->ctxlen && !(xecfg->flags & XDL_EMIT_FUNCCONTEXT)) + trim_common_tail(&a, &b); return xdl_diff(&a, &b, xpp, xecfg, xecb); } |