Skip to content

Commit e0876bc

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9e6a4cf commit e0876bc

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

t/t4051-diff-function-context.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ test_expect_success ' context includes begin' '
145145
grep "^ .*Begin of first part" long_common_tail.diff
146146
'
147147

148-
test_expect_failure ' context includes end' '
148+
test_expect_success ' context includes end' '
149149
grep "^ .*End of second part" long_common_tail.diff
150150
'
151151

xdiff-interface.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,16 @@ static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
100100

101101
/*
102102
* Trim down common substring at the end of the buffers,
103-
* but leave at least ctx lines at the end.
103+
* but end on a complete line.
104104
*/
105-
static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
105+
static void trim_common_tail(mmfile_t *a, mmfile_t *b)
106106
{
107107
const int blk = 1024;
108108
long trimmed = 0, recovered = 0;
109109
char *ap = a->ptr + a->size;
110110
char *bp = b->ptr + b->size;
111111
long smaller = (a->size < b->size) ? a->size : b->size;
112112

113-
if (ctx)
114-
return;
115-
116113
while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) {
117114
trimmed += blk;
118115
ap -= blk;
@@ -134,7 +131,8 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co
134131
if (mf1->size > MAX_XDIFF_SIZE || mf2->size > MAX_XDIFF_SIZE)
135132
return -1;
136133

137-
trim_common_tail(&a, &b, xecfg->ctxlen);
134+
if (!xecfg->ctxlen && !(xecfg->flags & XDL_EMIT_FUNCCONTEXT))
135+
trim_common_tail(&a, &b);
138136

139137
return xdl_diff(&a, &b, xpp, xecfg, xecb);
140138
}

0 commit comments

Comments
 (0)