~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Aaron Bentley
  • Date: 2005-10-04 04:32:32 UTC
  • mfrom: (1185.12.6)
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051004043231-40302a149769263b
merged my own changes

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
 
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
233
 
        print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
 
226
    for (old_path, new_path, file_id, kind,
 
227
         text_modified, meta_modified) in delta.renamed:
 
228
        prop_str = get_prop_change(meta_modified)
 
229
        print >>to_file, '=== renamed %s %r => %r%s' % (
 
230
                          kind, old_path, new_path, prop_str)
 
231
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
232
                                    new_label, new_path, new_tree,
 
233
                                    text_modified, kind, to_file, diff_file)
 
234
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
 
235
        prop_str = get_prop_change(meta_modified)
 
236
        print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
234
237
        if text_modified:
 
238
            _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
 
239
                                        new_label, path, new_tree,
 
240
                                        True, kind, to_file, diff_file)
 
241
    
 
242
 
 
243
def get_prop_change(meta_modified):
 
244
    if meta_modified:
 
245
        return " (properties changed)"
 
246
    else:
 
247
        return  ""
 
248
 
 
249
 
 
250
def _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
251
                                new_label, new_path, new_tree, text_modified,
 
252
                                kind, to_file, diff_file):
 
253
    if text_modified:
 
254
        if kind == 'file':
235
255
            diff_file(old_label + old_path,
236
256
                      old_tree.get_file(file_id).readlines(),
237
257
                      new_label + new_path,
238
258
                      new_tree.get_file(file_id).readlines(),
239
259
                      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
 
 
 
260
        elif kind == 'symlink':
 
261
            _diff_symlink(old_tree, new_tree, file_id, to_file)
 
262
            
 
263
def _diff_symlink(old_tree, new_tree, file_id, to_file):
 
264
    t1 = old_tree.get_symlink_target(file_id)
 
265
    t2 = new_tree.get_symlink_target(file_id)
 
266
    print >>to_file, '=== target changed %r => %r' % (t1, t2)