~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Aaron Bentley
  • Date: 2007-11-21 14:08:53 UTC
  • mto: (3008.1.2 transform_preview)
  • mto: This revision was merged to the branch mainline in revision 3036.
  • Revision ID: abentley@panoramicfeedback.com-20071121140853-yc9zlb4ct58x2j5b
Make old_tree/new_tree construction parameters of Differ

Show diffs side-by-side

added added

removed removed

Lines of Context:
409
409
        extra_trees=extra_trees, require_versioned=True)
410
410
 
411
411
    has_changes = 0
412
 
    differ = Differ(to_file, diff_file)
 
412
    differ = Differ(old_tree, new_tree, to_file, diff_file)
413
413
    for path, file_id, kind in delta.removed:
414
414
        has_changes = 1
415
415
        path_encoded = path.encode(path_encoding, "replace")
417
417
        old_name = '%s%s\t%s' % (old_label, path,
418
418
                                 _patch_header_date(old_tree, file_id, path))
419
419
        new_name = '%s%s\t%s' % (new_label, path, EPOCH_DATE)
420
 
        differ.diff(file_id, old_tree, new_tree, old_name, new_name)
 
420
        differ.diff(file_id, old_name, new_name)
421
421
    for path, file_id, kind in delta.added:
422
422
        has_changes = 1
423
423
        path_encoded = path.encode(path_encoding, "replace")
425
425
        old_name = '%s%s\t%s' % (old_label, path, EPOCH_DATE)
426
426
        new_name = '%s%s\t%s' % (new_label, path,
427
427
                                 _patch_header_date(new_tree, file_id, path))
428
 
        differ.diff(file_id, old_tree, new_tree, old_name, new_name)
 
428
        differ.diff(file_id, old_name, new_name)
429
429
    for (old_path, new_path, file_id, kind,
430
430
         text_modified, meta_modified) in delta.renamed:
431
431
        has_changes = 1
501
501
def _maybe_diff_file_or_symlink(old_path, old_tree, file_id,
502
502
                                new_path, new_tree, text_modified, differ):
503
503
    if text_modified:
504
 
        differ.diff(file_id, old_tree, new_tree, old_path, new_path)
 
504
        differ.diff(file_id, old_path, new_path)
505
505
 
506
506
 
507
507
class Differ(object):
508
508
 
509
 
    def __init__(self, to_file, text_diff):
 
509
    def __init__(self, old_tree, new_tree, to_file, text_diff):
 
510
        self.old_tree = old_tree
 
511
        self.new_tree = new_tree
510
512
        self.to_file = to_file
511
513
        self.text_diff = text_diff
512
514
 
513
 
    def diff(self, file_id, old_tree, new_tree, old_name, new_name):
 
515
    def diff(self, file_id, old_name, new_name):
514
516
        try:
515
 
            old_entry = old_tree.inventory[file_id]
 
517
            old_entry = self.old_tree.inventory[file_id]
516
518
        except errors.NoSuchId:
517
519
            old_entry = None
518
520
        try:
519
 
            new_entry = new_tree.inventory[file_id]
 
521
            new_entry = self.new_tree.inventory[file_id]
520
522
        except errors.NoSuchId:
521
523
            new_entry = None
522
524
        if old_entry is None:
523
 
            new_entry.diff(self.text_diff, new_name, new_tree, old_name,
524
 
                           old_entry, old_tree, self.to_file, reverse=True)
 
525
            new_entry.diff(self.text_diff, new_name, self.new_tree, old_name,
 
526
                           old_entry, self.old_tree, self.to_file,
 
527
                           reverse=True)
525
528
        else:
526
 
            old_entry.diff(self.text_diff, old_name, old_tree, new_name,
527
 
                           new_entry, new_tree, self.to_file)
 
529
            old_entry.diff(self.text_diff, old_name, self.old_tree, new_name,
 
530
                           new_entry, self.new_tree, self.to_file)