Skip to content

Commit d2f8295

Browse files
torvaldsgitster
authored andcommitted
Re(-re)*fix trim_common_tail()
The tar-ball and the git archive itself is fine, but yes, the diff from 2.6.23 to 2.6.24-rc6 is bad. It's the "trim_common_tail()" optimization that has caused way too much pain. Very interesting breakage. The patch was actually "correct" in a (rather limited) technical sense, but the context at the end was missing because while the trim_common_tail() code made sure to keep enough common context to allow a valid diff to be generated, the diff machinery itself could decide that it could generate the diff differently than the "obvious" solution. Thee sad fact is that the git optimization (which is very important for "git blame", which needs no context), is only really valid for that one case where we really don't need any context. [jc: since this is shared with "git diff -U0" codepath, context recovery to the end of line needs to be done even for zero context case.] Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d76a585 commit d2f8295

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

xdiff-interface.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,20 @@ static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx)
115115
char *bp = b->ptr + b->size;
116116
long smaller = (a->size < b->size) ? a->size : b->size;
117117

118+
if (ctx)
119+
return;
120+
118121
while (blk + trimmed <= smaller && !memcmp(ap - blk, bp - blk, blk)) {
119122
trimmed += blk;
120123
ap -= blk;
121124
bp -= blk;
122125
}
123126

124-
while (recovered < trimmed && 0 <= ctx)
127+
while (recovered < trimmed)
125128
if (ap[recovered++] == '\n')
126-
ctx--;
127-
a->size -= (trimmed - recovered);
128-
b->size -= (trimmed - recovered);
129+
break;
130+
a->size -= trimmed - recovered;
131+
b->size -= trimmed - recovered;
129132
}
130133

131134
int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *xecb)

0 commit comments

Comments
 (0)