1
# Copyright (C) 2005 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
# Author: Martin Pool <mbp@canonical.com>
20
from nofrillsprecisemerge import recurse_matches
21
from bzrlib.errors import BzrError
24
class SequenceMatcher(difflib.SequenceMatcher):
25
"""This is a class which attempts to look something like difflib's SequenceMatcher"""
27
def find_longest_match(self, alo, ahi, blo, bhi):
28
raise NotImplementedError
30
def get_matching_blocks(self):
31
"""Return list of triples describing matching subsequences.
33
Each triple is of the form (i, j, n), and means that
34
a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in
37
The last triple is a dummy, (len(a), len(b), 0), and is the only
40
>>> s = SequenceMatcher(None, "abxcd", "abcd")
41
>>> s.get_matching_blocks()
42
[(0, 0, 2), (3, 2, 2), (5, 4, 0)]
47
recurse_matches(a, b, len(a), len(b), matches, 10)
48
# Matches now has individual line pairs of
49
# line A matches line B, at the given offsets
52
start_a = start_b = None
54
for i_a, i_b in matches:
55
if (start_a is not None
56
and (i_a == start_a + length)
57
and (i_b == start_b + length)):
61
if start_a is not None:
62
match_blocks.append((start_a, start_b, length))
68
match_blocks.append((start_a, start_b, length))
70
match_blocks.append((len(a), len(b), 0))