X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=xdiff-interface.c;h=bba236428adb0b34421b9f1b5a3a1728911ee406;hb=ca132089d2c7628fb6bca59715ece342777bdaf0;hp=700def211e25a61591d4609ef19d64d91319f33e;hpb=29ab27f4b505dd6a56ded42ab2797c3e56f810b2;p=git.git diff --git a/xdiff-interface.c b/xdiff-interface.c index 700def211..bba236428 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -110,23 +110,25 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf) static void trim_common_tail(mmfile_t *a, mmfile_t *b, long ctx) { const int blk = 1024; - long trimmed = 0, recovered = 0, i; + long trimmed = 0, recovered = 0; char *ap = a->ptr + a->size; 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; bp -= blk; } - for (i = 0, recovered = 0; recovered < trimmed && i <= ctx; i++) { - while (recovered < trimmed && ap[recovered] != '\n') - recovered++; - } - a->size -= (trimmed - recovered); - b->size -= (trimmed - recovered); + while (recovered < trimmed) + if (ap[recovered++] == '\n') + break; + a->size -= trimmed - recovered; + b->size -= trimmed - recovered; } int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *xecb) @@ -231,8 +233,7 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value) expression = value; if (regcomp(®->re, expression, 0)) die("Invalid regexp to look for hunk header: %s", expression); - if (buffer) - free(buffer); + free(buffer); value = ep + 1; } }