# HG changeset patch # User Mads Kiilerich <mad...@unity3d.com> # Date 1479243409 -3600 # Tue Nov 15 21:56:49 2016 +0100 # Node ID efa30442953a6e1f096f8833c4ee8047375600d6 # Parent e022e995415bd48ffe6d4d03dc97b99dd547cde1 bdiff: give slight preference to removing trailing lines
[This change could be folded into the previous changeset to minimize the repo churn ...] Similar to the previous change, introduce an exception to the general preference for matches in the middle of bdiff ranges: If the best match on the B side starts at the beginning of the bdiff range, don't aim for the middle-most A side match but for the earliest. New (later) matches on the A side will only be considered better if the corresponding match on the B side *not* is at the beginning of the range. Thus, if the best (middle-most) match on the B side turns out to be at the beginning of the range, the earliest match on the A side will be used. The bundle size for 4.0 (hg bundle --base null -r 4.0 x.hg) happens to go from 22807275 to 22808120 bytes - a 0.004% increase. diff --git a/mercurial/bdiff.c b/mercurial/bdiff.c --- a/mercurial/bdiff.c +++ b/mercurial/bdiff.c @@ -184,7 +184,7 @@ static int longest_match(struct bdiff_li mj = j; mk = k; } else if (k == mk) { - if (i > mi && i <= half) { + if (i > mi && i <= half && j > b1) { /* same match but closer to half */ mi = i; mj = j; diff --git a/tests/test-bdiff.py b/tests/test-bdiff.py --- a/tests/test-bdiff.py +++ b/tests/test-bdiff.py @@ -88,7 +88,7 @@ print("Diff 1 to 3 lines - preference fo showdiff('a\n', 'a\n' * 3) print("Diff 1 to 5 lines - preference for appending:") showdiff('a\n', 'a\n' * 5) -print("Diff 3 to 1 lines - preference for balanced recursion:") +print("Diff 3 to 1 lines - preference for removing trailing lines:") showdiff('a\n' * 3, 'a\n') -print("Diff 5 to 1 lines - preference for balanced recursion:") +print("Diff 5 to 1 lines - preference for removing trailing lines:") showdiff('a\n' * 5, 'a\n') diff --git a/tests/test-bdiff.py.out b/tests/test-bdiff.py.out --- a/tests/test-bdiff.py.out +++ b/tests/test-bdiff.py.out @@ -68,17 +68,15 @@ showdiff( 'a\na\na\na\na\n'): 'a\n' 2 2 '' -> 'a\na\na\na\n' -Diff 3 to 1 lines - preference for balanced recursion: +Diff 3 to 1 lines - preference for removing trailing lines: showdiff( 'a\na\na\n', 'a\n'): - 0 2 'a\n' -> '' 'a\n' - 4 6 'a\n' -> '' -Diff 5 to 1 lines - preference for balanced recursion: + 2 6 'a\na\n' -> '' +Diff 5 to 1 lines - preference for removing trailing lines: showdiff( 'a\na\na\na\na\n', 'a\n'): - 0 4 'a\na\n' -> '' 'a\n' - 6 10 'a\na\n' -> '' + 2 10 'a\na\na\na\n' -> '' _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel