Example #1
0
 def _alldiffchunks(a, b, alines, blines):
     """like mdiff.allblocks, but only care about differences"""
     blocks = mdiff.allblocks(a, b, lines1=alines, lines2=blines)
     for chunk, btype in blocks:
         if btype != '!':
             continue
         yield chunk
Example #2
0
 def _alldiffchunks(a, b, alines, blines):
     """like mdiff.allblocks, but only care about differences"""
     blocks = mdiff.allblocks(a, b, lines1=alines, lines2=blines)
     for chunk, btype in blocks:
         if btype != b'!':
             continue
         yield chunk
Example #3
0
 def setUp(self):
     self.blocks = list(mdiff.allblocks(text1, text2))
     assert self.blocks == [
         ([0, 3, 0, 2], b'!'),
         ((3, 7, 2, 6), b'='),
         ([7, 12, 6, 12], b'!'),
         ((12, 12, 12, 12), b'='),
     ], self.blocks
Example #4
0
def difflineranges(content1, content2):
    """Return list of line number ranges in content2 that differ from content1.

    Line numbers are 1-based. The numbers are the first and last line contained
    in the range. Single-line ranges have the same line number for the first and
    last line. Excludes any empty ranges that result from lines that are only
    present in content1. Relies on mdiff's idea of where the line endings are in
    the string.

    >>> from mercurial import pycompat
    >>> lines = lambda s: b'\\n'.join([c for c in pycompat.iterbytestr(s)])
    >>> difflineranges2 = lambda a, b: difflineranges(lines(a), lines(b))
    >>> difflineranges2(b'', b'')
    []
    >>> difflineranges2(b'a', b'')
    []
    >>> difflineranges2(b'', b'A')
    [(1, 1)]
    >>> difflineranges2(b'a', b'a')
    []
    >>> difflineranges2(b'a', b'A')
    [(1, 1)]
    >>> difflineranges2(b'ab', b'')
    []
    >>> difflineranges2(b'', b'AB')
    [(1, 2)]
    >>> difflineranges2(b'abc', b'ac')
    []
    >>> difflineranges2(b'ab', b'aCb')
    [(2, 2)]
    >>> difflineranges2(b'abc', b'aBc')
    [(2, 2)]
    >>> difflineranges2(b'ab', b'AB')
    [(1, 2)]
    >>> difflineranges2(b'abcde', b'aBcDe')
    [(2, 2), (4, 4)]
    >>> difflineranges2(b'abcde', b'aBCDe')
    [(2, 4)]
    """
    ranges = []
    for lines, kind in mdiff.allblocks(content1, content2):
        firstline, lastline = lines[2:4]
        if kind == b'!' and firstline != lastline:
            ranges.append((firstline + 1, lastline))
    return ranges
Example #5
0
 def _diffblocks(self, a, b):
     return mdiff.allblocks(a, b, self.opts.diffopts)