~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-12 22:16:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20060912221638-bf11ba3e3f498106
lazy_import diff.py

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
 
import errno
18
17
import os
19
18
import re
 
19
import sys
 
20
 
 
21
from bzrlib.lazy_import import lazy_import
 
22
lazy_import(globals(), """
 
23
import errno
20
24
import subprocess
21
 
import sys
22
25
import tempfile
23
26
import time
24
27
 
25
28
from bzrlib import (
26
29
    errors,
27
30
    osutils,
 
31
    patiencediff,
 
32
    textfile,
28
33
    )
 
34
""")
 
35
 
29
36
# compatability - plugins import compare_trees from diff!!!
30
37
# deprecated as of 0.10
31
38
from bzrlib.delta import compare_trees
32
 
from bzrlib.errors import BzrError
33
 
from bzrlib.patiencediff import unified_diff
34
 
import bzrlib.patiencediff
35
 
from bzrlib.symbol_versioning import (deprecated_function,
36
 
        zero_eight)
37
 
from bzrlib.textfile import check_text_lines
 
39
from bzrlib.symbol_versioning import (
 
40
        deprecated_function,
 
41
        zero_eight,
 
42
        )
38
43
from bzrlib.trace import mutter, warning
39
44
 
40
45
 
62
67
        return
63
68
    
64
69
    if allow_binary is False:
65
 
        check_text_lines(oldlines)
66
 
        check_text_lines(newlines)
 
70
        textfile.check_text_lines(oldlines)
 
71
        textfile.check_text_lines(newlines)
67
72
 
68
73
    if sequence_matcher is None:
69
 
        sequence_matcher = bzrlib.patiencediff.PatienceSequenceMatcher
70
 
    ud = unified_diff(oldlines, newlines,
 
74
        sequence_matcher = patiencediff.PatienceSequenceMatcher
 
75
    ud = patiencediff.unified_diff(oldlines, newlines,
71
76
                      fromfile=old_filename.encode(path_encoding),
72
77
                      tofile=new_filename.encode(path_encoding),
73
78
                      sequencematcher=sequence_matcher)
212
217
            # Write out the new i18n diff response
213
218
            to_file.write(out+'\n')
214
219
            if pipe.returncode != 2:
215
 
                raise BzrError('external diff failed with exit code 2'
 
220
                raise errors.BzrError(
 
221
                               'external diff failed with exit code 2'
216
222
                               ' when run with LANG=C, but not when run'
217
223
                               ' natively: %r' % (diffcmd,))
218
224
 
220
226
            # Starting with diffutils 2.8.4 the word "binary" was dropped.
221
227
            m = re.match('^(binary )?files.*differ$', first_line, re.I)
222
228
            if m is None:
223
 
                raise BzrError('external diff failed with exit code 2;'
224
 
                               ' command: %r' % (diffcmd,))
 
229
                raise errors.BzrError('external diff failed with exit code 2;'
 
230
                                      ' command: %r' % (diffcmd,))
225
231
            else:
226
232
                # Binary files differ, just return
227
233
                return
236
242
            else:
237
243
                msg = 'exit code %d' % rc
238
244
                
239
 
            raise BzrError('external diff failed with %s; command: %r' 
240
 
                           % (rc, diffcmd))
 
245
            raise errors.BzrError('external diff failed with %s; command: %r' 
 
246
                                  % (rc, diffcmd))
241
247
 
242
248
 
243
249
    finally: