Patchwork D2575: xdiff: add a bdiff hunk mode

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 8:30 p.m.
Message ID <ff6dac26c9ea75c14cb9c74a76ce9122@localhost.localdomain>
Download mbox | patch
Permalink /patch/28836/
State Not Applicable
Headers show

Comments

phabricator - March 3, 2018, 8:30 p.m.
quark updated this revision to Diff 6474.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2575?vs=6457&id=6474

REVISION DETAIL
  https://phab.mercurial-scm.org/D2575

AFFECTED FILES
  mercurial/thirdparty/xdiff/xdiff.h
  mercurial/thirdparty/xdiff/xdiffi.c

CHANGE DETAILS




To: ryanmce, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/thirdparty/xdiff/xdiffi.c b/mercurial/thirdparty/xdiff/xdiffi.c
--- a/mercurial/thirdparty/xdiff/xdiffi.c
+++ b/mercurial/thirdparty/xdiff/xdiffi.c
@@ -975,15 +975,32 @@ 
 			      xdemitconf_t const *xecfg)
 {
 	xdchange_t *xch, *xche;
-
-	for (xch = xscr; xch; xch = xche->next) {
-		xche = xdl_get_hunk(&xch, xecfg);
-		if (!xch)
-			break;
-		if (xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1,
-				     xch->i2, xche->i2 + xche->chg2 - xch->i2,
-				     ecb->priv) < 0)
+	if ((xecfg->flags & XDL_EMIT_BDIFFHUNK) != 0) {
+		long i1 = 0, i2 = 0, n1 = xe->xdf1.nrec, n2 = xe->xdf2.nrec;
+		for (xch = xscr; xch; xch = xche->next) {
+			xche = xdl_get_hunk(&xch, xecfg);
+			if (!xch)
+				break;
+			if (xch->i1 > i1 || xch->i2 > i2) {
+				if (xecfg->hunk_func(i1, xch->i1, i2, xch->i2, ecb->priv) < 0)
+					return -1;
+			}
+			i1 = xche->i1 + xche->chg1;
+			i2 = xche->i2 + xche->chg2;
+		}
+		if (xecfg->hunk_func(i1, n1, i2, n2, ecb->priv) < 0)
 			return -1;
+	} else {
+		for (xch = xscr; xch; xch = xche->next) {
+			xche = xdl_get_hunk(&xch, xecfg);
+			if (!xch)
+				break;
+			if (xecfg->hunk_func(
+					xch->i1, xche->i1 + xche->chg1 - xch->i1,
+					xch->i2, xche->i2 + xche->chg2 - xch->i2,
+					ecb->priv) < 0)
+				return -1;
+		}
 	}
 	return 0;
 }
@@ -1026,18 +1043,15 @@ 
 		xdl_free_env(&xe);
 		return -1;
 	}
-	if (xscr) {
-		if (xpp->flags & XDF_IGNORE_BLANK_LINES)
-			xdl_mark_ignorable(xscr, &xe, xpp->flags);
-
-		if (ef(&xe, xscr, ecb, xecfg) < 0) {
 
-			xdl_free_script(xscr);
-			xdl_free_env(&xe);
-			return -1;
-		}
+	if (xpp->flags & XDF_IGNORE_BLANK_LINES)
+		xdl_mark_ignorable(xscr, &xe, xpp->flags);
+	if (ef(&xe, xscr, ecb, xecfg) < 0) {
 		xdl_free_script(xscr);
+		xdl_free_env(&xe);
+		return -1;
 	}
+	xdl_free_script(xscr);
 	xdl_free_env(&xe);
 
 	return 0;
diff --git a/mercurial/thirdparty/xdiff/xdiff.h b/mercurial/thirdparty/xdiff/xdiff.h
--- a/mercurial/thirdparty/xdiff/xdiff.h
+++ b/mercurial/thirdparty/xdiff/xdiff.h
@@ -48,6 +48,9 @@ 
 /* xdemitconf_t.flags */
 #define XDL_EMIT_FUNCNAMES (1 << 0)
 #define XDL_EMIT_FUNCCONTEXT (1 << 2)
+/* emit bdiff-style "matched" (a1, a2, b1, b2) hunks instead of "different"
+ * (a1, a2 - a1, b1, b2 - b1) hunks */
+#define XDL_EMIT_BDIFFHUNK (1 << 4)
 
 #define XDL_MMB_READONLY (1 << 0)