~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2005-10-03 01:15:02 UTC
  • mfrom: (1092.2.28)
  • Revision ID: robertc@robertcollins.net-20051003011502-f579a509a136b774
mergeĀ fromĀ baz2bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    print >>to_file
63
63
 
64
64
 
65
 
 
66
 
 
67
65
def external_diff(old_label, oldlines, new_label, newlines, to_file,
68
66
                  diff_opts):
69
67
    """Display a diff by calling out to the external diff program."""
141
139
    finally:
142
140
        oldtmpf.close()                 # and delete
143
141
        newtmpf.close()
144
 
    
145
 
 
146
142
 
147
143
def show_diff(b, revision, specific_files, external_diff_options=None,
148
144
              revision2=None, output=None):
219
215
                      DEVNULL, 
220
216
                      [],
221
217
                      to_file)
222
 
 
223
218
    for path, file_id, kind in delta.added:
224
219
        print >>to_file, '=== added %s %r' % (kind, path)
225
220
        if kind == 'file':
228
223
                      new_label + path,
229
224
                      new_tree.get_file(file_id).readlines(),
230
225
                      to_file)
231
 
 
232
226
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
233
227
        print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
234
 
        if text_modified:
 
228
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
229
                                    new_label, new_path, new_tree,
 
230
                                    text_modified, kind, to_file, diff_file)
 
231
    for path, file_id, kind in delta.modified:
 
232
        print >>to_file, '=== modified %s %r' % (kind, path)
 
233
        _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
 
234
                                    new_label, path, new_tree,
 
235
                                    True, kind, to_file, diff_file)
 
236
    
 
237
 
 
238
def _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
239
                                new_label, new_path, new_tree, text_modified,
 
240
                                kind, to_file, diff_file):
 
241
    if text_modified:
 
242
        if kind == 'file':
235
243
            diff_file(old_label + old_path,
236
244
                      old_tree.get_file(file_id).readlines(),
237
245
                      new_label + new_path,
238
246
                      new_tree.get_file(file_id).readlines(),
239
247
                      to_file)
240
 
 
241
 
    for path, file_id, kind in delta.modified:
242
 
        print >>to_file, '=== modified %s %r' % (kind, path)
243
 
        if kind == 'file':
244
 
            diff_file(old_label + path,
245
 
                      old_tree.get_file(file_id).readlines(),
246
 
                      new_label + path,
247
 
                      new_tree.get_file(file_id).readlines(),
248
 
                      to_file)
249
 
 
250
 
 
251
 
 
252
 
 
253
 
 
 
248
        elif kind == 'symlink':
 
249
            _diff_symlink(old_tree, new_tree, file_id, to_file)
 
250
            
 
251
def _diff_symlink(old_tree, new_tree, file_id, to_file):
 
252
    t1 = old_tree.get_symlink_target(file_id)
 
253
    t2 = new_tree.get_symlink_target(file_id)
 
254
    print >>to_file, '=== target changed %r => %r' % (t1, t2)