~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-15 00:44:57 UTC
  • mfrom: (2009 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2050.
  • Revision ID: john@arbash-meinel.com-20060915004457-902cec0526a39337
[merge] bzr.dev 2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import tempfile
23
23
import time
24
24
 
 
25
from bzrlib import (
 
26
    errors,
 
27
    osutils,
 
28
    )
25
29
# compatability - plugins import compare_trees from diff!!!
26
30
# deprecated as of 0.10
27
31
from bzrlib.delta import compare_trees
28
32
from bzrlib.errors import BzrError
29
 
import bzrlib.errors as errors
30
 
import bzrlib.osutils
31
33
from bzrlib.patiencediff import unified_diff
32
34
import bzrlib.patiencediff
33
35
from bzrlib.symbol_versioning import (deprecated_function,
90
92
 
91
93
def _set_lang_C():
92
94
    """Set the env var LANG=C"""
93
 
    os.environ['LANG'] = 'C'
 
95
    osutils.set_or_unset_env('LANG', 'C')
 
96
    osutils.set_or_unset_env('LC_ALL', None)
 
97
    osutils.set_or_unset_env('LC_CTYPE', None)
 
98
    osutils.set_or_unset_env('LANGUAGE', None)
94
99
 
95
100
 
96
101
def _spawn_external_diff(diffcmd, capture_errors=True):
103
108
    :return: A Popen object.
104
109
    """
105
110
    if capture_errors:
106
 
        preexec_fn = _set_lang_C
 
111
        if sys.platform == 'win32':
 
112
            # Win32 doesn't support preexec_fn, but that is
 
113
            # okay, because it doesn't support LANG either.
 
114
            preexec_fn = None
 
115
        else:
 
116
            preexec_fn = _set_lang_C
107
117
        stderr = subprocess.PIPE
108
118
    else:
109
119
        preexec_fn = None
192
202
            # 'diff' gives retcode == 2 for all sorts of errors
193
203
            # one of those is 'Binary files differ'.
194
204
            # Bad options could also be the problem.
195
 
            # 'Binary files' is not a real error, so we suppress that error
 
205
            # 'Binary files' is not a real error, so we suppress that error.
196
206
            lang_c_out = out
197
207
 
198
208
            # Since we got here, we want to make sure to give an i18n error
207
217
                               ' natively: %r' % (diffcmd,))
208
218
 
209
219
            first_line = lang_c_out.split('\n', 1)[0]
210
 
            m = re.match('^binary files.*differ$', first_line, re.I)
 
220
            # Starting with diffutils 2.8.4 the word "binary" was dropped.
 
221
            m = re.match('^(binary )?files.*differ$', first_line, re.I)
211
222
            if m is None:
212
223
                raise BzrError('external diff failed with exit code 2;'
213
224
                               ' command: %r' % (diffcmd,))