~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/cdv/cdvdifflib.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-10 03:59:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: john@arbash-meinel.com-20051110035926-e391fd93199f0537
Added some more test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
# Author: Martin Pool <mbp@canonical.com>
18
 
 
19
17
 
20
18
from nofrillsprecisemerge import recurse_matches
21
19
from bzrlib.errors import BzrError
51
49
                # New block
52
50
                if start_a is not None:
53
51
                    answer.append((start_a+alo, start_b+blo, length))
 
52
                    # WORKAROUND
 
53
                    # recurse_matches has an implementation design
 
54
                    # which does not match non-unique lines in the
 
55
                    # if they do not touch matching unique lines
 
56
                    # so we rerun the regular diff algorithm
 
57
                    # if find a large enough chunk.
 
58
 
 
59
                    last_match_a = start_a + length
 
60
                    last_match_b = start_b + length
 
61
                    # recurse_matches already looked at the direct
 
62
                    # neighbors, so we only need to run if there is
 
63
                    # enough space to do so
 
64
                    if (i_a - last_match_a > 2
 
65
                        and i_b - last_match_b > 2):
 
66
                        m = SequenceMatcher(None,
 
67
                                            a[last_match_a+1:i_a-1],
 
68
                                            b[last_match_b+1:i_b-1])
 
69
                        new_blocks = m.get_matching_blocks()
 
70
                        # difflib always adds a final match
 
71
                        new_blocks.pop()
 
72
                        for blk in new_blocks:
 
73
                            answer.append((blk[0]+last_match_a+1,
 
74
                                           blk[1]+last_match_b+1,
 
75
                                           blk[2]))
54
76
                start_a = i_a
55
77
                start_b = i_b
56
78
                length = 1