~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

[merge] aaron, various fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# invoke callbacks on an object.  That object can either accumulate a
23
23
# list, write them out directly, etc etc.
24
24
 
25
 
def internal_diff(old_label, oldlines, new_label, newlines, to_file):
 
25
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file):
26
26
    import difflib
27
27
    
28
28
    # FIXME: difflib is wrong if there is no trailing newline.
42
42
        return
43
43
 
44
44
    ud = difflib.unified_diff(oldlines, newlines,
45
 
                              fromfile=old_label, tofile=new_label)
 
45
                              fromfile=old_filename+'\t', 
 
46
                              tofile=new_filename+'\t')
46
47
 
47
48
    ud = list(ud)
48
49
    # work-around for difflib being too smart for its own good
62
63
    print >>to_file
63
64
 
64
65
 
65
 
def external_diff(old_label, oldlines, new_label, newlines, to_file,
 
66
def external_diff(old_filename, oldlines, new_filename, newlines, to_file,
66
67
                  diff_opts):
67
68
    """Display a diff by calling out to the external diff program."""
68
69
    import sys
97
98
        if not diff_opts:
98
99
            diff_opts = []
99
100
        diffcmd = ['diff',
100
 
                   '--label', old_label,
 
101
                   '--label', old_filename+'\t',
101
102
                   oldtmpf.name,
102
 
                   '--label', new_label,
 
103
                   '--label', new_filename+'\t',
103
104
                   newtmpf.name]
104
105
 
105
106
        # diff only allows one style to be specified; they don't override.
141
142
        newtmpf.close()
142
143
 
143
144
def show_diff(b, from_spec, specific_files, external_diff_options=None,
144
 
              revision2=None, output=None):
 
145
              revision2=None, output=None, b2=None):
145
146
    """Shortcut for showing the diff to the working tree.
146
147
 
147
148
    b
158
159
        output = sys.stdout
159
160
 
160
161
    if from_spec is None:
161
 
        old_tree = b.basis_tree()
 
162
        if b2 is None:
 
163
            old_tree = b.basis_tree()
 
164
        else:
 
165
            old_tree = b.working_tree()
162
166
    else:
163
167
        old_tree = b.revision_tree(from_spec.in_history(b).rev_id)
164
168
 
165
169
    if revision2 is None:
166
 
        new_tree = b.working_tree()
 
170
        if b2 is None:
 
171
            new_tree = b.working_tree()
 
172
        else:
 
173
            new_tree = b2.working_tree()
167
174
    else:
168
175
        new_tree = b.revision_tree(revision2.in_history(b).rev_id)
169
176