~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

  • Committer: Aaron Bentley
  • Date: 2005-10-23 00:26:17 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1488.
  • Revision ID: aaron.bentley@utoronto.ca-20051023002617-d57101d2671509f7
Preliminary weave merge support

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from bzrlib.osutils import backup_file, rename
6
6
from bzrlib.merge3 import Merge3
7
7
import bzrlib
 
8
from bzrlib.atomicfile import AtomicFile
8
9
from changeset import get_contents
9
10
 
10
11
class ApplyMerge3:
 
12
    history_based = False
11
13
    """Contents-change wrapper around merge3.Merge3"""
12
14
    def __init__(self, file_id, base, other, show_base=False):
13
15
        self.file_id = file_id
71
73
            conflict_handler.merge_conflict(new_file, filename, base_lines,
72
74
                                            other_lines)
73
75
 
 
76
class WeaveMerge:
 
77
    """Contents-change wrapper around weave merge"""
 
78
    history_based = True
 
79
    def __init__(self, weave, this_revision_id, other_revision_id):
 
80
        self.weave = weave
 
81
        self.this_revision_id = this_revision_id
 
82
        self.other_revision_id = other_revision_id
 
83
 
 
84
    def is_creation(self):
 
85
        return False
 
86
 
 
87
    def is_deletion(self):
 
88
        return False
 
89
 
 
90
    def __eq__(self, other):
 
91
        if not isinstance(other, WeaveMerge):
 
92
            return False
 
93
        return self.weave == other.weave and\
 
94
            self.this_revision_id == other.this_revision_id and\
 
95
            self.other_revision_id == other.other_revision_id
 
96
 
 
97
    def __ne__(self, other):
 
98
        return not (self == other)
 
99
 
 
100
    def apply(self, filename, conflict_handler, reverse=False):
 
101
        this_i = self.weave.lookup(self.this_revision_id)
 
102
        other_i = self.weave.lookup(self.other_revision_id)
 
103
        plan = self.weave.plan_merge(this_i, other_i)
 
104
        lines = self.weave.weave_merge(plan)
 
105
        conflicts = False
 
106
        out_file = AtomicFile(filename, mode='wb')
 
107
        for line in lines:
 
108
            if line == '<<<<\n':
 
109
                conflicts = True
 
110
            out_file.write(line)
 
111
        out_file.commit()
74
112
 
75
113
class BackupBeforeChange:
76
114
    """Contents-change wrapper to back up file first"""