~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge_core.py

  • Committer: Aaron Bentley
  • Date: 2005-08-11 16:20:13 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: abentley@panoramicfeedback.com-20050811162013-c53441a23f455256
Refactored code

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
 
119
119
    return new_cset
120
120
 
 
121
class ThreeWayConflict(Exception):
 
122
    def __init__(self, this, base, other):
 
123
        self.this = this
 
124
        self.base = base
 
125
        self.other = other
 
126
        msg = "Conflict merging %s %s and %s" % (this, base, other)
 
127
        Exception.__init__(self, msg)
 
128
 
 
129
def threeway_select(this, base, other):
 
130
    """Returns a value selected by the three-way algorithm.
 
131
    Raises ThreewayConflict if the algorithm yields a conflict"""
 
132
    if base == other:
 
133
        return this
 
134
    elif base == this:
 
135
        return other
 
136
    elif other == this:
 
137
        return this
 
138
    else:
 
139
        raise ThreeWayConflict(this, base, other)
 
140
 
 
141
 
121
142
def make_merged_entry(entry, this, base, other, conflict_handler):
122
143
    from bzrlib.trace import mutter
123
144
    def entry_data(file_id, tree):
134
155
    other_name, other_parent, other_dir = entry_data(entry.id, other)
135
156
    mutter("Dirs: this, base, other %r %r %r" % (this_dir, base_dir, other_dir))
136
157
    mutter("Names: this, base, other %r %r %r" % (this_name, base_name, other_name))
137
 
    if base_name == other_name:
138
 
        old_name = this_name
139
 
        new_name = this_name
140
 
    else:
141
 
        if this_name != base_name and this_name != other_name:
142
 
            conflict_handler.rename_conflict(entry.id, this_name, base_name,
143
 
                                             other_name)
144
 
        else:
145
 
            old_name = this_name
146
 
            new_name = other_name
147
 
 
148
 
    if base_parent == other_parent:
149
 
        old_parent = this_parent
150
 
        new_parent = this_parent
151
 
        old_dir = this_dir
152
 
        new_dir = this_dir
153
 
    else:
154
 
        if this_parent != base_parent and this_parent != other_parent:
155
 
            conflict_handler.move_conflict(entry.id, this_dir, base_dir, 
156
 
                                           other_dir)
157
 
        else:
158
 
            old_parent = this_parent
159
 
            old_dir = this_dir
160
 
            new_parent = other_parent
161
 
            new_dir = other_dir
162
 
    if old_name is not None and old_parent is not None:
163
 
        old_path = os.path.join(old_dir, old_name)
164
 
    else:
165
 
        old_path = None
 
158
    old_name = this_name
 
159
    try:
 
160
        new_name = threeway_select(this_name, base_name, other_name)
 
161
    except ThreeWayConflict:
 
162
        new_name = conflict_handler.rename_conflict(entry.id, this_name, 
 
163
                                                    base_name, other_name)
 
164
 
 
165
    old_parent = this_parent
 
166
    try:
 
167
        new_parent = threeway_select(this_parent, base_parent, other_parent)
 
168
    except ThreeWayConflict:
 
169
        new_parent = conflict_handler.move_conflict(entry.id, this_dir,
 
170
                                                    base_dir, other_dir)
 
171
    def get_path(name, parent):
 
172
        if name is not None and parent is not None:
 
173
            parent_dir = {this_parent: this_dir, other_parent: other_dir, 
 
174
                          base_parent: base_dir}
 
175
            directory = parent_dir[parent]
 
176
            return os.path.join(directory, name)
 
177
        else:
 
178
            assert name is None and parent is None
 
179
            return None
 
180
 
 
181
    old_path = get_path(old_name, old_parent)
 
182
        
166
183
    new_entry = changeset.ChangesetEntry(entry.id, old_parent, old_path)
167
 
    if new_name is not None and new_parent is not None:
168
 
        new_entry.new_path = os.path.join(new_dir, new_name)
169
 
    else:
170
 
        new_entry.new_path = None
 
184
    new_entry.new_path = get_path(new_name, new_parent)
171
185
    new_entry.new_parent = new_parent
172
186
    mutter(repr(new_entry))
173
187
    return new_entry