git-p4: place temporary refs used for branch import under refs/git-p4-tmp
[gitweb.git] / xdiff-interface.c
index 54236f24b9786710f91650ac63f6004cdeb012e6..f34ea762e477d9874ef8d75e24f54230520a6e4b 100644 (file)
@@ -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);
 }