~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

  • Committer: Aaron Bentley
  • Date: 2005-07-28 18:46:35 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1020.
  • Revision ID: abentley@panoramicfeedback.com-20050728184635-2461268fd9d1e8d1
Added default backups for merge-revert

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import changeset
2
2
from changeset import Inventory, apply_changeset, invert_dict
3
3
import os.path
 
4
from osutils import backup_file
4
5
from merge3 import Merge3
5
6
 
6
7
class ApplyMerge3:
49
50
        else:
50
51
            conflict_handler.merge_conflict(new_file, filename, base, other)
51
52
 
 
53
 
 
54
class BackupBeforeChange:
 
55
    """Contents-change wrapper to back up file first"""
 
56
    def __init__(self, contents_change):
 
57
        self.contents_change = contents_change
 
58
 
 
59
    def __eq__(self, other):
 
60
        if not isinstance(other, BackupBeforeChange):
 
61
            return False
 
62
        return (self.contents_change == other.contents_change)
 
63
 
 
64
    def __ne__(self, other):
 
65
        return not (self == other)
 
66
 
 
67
    def apply(self, filename, conflict_handler, reverse=False):
 
68
        backup_file(filename)
 
69
        self.contents_change.apply(filename, conflict_handler, reverse)
 
70
 
 
71
 
52
72
class ThreewayInventory(object):
53
73
    def __init__(self, this_inventory, base_inventory, other_inventory):
54
74
        self.this = this_inventory
548
568
        """Test diff3 merging"""
549
569
        self.do_contents_test(changeset.Diff3Merge)
550
570
 
 
571
    def test_contents_merge3(self):
 
572
        """Test diff3 merging"""
 
573
        def backup_merge(base_file, other_file):
 
574
            return BackupBeforeChange(ApplyMerge3(base_file, other_file))
 
575
        builder = self.contents_test_success(backup_merge)
 
576
        def backup_exists(file_id):
 
577
            return os.path.exists(builder.this.full_path(file_id)+"~")
 
578
        assert backup_exists("1")
 
579
        assert backup_exists("2")
 
580
        assert not backup_exists("3")
 
581
        builder.cleanup()
 
582
 
551
583
    def do_contents_test(self, merge_factory):
552
584
        """Test merging with specified ContentsChange factory"""
 
585
        builder = self.contents_test_success(merge_factory)
 
586
        builder.cleanup()
 
587
        self.contents_test_conflicts(merge_factory)
 
588
 
 
589
    def contents_test_success(self, merge_factory):
553
590
        from inspect import isclass
554
591
        builder = MergeBuilder()
555
592
        builder.add_file("1", "0", "name1", "text1", 0755)
572
609
        assert(os.stat(builder.this.full_path("1")).st_mode &0777 == 0755)
573
610
        assert(os.stat(builder.this.full_path("2")).st_mode &0777 == 0655)
574
611
        assert(os.stat(builder.this.full_path("3")).st_mode &0777 == 0744)
575
 
        builder.cleanup()
 
612
        return builder
576
613
 
 
614
    def contents_test_conflicts(self, merge_factory):
577
615
        builder = MergeBuilder()
578
616
        builder.add_file("1", "0", "name1", "text1", 0755)
579
617
        builder.change_contents("1", other="text4", this="text3")