##// END OF EJS Templates
bdiff: give slight preference to appending lines...
bdiff: give slight preference to appending lines [This change could be folded into the previous changeset to minimize the repo churn ...] The general preference to matches in the middle of bdiff ranges helps getting balanced recursion and efficient computation. But, as previous changes have shown, it might also give diffs that seems "obviously wrong". To mitigate that: If the best match on the A side starts at the beginning of the bdiff range, don't aim for the middle-most B side match but for the earliest. This will make the matches balanced (by both sides being "early") even though the bisection will be less balanced. Still, this case only apply if the *best* and middle-most match was fully unbalanced on the A side. Each recursion will thus even in this worst case reduce the problem significantly and we are not re-introducing the problem that was fixed in f1ca249696ed. The bundle size for 4.0 (hg bundle --base null -r 4.0 x.hg) happens to go from 22806817 to 22807275 bytes - a 0.002% increase. This make the recent test-bdiff.py changes give a more pretty output ... but they no longer show that the recursion is around middle matches (because it in these cases isn't).

File last commit:

r30432:36334038 default
r30432:36334038 default
Show More
test-bdiff.py
94 lines | 2.4 KiB | text/x-python | PythonLexer
Robert Stanca
py3: use print_function in test-bdiff.py
r28734 from __future__ import absolute_import, print_function
Martin Geisler
removed unused imports
r8656 import struct
Robert Stanca
py3: use absolute_import in test-bdiff.py
r28733 from mercurial import (
bdiff,
mpatch,
)
Martin Geisler
tests: renamed Python tests to .py
r8449
def test1(a, b):
d = bdiff.bdiff(a, b)
c = a
if d:
c = mpatch.patches(a, [d])
if c != b:
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 print("bad diff+patch result from\n %r to\n %r:" % (a, b))
print("bdiff: %r" % d)
print("patched: %r" % c[:200])
Martin Geisler
tests: renamed Python tests to .py
r8449
def test(a, b):
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 print("test", repr(a), repr(b))
Martin Geisler
tests: renamed Python tests to .py
r8449 test1(a, b)
test1(b, a)
test("a\nc\n\n\n\n", "a\nb\n\n\n")
test("a\nb\nc\n", "a\nc\n")
test("", "")
test("a\nb\nc", "a\nb\nc")
test("a\nb\nc\nd\n", "a\nd\n")
test("a\nb\nc\nd\n", "a\nc\ne\n")
test("a\nb\nc\n", "a\nc\n")
test("a\n", "c\na\nb\n")
test("a\n", "")
test("a\n", "b\nc\n")
test("a\n", "c\na\n")
test("", "adjfkjdjksdhfksj")
test("", "ab")
test("", "abc")
test("a", "a")
test("ab", "ab")
test("abc", "abc")
test("a\n", "a\n")
test("a\nb", "a\nb")
#issue1295
def showdiff(a, b):
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 print('showdiff(\n %r,\n %r):' % (a, b))
Martin Geisler
tests: renamed Python tests to .py
r8449 bin = bdiff.bdiff(a, b)
pos = 0
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 q = 0
Martin Geisler
tests: renamed Python tests to .py
r8449 while pos < len(bin):
p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
pos += 12
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 if p1:
print('', repr(a[q:p1]))
print('', p1, p2, repr(a[p1:p2]), '->', repr(bin[pos:pos + l]))
Martin Geisler
tests: renamed Python tests to .py
r8449 pos += l
Mads Kiilerich
tests: make test-bdiff.py easier to maintain...
r30427 q = p2
if q < len(a):
print('', repr(a[q:]))
Martin Geisler
tests: renamed Python tests to .py
r8449 showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\nx\n\nz\n")
showdiff("x\n\nx\n\nx\n\nx\n\nz\n", "x\n\nx\n\ny\n\nx\n\ny\n\nx\n\nz\n")
Matt Mackall
bdiff: deal better with duplicate lines...
r29013 # we should pick up abbbc. rather than bc.de as the longest match
showdiff("a\nb\nb\nb\nc\n.\nd\ne\n.\nf\n",
"a\nb\nb\na\nb\nb\nb\nc\n.\nb\nc\n.\nd\ne\nf\n")
Martin Geisler
tests: renamed Python tests to .py
r8449
Robert Stanca
py3: use print_function in test-bdiff.py
r28734 print("done")
Patrick Mezard
mdiff: replace wscleanup() regexps with C loops...
r15530
def testfixws(a, b, allws):
c = bdiff.fixws(a, allws)
if c != b:
Robert Stanca
py3: use print_function in test-bdiff.py
r28734 print("*** fixws", repr(a), repr(b), allws)
print("got:")
print(repr(c))
Patrick Mezard
mdiff: replace wscleanup() regexps with C loops...
r15530
testfixws(" \ta\r b\t\n", "ab\n", 1)
testfixws(" \ta\r b\t\n", " a b\n", 0)
testfixws("", "", 1)
testfixws("", "", 0)
Robert Stanca
py3: use print_function in test-bdiff.py
r28734 print("done")
Mads Kiilerich
tests: explore some bdiff cases
r30428
Mads Kiilerich
bdiff: give slight preference to longest matches in the middle of the B side...
r30431 print("Nice diff for a trivial change:")
Mads Kiilerich
tests: explore some bdiff cases
r30428 showdiff(
''.join('<%s\n-\n' % i for i in range(5)),
''.join('>%s\n-\n' % i for i in range(5)))
Mads Kiilerich
bdiff: give slight preference to appending lines...
r30432 print("Diff 1 to 3 lines - preference for appending:")
Mads Kiilerich
tests: explore some bdiff cases
r30428 showdiff('a\n', 'a\n' * 3)
Mads Kiilerich
bdiff: give slight preference to appending lines...
r30432 print("Diff 1 to 5 lines - preference for appending:")
Mads Kiilerich
tests: explore some bdiff cases
r30428 showdiff('a\n', 'a\n' * 5)
Mads Kiilerich
bdiff: adjust criteria for getting optimal longest match in the A side middle...
r30429 print("Diff 3 to 1 lines - preference for balanced recursion:")
Mads Kiilerich
tests: explore some bdiff cases
r30428 showdiff('a\n' * 3, 'a\n')
Mads Kiilerich
bdiff: adjust criteria for getting optimal longest match in the A side middle...
r30429 print("Diff 5 to 1 lines - preference for balanced recursion:")
Mads Kiilerich
tests: explore some bdiff cases
r30428 showdiff('a\n' * 5, 'a\n')