~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

Lalo Martins remotebranch patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    ud = difflib.unified_diff(oldlines, newlines,
46
46
                              fromfile=old_label, tofile=new_label)
47
47
 
 
48
    ud = list(ud)
48
49
    # work-around for difflib being too smart for its own good
49
50
    # if /dev/null is "1,0", patch won't recognize it as /dev/null
50
51
    if not oldlines:
51
 
        ud = list(ud)
52
52
        ud[2] = ud[2].replace('-1,0', '-0,0')
53
53
    elif not newlines:
54
 
        ud = list(ud)
55
54
        ud[2] = ud[2].replace('+1,0', '+0,0')
 
55
    # work around for difflib emitting random spaces after the label
 
56
    ud[0] = ud[0][:-2] + '\n'
 
57
    ud[1] = ud[1][:-2] + '\n'
56
58
 
57
59
    for line in ud:
58
60
        to_file.write(line)
143
145
    
144
146
 
145
147
 
146
 
def show_diff(b, revision, specific_files, external_diff_options=None):
 
148
def show_diff(b, revision, specific_files, external_diff_options=None,
 
149
              revision2=None, output=None):
147
150
    """Shortcut for showing the diff to the working tree.
148
151
 
149
152
    b
155
158
    The more general form is show_diff_trees(), where the caller
156
159
    supplies any two trees.
157
160
    """
158
 
    import sys
 
161
    if output is None:
 
162
        import sys
 
163
        output = sys.stdout
159
164
 
160
165
    if revision == None:
161
166
        old_tree = b.basis_tree()
162
167
    else:
163
168
        old_tree = b.revision_tree(b.lookup_revision(revision))
164
 
        
165
 
    new_tree = b.working_tree()
166
 
 
167
 
    show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
 
169
 
 
170
    if revision2 == None:
 
171
        new_tree = b.working_tree()
 
172
    else:
 
173
        new_tree = b.revision_tree(b.lookup_revision(revision2))
 
174
 
 
175
    show_diff_trees(old_tree, new_tree, output, specific_files,
168
176
                    external_diff_options)
169
177
 
170
178
 
205
213
                          specific_files=specific_files)
206
214
 
207
215
    for path, file_id, kind in delta.removed:
208
 
        print >>to_file, '*** removed %s %r' % (kind, path)
 
216
        print >>to_file, '=== removed %s %r' % (kind, path)
209
217
        if kind == 'file':
210
218
            diff_file(old_label + path,
211
219
                      old_tree.get_file(file_id).readlines(),
214
222
                      to_file)
215
223
 
216
224
    for path, file_id, kind in delta.added:
217
 
        print >>to_file, '*** added %s %r' % (kind, path)
 
225
        print >>to_file, '=== added %s %r' % (kind, path)
218
226
        if kind == 'file':
219
227
            diff_file(DEVNULL,
220
228
                      [],
223
231
                      to_file)
224
232
 
225
233
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
226
 
        print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
 
234
        print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
227
235
        if text_modified:
228
236
            diff_file(old_label + old_path,
229
237
                      old_tree.get_file(file_id).readlines(),
232
240
                      to_file)
233
241
 
234
242
    for path, file_id, kind in delta.modified:
235
 
        print >>to_file, '*** modified %s %r' % (kind, path)
 
243
        print >>to_file, '=== modified %s %r' % (kind, path)
236
244
        if kind == 'file':
237
245
            diff_file(old_label + path,
238
246
                      old_tree.get_file(file_id).readlines(),