/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2007-04-23 02:29:35 UTC
  • mfrom: (2441 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070423022935-9hhongamvk6bfdso
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    osutils,
31
31
    patiencediff,
32
32
    textfile,
 
33
    timestamp,
33
34
    )
34
35
""")
35
36
 
95
96
    print >>to_file
96
97
 
97
98
 
98
 
def _set_lang_C():
99
 
    """Set the env vars LANG=C and LC_ALL=C."""
100
 
    osutils.set_or_unset_env('LANG', 'C')
101
 
    osutils.set_or_unset_env('LC_ALL', 'C')
102
 
    osutils.set_or_unset_env('LC_CTYPE', None)
103
 
    osutils.set_or_unset_env('LANGUAGE', None)
104
 
 
105
 
 
106
99
def _spawn_external_diff(diffcmd, capture_errors=True):
107
100
    """Spawn the externall diff process, and return the child handle.
108
101
 
113
106
    :return: A Popen object.
114
107
    """
115
108
    if capture_errors:
116
 
        if sys.platform == 'win32':
117
 
            # Win32 doesn't support preexec_fn, but that is
118
 
            # okay, because it doesn't support LANG and LC_ALL either.
119
 
            preexec_fn = None
120
 
        else:
121
 
            preexec_fn = _set_lang_C
 
109
        # construct minimal environment
 
110
        env = {}
 
111
        path = os.environ.get('PATH')
 
112
        if path is not None:
 
113
            env['PATH'] = path
 
114
        env['LANGUAGE'] = 'C'   # on win32 only LANGUAGE has effect
 
115
        env['LANG'] = 'C'
 
116
        env['LC_ALL'] = 'C'
122
117
        stderr = subprocess.PIPE
123
118
    else:
124
 
        preexec_fn = None
 
119
        env = None
125
120
        stderr = None
126
121
 
127
122
    try:
129
124
                                stdin=subprocess.PIPE,
130
125
                                stdout=subprocess.PIPE,
131
126
                                stderr=stderr,
132
 
                                preexec_fn=preexec_fn)
 
127
                                env=env)
133
128
    except OSError, e:
134
129
        if e.errno == errno.ENOENT:
135
130
            raise errors.NoDiff(str(e))
476
471
        has_changes = 1
477
472
        prop_str = get_prop_change(meta_modified)
478
473
        print >>to_file, '=== modified %s %r%s' % (kind, path.encode('utf8'), prop_str)
479
 
        old_name = '%s%s\t%s' % (old_label, path,
480
 
                                 _patch_header_date(old_tree, file_id, path))
 
474
        # The file may be in a different location in the old tree (because
 
475
        # the containing dir was renamed, but the file itself was not)
 
476
        old_path = old_tree.id2path(file_id)
 
477
        old_name = '%s%s\t%s' % (old_label, old_path,
 
478
                                 _patch_header_date(old_tree, file_id, old_path))
481
479
        new_name = '%s%s\t%s' % (new_label, path,
482
480
                                 _patch_header_date(new_tree, file_id, path))
483
481
        if text_modified:
490
488
 
491
489
def _patch_header_date(tree, file_id, path):
492
490
    """Returns a timestamp suitable for use in a patch header."""
493
 
    tm = time.gmtime(tree.get_file_mtime(file_id, path))
494
 
    return time.strftime('%Y-%m-%d %H:%M:%S +0000', tm)
 
491
    mtime = tree.get_file_mtime(file_id, path)
 
492
    assert mtime is not None, \
 
493
        "got an mtime of None for file-id %s, path %s in tree %s" % (
 
494
                file_id, path, tree)
 
495
    return timestamp.format_patch_date(mtime)
495
496
 
496
497
 
497
498
def _raise_if_nonexistent(paths, old_tree, new_tree):