~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Martin Pool
  • Date: 2006-03-21 12:26:54 UTC
  • mto: This revision was merged to the branch mainline in revision 1621.
  • Revision ID: mbp@sourcefrog.net-20060321122654-514047ed65795a17
New developer commands 'weave-list' and 'weave-join'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
import os
19
19
import errno
20
 
import warnings
 
20
from shutil import rmtree
 
21
from tempfile import mkdtemp
21
22
 
22
 
from bzrlib import (
23
 
    errors,
24
 
    osutils,
25
 
    registry,
26
 
    revision as _mod_revision,
27
 
    )
 
23
import bzrlib
28
24
from bzrlib.branch import Branch
29
 
from bzrlib.conflicts import ConflictList, Conflict
 
25
from bzrlib.delta import compare_trees
30
26
from bzrlib.errors import (BzrCommandError,
31
27
                           BzrError,
32
28
                           NoCommonAncestor,
36
32
                           NotBranchError,
37
33
                           NotVersionedError,
38
34
                           UnrelatedBranches,
39
 
                           UnsupportedOperation,
40
35
                           WorkingTreeNotRevision,
41
 
                           BinaryFile,
42
36
                           )
43
37
from bzrlib.merge3 import Merge3
 
38
import bzrlib.osutils
44
39
from bzrlib.osutils import rename, pathjoin
45
40
from progress import DummyProgress, ProgressPhase
46
 
from bzrlib.revision import (is_ancestor, NULL_REVISION, ensure_null)
47
 
from bzrlib.textfile import check_text_lines
 
41
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
 
42
from bzrlib.symbol_versioning import *
48
43
from bzrlib.trace import mutter, warning, note
49
44
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
50
 
                              conflict_pass, FinalPaths, create_by_entry,
51
 
                              unique_add, ROOT_PARENT)
52
 
from bzrlib.versionedfile import WeaveMerge
53
 
from bzrlib import ui
 
45
                              conflicts_strings, FinalPaths, create_by_entry,
 
46
                              unique_add)
 
47
import bzrlib.ui
54
48
 
55
49
# TODO: Report back as changes are merged in
56
50
 
 
51
def _get_tree(treespec, local_branch=None):
 
52
    location, revno = treespec
 
53
    branch = Branch.open_containing(location)[0]
 
54
    if revno is None:
 
55
        revision = None
 
56
    elif revno == -1:
 
57
        revision = branch.last_revision()
 
58
    else:
 
59
        revision = branch.get_rev_id(revno)
 
60
        if revision is None:
 
61
            revision = NULL_REVISION
 
62
    return branch, _get_revid_tree(branch, revision, local_branch)
 
63
 
 
64
 
 
65
def _get_revid_tree(branch, revision, local_branch):
 
66
    if revision is None:
 
67
        base_tree = branch.bzrdir.open_workingtree()
 
68
    else:
 
69
        if local_branch is not None:
 
70
            if local_branch.base != branch.base:
 
71
                local_branch.fetch(branch, revision)
 
72
            base_tree = local_branch.repository.revision_tree(revision)
 
73
        else:
 
74
            base_tree = branch.repository.revision_tree(revision)
 
75
    return base_tree
 
76
 
57
77
 
58
78
def transform_tree(from_tree, to_tree, interesting_ids=None):
59
79
    merge_inner(from_tree.branch, to_tree, from_tree, ignore_zero=True,
61
81
 
62
82
 
63
83
class Merger(object):
64
 
    def __init__(self, this_branch, other_tree=None, base_tree=None,
65
 
                 this_tree=None, pb=DummyProgress(), change_reporter=None,
66
 
                 recurse='down'):
 
84
    def __init__(self, this_branch, other_tree=None, base_tree=None, 
 
85
                 this_tree=None, pb=DummyProgress()):
67
86
        object.__init__(self)
68
87
        assert this_tree is not None, "this_tree is required"
69
88
        self.this_branch = this_branch
70
 
        self.this_basis = _mod_revision.ensure_null(
71
 
            this_branch.last_revision())
 
89
        self.this_basis = this_branch.last_revision()
72
90
        self.this_rev_id = None
73
91
        self.this_tree = this_tree
74
92
        self.this_revision_tree = None
75
93
        self.this_basis_tree = None
76
94
        self.other_tree = other_tree
77
 
        self.other_branch = None
78
95
        self.base_tree = base_tree
79
96
        self.ignore_zero = False
80
97
        self.backup_files = False
81
98
        self.interesting_ids = None
82
 
        self.interesting_files = None
83
99
        self.show_base = False
84
100
        self.reprocess = False
85
 
        self._pb = pb
 
101
        self._pb = pb 
86
102
        self.pp = None
87
 
        self.recurse = recurse
88
 
        self.change_reporter = change_reporter
89
 
        self._cached_trees = {}
90
 
 
91
 
    def revision_tree(self, revision_id, branch=None):
92
 
        if revision_id not in self._cached_trees:
93
 
            if branch is None:
94
 
                branch = self.this_branch
95
 
            try:
96
 
                tree = self.this_tree.revision_tree(revision_id)
97
 
            except errors.NoSuchRevisionInTree:
98
 
                tree = branch.repository.revision_tree(revision_id)
99
 
            self._cached_trees[revision_id] = tree
100
 
        return self._cached_trees[revision_id]
101
 
 
102
 
    def _get_tree(self, treespec, possible_transports=None):
103
 
        from bzrlib import workingtree
104
 
        location, revno = treespec
105
 
        if revno is None:
106
 
            tree = workingtree.WorkingTree.open_containing(location)[0]
107
 
            return tree.branch, tree
108
 
        branch = Branch.open_containing(location, possible_transports)[0]
109
 
        if revno == -1:
110
 
            revision_id = branch.last_revision()
111
 
        else:
112
 
            revision_id = branch.get_rev_id(revno)
113
 
        revision_id = ensure_null(revision_id)
114
 
        return branch, self.revision_tree(revision_id, branch)
 
103
 
 
104
 
 
105
    def revision_tree(self, revision_id):
 
106
        return self.this_branch.repository.revision_tree(revision_id)
115
107
 
116
108
    def ensure_revision_trees(self):
117
109
        if self.this_revision_tree is None:
118
 
            self.this_basis_tree = self.revision_tree(self.this_basis)
 
110
            self.this_basis_tree = self.this_branch.repository.revision_tree(
 
111
                self.this_basis)
119
112
            if self.this_basis == self.this_rev_id:
120
113
                self.this_revision_tree = self.this_basis_tree
121
114
 
122
115
        if self.other_rev_id is None:
123
116
            other_basis_tree = self.revision_tree(self.other_basis)
124
 
            changes = other_basis_tree.changes_from(self.other_tree)
 
117
            changes = compare_trees(self.other_tree, other_basis_tree)
125
118
            if changes.has_changed():
126
119
                raise WorkingTreeNotRevision(self.this_tree)
127
 
            other_rev_id = self.other_basis
 
120
            other_rev_id = other_basis
128
121
            self.other_tree = other_basis_tree
129
122
 
130
123
    def file_revisions(self, file_id):
141
134
        trees = (self.this_basis_tree, self.other_tree)
142
135
        return [get_id(tree, file_id) for tree in trees]
143
136
 
144
 
    def check_basis(self, check_clean, require_commits=True):
145
 
        if self.this_basis is None and require_commits is True:
146
 
            raise BzrCommandError("This branch has no commits."
147
 
                                  " (perhaps you would prefer 'bzr pull')")
 
137
    def check_basis(self, check_clean):
 
138
        if self.this_basis is None:
 
139
            raise BzrCommandError("This branch has no commits")
148
140
        if check_clean:
149
141
            self.compare_basis()
150
142
            if self.this_basis != self.this_rev_id:
151
143
                raise BzrCommandError("Working tree has uncommitted changes.")
152
144
 
153
145
    def compare_basis(self):
154
 
        try:
155
 
            basis_tree = self.revision_tree(self.this_tree.last_revision())
156
 
        except errors.RevisionNotPresent:
157
 
            basis_tree = self.this_tree.basis_tree()
158
 
        changes = self.this_tree.changes_from(basis_tree)
 
146
        changes = compare_trees(self.this_tree, 
 
147
                                self.this_tree.basis_tree(), False)
159
148
        if not changes.has_changed():
160
149
            self.this_rev_id = self.this_basis
161
150
 
162
151
    def set_interesting_files(self, file_list):
163
 
        self.interesting_files = file_list
 
152
        try:
 
153
            self._set_interesting_files(file_list)
 
154
        except NotVersionedError, e:
 
155
            raise BzrCommandError("%s is not a source file in any"
 
156
                                      " tree." % e.path)
 
157
 
 
158
    def _set_interesting_files(self, file_list):
 
159
        """Set the list of interesting ids from a list of files."""
 
160
        if file_list is None:
 
161
            self.interesting_ids = None
 
162
            return
 
163
 
 
164
        interesting_ids = set()
 
165
        for path in file_list:
 
166
            found_id = False
 
167
            for tree in (self.this_tree, self.base_tree, self.other_tree):
 
168
                file_id = tree.inventory.path2id(path)
 
169
                if file_id is not None:
 
170
                    interesting_ids.add(file_id)
 
171
                    found_id = True
 
172
            if not found_id:
 
173
                raise NotVersionedError(path=path)
 
174
        self.interesting_ids = interesting_ids
164
175
 
165
176
    def set_pending(self):
166
 
        if not self.base_is_ancestor or not self.base_is_other_ancestor:
167
 
            return
168
 
        self._add_parent()
169
 
 
170
 
    def _add_parent(self):
171
 
        new_parents = self.this_tree.get_parent_ids() + [self.other_rev_id]
172
 
        new_parent_trees = []
173
 
        for revision_id in new_parents:
174
 
            try:
175
 
                tree = self.revision_tree(revision_id)
176
 
            except errors.RevisionNotPresent:
177
 
                tree = None
178
 
            else:
179
 
                tree.lock_read()
180
 
            new_parent_trees.append((revision_id, tree))
181
 
        try:
182
 
            self.this_tree.set_parent_trees(new_parent_trees,
183
 
                                            allow_leftmost_as_ghost=True)
184
 
        finally:
185
 
            for _revision_id, tree in new_parent_trees:
186
 
                if tree is not None:
187
 
                    tree.unlock()
188
 
 
189
 
    def set_other(self, other_revision, possible_transports=None):
190
 
        """Set the revision and tree to merge from.
191
 
 
192
 
        This sets the other_tree, other_rev_id, other_basis attributes.
193
 
 
194
 
        :param other_revision: The [path, revision] list to merge from.
195
 
        """
196
 
        self.other_branch, self.other_tree = self._get_tree(other_revision,
197
 
                                                            possible_transports)
 
177
        if not self.base_is_ancestor:
 
178
            return
 
179
        if self.other_rev_id is None:
 
180
            return
 
181
        ancestry = self.this_branch.repository.get_ancestry(self.this_basis)
 
182
        if self.other_rev_id in ancestry:
 
183
            return
 
184
        self.this_tree.add_pending_merge(self.other_rev_id)
 
185
 
 
186
    def set_other(self, other_revision):
 
187
        other_branch, self.other_tree = _get_tree(other_revision, 
 
188
                                                  self.this_branch)
198
189
        if other_revision[1] == -1:
199
 
            self.other_rev_id = _mod_revision.ensure_null(
200
 
                self.other_branch.last_revision())
201
 
            if _mod_revision.is_null(self.other_rev_id):
202
 
                raise NoCommits(self.other_branch)
 
190
            self.other_rev_id = other_branch.last_revision()
 
191
            if self.other_rev_id is None:
 
192
                raise NoCommits(other_branch)
203
193
            self.other_basis = self.other_rev_id
204
194
        elif other_revision[1] is not None:
205
 
            self.other_rev_id = self.other_branch.get_rev_id(other_revision[1])
 
195
            self.other_rev_id = other_branch.get_rev_id(other_revision[1])
206
196
            self.other_basis = self.other_rev_id
207
197
        else:
208
198
            self.other_rev_id = None
209
 
            self.other_basis = self.other_branch.last_revision()
 
199
            self.other_basis = other_branch.last_revision()
210
200
            if self.other_basis is None:
211
 
                raise NoCommits(self.other_branch)
212
 
        if self.other_rev_id is not None:
213
 
            self._cached_trees[self.other_rev_id] = self.other_tree
214
 
        self._maybe_fetch(self.other_branch,self.this_branch, self.other_basis)
215
 
 
216
 
    def set_other_revision(self, revision_id, other_branch):
217
 
        """Set 'other' based on a branch and revision id
218
 
 
219
 
        :param revision_id: The revision to use for a tree
220
 
        :param other_branch: The branch containing this tree
221
 
        """
222
 
        self.other_rev_id = revision_id
223
 
        self.other_branch = other_branch
224
 
        self._maybe_fetch(other_branch, self.this_branch, self.other_rev_id)
225
 
        self.other_tree = self.revision_tree(revision_id)
226
 
        self.other_basis = revision_id
227
 
 
228
 
    def _maybe_fetch(self, source, target, revision_id):
229
 
        if (source.repository.bzrdir.root_transport.base !=
230
 
            target.repository.bzrdir.root_transport.base):
231
 
            target.fetch(source, revision_id)
232
 
 
233
 
    def find_base(self):
234
 
        this_repo = self.this_branch.repository
235
 
        graph = this_repo.get_graph()
236
 
        revisions = [ensure_null(self.this_basis),
237
 
                     ensure_null(self.other_basis)]
238
 
        if NULL_REVISION in revisions:
239
 
            self.base_rev_id = NULL_REVISION
240
 
        else:
241
 
            self.base_rev_id = graph.find_unique_lca(*revisions)
242
 
            if self.base_rev_id == NULL_REVISION:
243
 
                raise UnrelatedBranches()
244
 
        self.base_tree = self.revision_tree(self.base_rev_id)
245
 
        self.base_is_ancestor = True
246
 
        self.base_is_other_ancestor = True
 
201
                raise NoCommits(other_branch)
 
202
        if other_branch.base != self.this_branch.base:
 
203
            self.this_branch.fetch(other_branch, last_revision=self.other_basis)
247
204
 
248
205
    def set_base(self, base_revision):
249
 
        """Set the base revision to use for the merge.
250
 
 
251
 
        :param base_revision: A 2-list containing a path and revision number.
252
 
        """
253
206
        mutter("doing merge() with no base_revision specified")
254
207
        if base_revision == [None, None]:
255
 
            self.find_base()
 
208
            try:
 
209
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
210
                try:
 
211
                    this_repo = self.this_branch.repository
 
212
                    self.base_rev_id = common_ancestor(self.this_basis, 
 
213
                                                       self.other_basis, 
 
214
                                                       this_repo, pb)
 
215
                finally:
 
216
                    pb.finished()
 
217
            except NoCommonAncestor:
 
218
                raise UnrelatedBranches()
 
219
            self.base_tree = _get_revid_tree(self.this_branch, self.base_rev_id,
 
220
                                            None)
 
221
            self.base_is_ancestor = True
256
222
        else:
257
 
            base_branch, self.base_tree = self._get_tree(base_revision)
 
223
            base_branch, self.base_tree = _get_tree(base_revision)
258
224
            if base_revision[1] == -1:
259
225
                self.base_rev_id = base_branch.last_revision()
260
226
            elif base_revision[1] is None:
261
 
                self.base_rev_id = _mod_revision.NULL_REVISION
 
227
                self.base_rev_id = None
262
228
            else:
263
 
                self.base_rev_id = _mod_revision.ensure_null(
264
 
                    base_branch.get_rev_id(base_revision[1]))
265
 
            self._maybe_fetch(base_branch, self.this_branch, self.base_rev_id)
 
229
                self.base_rev_id = base_branch.get_rev_id(base_revision[1])
 
230
            if self.this_branch.base != base_branch.base:
 
231
                self.this_branch.fetch(base_branch)
266
232
            self.base_is_ancestor = is_ancestor(self.this_basis, 
267
233
                                                self.base_rev_id,
268
234
                                                self.this_branch)
269
 
            self.base_is_other_ancestor = is_ancestor(self.other_basis,
270
 
                                                      self.base_rev_id,
271
 
                                                      self.this_branch)
272
235
 
273
236
    def do_merge(self):
274
 
        kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree,
275
 
                  'other_tree': self.other_tree,
 
237
        kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree, 
 
238
                  'other_tree': self.other_tree, 
276
239
                  'interesting_ids': self.interesting_ids,
277
 
                  'interesting_files': self.interesting_files,
278
240
                  'pp': self.pp}
279
241
        if self.merge_type.requires_base:
280
242
            kwargs['base_tree'] = self.base_tree
281
243
        if self.merge_type.supports_reprocess:
282
244
            kwargs['reprocess'] = self.reprocess
283
245
        elif self.reprocess:
284
 
            raise BzrError("Conflict reduction is not supported for merge"
285
 
                                  " type %s." % self.merge_type)
 
246
            raise BzrError("Reprocess is not supported for this merge"
 
247
                                  " type. %s" % merge_type)
286
248
        if self.merge_type.supports_show_base:
287
249
            kwargs['show_base'] = self.show_base
288
250
        elif self.show_base:
289
251
            raise BzrError("Showing base is not supported for this"
290
252
                                  " merge type. %s" % self.merge_type)
291
 
        self.this_tree.lock_tree_write()
292
 
        if self.base_tree is not None:
293
 
            self.base_tree.lock_read()
294
 
        if self.other_tree is not None:
295
 
            self.other_tree.lock_read()
296
 
        try:
297
 
            merge = self.merge_type(pb=self._pb,
298
 
                                    change_reporter=self.change_reporter,
299
 
                                    **kwargs)
300
 
            if self.recurse == 'down':
301
 
                for path, file_id in self.this_tree.iter_references():
302
 
                    sub_tree = self.this_tree.get_nested_tree(file_id, path)
303
 
                    other_revision = self.other_tree.get_reference_revision(
304
 
                        file_id, path)
305
 
                    if  other_revision == sub_tree.last_revision():
306
 
                        continue
307
 
                    sub_merge = Merger(sub_tree.branch, this_tree=sub_tree)
308
 
                    sub_merge.merge_type = self.merge_type
309
 
                    relpath = self.this_tree.relpath(path)
310
 
                    other_branch = self.other_branch.reference_parent(file_id, relpath)
311
 
                    sub_merge.set_other_revision(other_revision, other_branch)
312
 
                    base_revision = self.base_tree.get_reference_revision(file_id)
313
 
                    sub_merge.base_tree = \
314
 
                        sub_tree.branch.repository.revision_tree(base_revision)
315
 
                    sub_merge.do_merge()
316
 
 
317
 
        finally:
318
 
            if self.other_tree is not None:
319
 
                self.other_tree.unlock()
320
 
            if self.base_tree is not None:
321
 
                self.base_tree.unlock()
322
 
            self.this_tree.unlock()
 
253
        merge = self.merge_type(pb=self._pb, **kwargs)
323
254
        if len(merge.cooked_conflicts) == 0:
324
255
            if not self.ignore_zero:
325
256
                note("All changes applied successfully.")
328
259
 
329
260
        return len(merge.cooked_conflicts)
330
261
 
 
262
    def regen_inventory(self, new_entries):
 
263
        old_entries = self.this_tree.read_working_inventory()
 
264
        new_inventory = {}
 
265
        by_path = {}
 
266
        new_entries_map = {} 
 
267
        for path, file_id in new_entries:
 
268
            if path is None:
 
269
                continue
 
270
            new_entries_map[file_id] = path
 
271
 
 
272
        def id2path(file_id):
 
273
            path = new_entries_map.get(file_id)
 
274
            if path is not None:
 
275
                return path
 
276
            entry = old_entries[file_id]
 
277
            if entry.parent_id is None:
 
278
                return entry.name
 
279
            return pathjoin(id2path(entry.parent_id), entry.name)
 
280
            
 
281
        for file_id in old_entries:
 
282
            entry = old_entries[file_id]
 
283
            path = id2path(file_id)
 
284
            new_inventory[file_id] = (path, file_id, entry.parent_id, 
 
285
                                      entry.kind)
 
286
            by_path[path] = file_id
 
287
        
 
288
        deletions = 0
 
289
        insertions = 0
 
290
        new_path_list = []
 
291
        for path, file_id in new_entries:
 
292
            if path is None:
 
293
                del new_inventory[file_id]
 
294
                deletions += 1
 
295
            else:
 
296
                new_path_list.append((path, file_id))
 
297
                if file_id not in old_entries:
 
298
                    insertions += 1
 
299
        # Ensure no file is added before its parent
 
300
        new_path_list.sort()
 
301
        for path, file_id in new_path_list:
 
302
            if path == '':
 
303
                parent = None
 
304
            else:
 
305
                parent = by_path[os.path.dirname(path)]
 
306
            abspath = pathjoin(self.this_tree.basedir, path)
 
307
            kind = bzrlib.osutils.file_kind(abspath)
 
308
            new_inventory[file_id] = (path, file_id, parent, kind)
 
309
            by_path[path] = file_id 
 
310
 
 
311
        # Get a list in insertion order
 
312
        new_inventory_list = new_inventory.values()
 
313
        mutter ("""Inventory regeneration:
 
314
    old length: %i insertions: %i deletions: %i new_length: %i"""\
 
315
            % (len(old_entries), insertions, deletions, 
 
316
               len(new_inventory_list)))
 
317
        assert len(new_inventory_list) == len(old_entries) + insertions\
 
318
            - deletions
 
319
        new_inventory_list.sort()
 
320
        return new_inventory_list
 
321
 
331
322
 
332
323
class Merge3Merger(object):
333
324
    """Three-way merger that uses the merge3 text merger"""
335
326
    supports_reprocess = True
336
327
    supports_show_base = True
337
328
    history_based = False
338
 
    winner_idx = {"this": 2, "other": 1, "conflict": 1}
339
329
 
340
330
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
341
331
                 interesting_ids=None, reprocess=False, show_base=False,
342
 
                 pb=DummyProgress(), pp=None, change_reporter=None,
343
 
                 interesting_files=None):
344
 
        """Initialize the merger object and perform the merge.
345
 
 
346
 
        :param working_tree: The working tree to apply the merge to
347
 
        :param this_tree: The local tree in the merge operation
348
 
        :param base_tree: The common tree in the merge operation
349
 
        :param other_tree: The other other tree to merge changes from
350
 
        :param interesting_ids: The file_ids of files that should be
351
 
            participate in the merge.  May not be combined with
352
 
            interesting_files.
353
 
        :param: reprocess If True, perform conflict-reduction processing.
354
 
        :param show_base: If True, show the base revision in text conflicts.
355
 
            (incompatible with reprocess)
356
 
        :param pb: A Progress bar
357
 
        :param pp: A ProgressPhase object
358
 
        :param change_reporter: An object that should report changes made
359
 
        :param interesting_files: The tree-relative paths of files that should
360
 
            participate in the merge.  If these paths refer to directories,
361
 
            the contents of those directories will also be included.  May not
362
 
            be combined with interesting_ids.  If neither interesting_files nor
363
 
            interesting_ids is specified, all files may participate in the
364
 
            merge.
365
 
        """
 
332
                 pb=DummyProgress(), pp=None):
 
333
        """Initialize the merger object and perform the merge."""
366
334
        object.__init__(self)
367
 
        if interesting_files is not None:
368
 
            assert interesting_ids is None
369
 
        self.interesting_ids = interesting_ids
370
 
        self.interesting_files = interesting_files
371
335
        self.this_tree = working_tree
372
 
        self.this_tree.lock_tree_write()
373
336
        self.base_tree = base_tree
374
 
        self.base_tree.lock_read()
375
337
        self.other_tree = other_tree
376
 
        self.other_tree.lock_read()
377
338
        self._raw_conflicts = []
378
339
        self.cooked_conflicts = []
379
340
        self.reprocess = reprocess
380
341
        self.show_base = show_base
381
342
        self.pb = pb
382
343
        self.pp = pp
383
 
        self.change_reporter = change_reporter
384
344
        if self.pp is None:
385
345
            self.pp = ProgressPhase("Merge phase", 3, self.pb)
386
346
 
 
347
        if interesting_ids is not None:
 
348
            all_ids = interesting_ids
 
349
        else:
 
350
            all_ids = set(base_tree)
 
351
            all_ids.update(other_tree)
 
352
        working_tree.lock_write()
387
353
        self.tt = TreeTransform(working_tree, self.pb)
388
354
        try:
389
355
            self.pp.next_phase()
390
 
            entries = self._entries3()
391
 
            child_pb = ui.ui_factory.nested_progress_bar()
 
356
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
392
357
            try:
393
 
                for num, (file_id, changed, parents3, names3,
394
 
                          executable3) in enumerate(entries):
395
 
                    child_pb.update('Preparing file merge', num, len(entries))
396
 
                    self._merge_names(file_id, parents3, names3)
397
 
                    if changed:
398
 
                        file_status = self.merge_contents(file_id)
399
 
                    else:
400
 
                        file_status = 'unmodified'
401
 
                    self._merge_executable(file_id,
402
 
                        executable3, file_status)
 
358
                for num, file_id in enumerate(all_ids):
 
359
                    child_pb.update('Preparing file merge', num, len(all_ids))
 
360
                    self.merge_names(file_id)
 
361
                    file_status = self.merge_contents(file_id)
 
362
                    self.merge_executable(file_id, file_status)
403
363
            finally:
404
364
                child_pb.finished()
405
 
            self.fix_root()
 
365
                
406
366
            self.pp.next_phase()
407
 
            child_pb = ui.ui_factory.nested_progress_bar()
 
367
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
408
368
            try:
409
 
                fs_conflicts = resolve_conflicts(self.tt, child_pb,
410
 
                    lambda t, c: conflict_pass(t, c, self.other_tree))
 
369
                fs_conflicts = resolve_conflicts(self.tt, child_pb)
411
370
            finally:
412
371
                child_pb.finished()
413
 
            if change_reporter is not None:
414
 
                from bzrlib import delta
415
 
                delta.report_changes(self.tt._iter_changes(), change_reporter)
416
372
            self.cook_conflicts(fs_conflicts)
417
 
            for conflict in self.cooked_conflicts:
418
 
                warning(conflict)
 
373
            for line in conflicts_strings(self.cooked_conflicts):
 
374
                warning(line)
419
375
            self.pp.next_phase()
420
 
            results = self.tt.apply(no_conflicts=True)
 
376
            results = self.tt.apply()
421
377
            self.write_modified(results)
 
378
        finally:
422
379
            try:
423
 
                working_tree.add_conflicts(self.cooked_conflicts)
424
 
            except UnsupportedOperation:
 
380
                self.tt.finalize()
 
381
            except:
425
382
                pass
426
 
        finally:
427
 
            self.tt.finalize()
428
 
            self.other_tree.unlock()
429
 
            self.base_tree.unlock()
430
 
            self.this_tree.unlock()
 
383
            working_tree.unlock()
431
384
            self.pb.clear()
432
385
 
433
 
    def _entries3(self):
434
 
        """Gather data about files modified between three trees.
435
 
 
436
 
        Return a list of tuples of file_id, changed, parents3, names3,
437
 
        executable3.  changed is a boolean indicating whether the file contents
438
 
        or kind were changed.  parents3 is a tuple of parent ids for base,
439
 
        other and this.  names3 is a tuple of names for base, other and this.
440
 
        executable3 is a tuple of execute-bit values for base, other and this.
441
 
        """
442
 
        result = []
443
 
        iterator = self.other_tree._iter_changes(self.base_tree,
444
 
                include_unchanged=True, specific_files=self.interesting_files,
445
 
                extra_trees=[self.this_tree])
446
 
        for (file_id, paths, changed, versioned, parents, names, kind,
447
 
             executable) in iterator:
448
 
            if (self.interesting_ids is not None and
449
 
                file_id not in self.interesting_ids):
450
 
                continue
451
 
            if file_id in self.this_tree.inventory:
452
 
                entry = self.this_tree.inventory[file_id]
453
 
                this_name = entry.name
454
 
                this_parent = entry.parent_id
455
 
                this_executable = entry.executable
456
 
            else:
457
 
                this_name = None
458
 
                this_parent = None
459
 
                this_executable = None
460
 
            parents3 = parents + (this_parent,)
461
 
            names3 = names + (this_name,)
462
 
            executable3 = executable + (this_executable,)
463
 
            result.append((file_id, changed, parents3, names3, executable3))
464
 
        return result
465
 
 
466
 
    def fix_root(self):
467
 
        try:
468
 
            self.tt.final_kind(self.tt.root)
469
 
        except NoSuchFile:
470
 
            self.tt.cancel_deletion(self.tt.root)
471
 
        if self.tt.final_file_id(self.tt.root) is None:
472
 
            self.tt.version_file(self.tt.tree_file_id(self.tt.root), 
473
 
                                 self.tt.root)
474
 
        if self.other_tree.inventory.root is None:
475
 
            return
476
 
        other_root_file_id = self.other_tree.inventory.root.file_id
477
 
        other_root = self.tt.trans_id_file_id(other_root_file_id)
478
 
        if other_root == self.tt.root:
479
 
            return
480
 
        try:
481
 
            self.tt.final_kind(other_root)
482
 
        except NoSuchFile:
483
 
            return
484
 
        self.reparent_children(self.other_tree.inventory.root, self.tt.root)
485
 
        self.tt.cancel_creation(other_root)
486
 
        self.tt.cancel_versioning(other_root)
487
 
 
488
 
    def reparent_children(self, ie, target):
489
 
        for thing, child in ie.children.iteritems():
490
 
            trans_id = self.tt.trans_id_file_id(child.file_id)
491
 
            self.tt.adjust_path(self.tt.final_name(trans_id), target, trans_id)
492
 
 
493
386
    def write_modified(self, results):
494
387
        modified_hashes = {}
495
388
        for path in results.modified_paths:
540
433
        return tree.kind(file_id)
541
434
 
542
435
    @staticmethod
543
 
    def _three_way(base, other, this):
544
 
        #if base == other, either they all agree, or only THIS has changed.
545
 
        if base == other:
546
 
            return 'this'
547
 
        elif this not in (base, other):
548
 
            return 'conflict'
549
 
        # "Ambiguous clean merge" -- both sides have made the same change.
550
 
        elif this == other:
551
 
            return "this"
552
 
        # this == base: only other has changed.
553
 
        else:
554
 
            return "other"
555
 
 
556
 
    @staticmethod
557
436
    def scalar_three_way(this_tree, base_tree, other_tree, file_id, key):
558
437
        """Do a three-way test on a scalar.
559
438
        Return "this", "other" or "conflict", depending whether a value wins.
574
453
            return "other"
575
454
 
576
455
    def merge_names(self, file_id):
 
456
        """Perform a merge on file_id names and parents"""
577
457
        def get_entry(tree):
578
458
            if file_id in tree.inventory:
579
459
                return tree.inventory[file_id]
582
462
        this_entry = get_entry(self.this_tree)
583
463
        other_entry = get_entry(self.other_tree)
584
464
        base_entry = get_entry(self.base_tree)
585
 
        entries = (base_entry, other_entry, this_entry)
586
 
        names = []
587
 
        parents = []
588
 
        for entry in entries:
589
 
            if entry is None:
590
 
                names.append(None)
591
 
                parents.append(None)
592
 
            else:
593
 
                names.append(entry.name)
594
 
                parents.append(entry.parent_id)
595
 
        return self._merge_names(file_id, parents, names)
596
 
 
597
 
    def _merge_names(self, file_id, parents, names):
598
 
        """Perform a merge on file_id names and parents"""
599
 
        base_name, other_name, this_name = names
600
 
        base_parent, other_parent, this_parent = parents
601
 
 
602
 
        name_winner = self._three_way(*names)
603
 
 
604
 
        parent_id_winner = self._three_way(*parents)
605
 
        if this_name is None:
 
465
        name_winner = self.scalar_three_way(this_entry, base_entry, 
 
466
                                            other_entry, file_id, self.name)
 
467
        parent_id_winner = self.scalar_three_way(this_entry, base_entry, 
 
468
                                                 other_entry, file_id, 
 
469
                                                 self.parent)
 
470
        if this_entry is None:
606
471
            if name_winner == "this":
607
472
                name_winner = "other"
608
473
            if parent_id_winner == "this":
612
477
        if name_winner == "conflict":
613
478
            trans_id = self.tt.trans_id_file_id(file_id)
614
479
            self._raw_conflicts.append(('name conflict', trans_id, 
615
 
                                        this_name, other_name))
 
480
                                        self.name(this_entry, file_id), 
 
481
                                        self.name(other_entry, file_id)))
616
482
        if parent_id_winner == "conflict":
617
483
            trans_id = self.tt.trans_id_file_id(file_id)
618
484
            self._raw_conflicts.append(('parent conflict', trans_id, 
619
 
                                        this_parent, other_parent))
620
 
        if other_name is None:
 
485
                                        self.parent(this_entry, file_id), 
 
486
                                        self.parent(other_entry, file_id)))
 
487
        if other_entry is None:
621
488
            # it doesn't matter whether the result was 'other' or 
622
489
            # 'conflict'-- if there's no 'other', we leave it alone.
623
490
            return
624
491
        # if we get here, name_winner and parent_winner are set to safe values.
 
492
        winner_entry = {"this": this_entry, "other": other_entry, 
 
493
                        "conflict": other_entry}
625
494
        trans_id = self.tt.trans_id_file_id(file_id)
626
 
        parent_id = parents[self.winner_idx[parent_id_winner]]
627
 
        if parent_id is not None:
628
 
            parent_trans_id = self.tt.trans_id_file_id(parent_id)
629
 
            self.tt.adjust_path(names[self.winner_idx[name_winner]],
630
 
                                parent_trans_id, trans_id)
 
495
        parent_id = winner_entry[parent_id_winner].parent_id
 
496
        parent_trans_id = self.tt.trans_id_file_id(parent_id)
 
497
        self.tt.adjust_path(winner_entry[name_winner].name, parent_trans_id,
 
498
                            trans_id)
631
499
 
632
500
    def merge_contents(self, file_id):
633
501
        """Performa a merge on file_id contents."""
635
503
            if file_id not in tree:
636
504
                return (None, None)
637
505
            kind = tree.kind(file_id)
 
506
            if kind == "root_directory":
 
507
                kind = "directory"
638
508
            if kind == "file":
639
509
                contents = tree.get_file_sha1(file_id)
640
510
            elif kind == "symlink":
642
512
            else:
643
513
                contents = None
644
514
            return kind, contents
645
 
 
646
 
        def contents_conflict():
647
 
            trans_id = self.tt.trans_id_file_id(file_id)
648
 
            name = self.tt.final_name(trans_id)
649
 
            parent_id = self.tt.final_parent(trans_id)
650
 
            if file_id in self.this_tree.inventory:
651
 
                self.tt.unversion_file(trans_id)
652
 
                if file_id in self.this_tree:
653
 
                    self.tt.delete_contents(trans_id)
654
 
            file_group = self._dump_conflicts(name, parent_id, file_id, 
655
 
                                              set_version=True)
656
 
            self._raw_conflicts.append(('contents conflict', file_group))
657
 
 
658
515
        # See SPOT run.  run, SPOT, run.
659
516
        # So we're not QUITE repeating ourselves; we do tricky things with
660
517
        # file kind...
691
548
                # THIS and OTHER are both files, so text merge.  Either
692
549
                # BASE is a file, or both converted to files, so at least we
693
550
                # have agreement that output should be a file.
694
 
                try:
695
 
                    self.text_merge(file_id, trans_id)
696
 
                except BinaryFile:
697
 
                    return contents_conflict()
698
551
                if file_id not in self.this_tree.inventory:
699
552
                    self.tt.version_file(file_id, trans_id)
 
553
                self.text_merge(file_id, trans_id)
700
554
                try:
701
555
                    self.tt.tree_kind(trans_id)
702
556
                    self.tt.delete_contents(trans_id)
705
559
                return "modified"
706
560
            else:
707
561
                # Scalar conflict, can't text merge.  Dump conflicts
708
 
                return contents_conflict()
 
562
                trans_id = self.tt.trans_id_file_id(file_id)
 
563
                name = self.tt.final_name(trans_id)
 
564
                parent_id = self.tt.final_parent(trans_id)
 
565
                if file_id in self.this_tree.inventory:
 
566
                    self.tt.unversion_file(trans_id)
 
567
                    self.tt.delete_contents(trans_id)
 
568
                file_group = self._dump_conflicts(name, parent_id, file_id, 
 
569
                                                  set_version=True)
 
570
                self._raw_conflicts.append(('contents conflict', file_group))
709
571
 
710
572
    def get_lines(self, tree, file_id):
711
573
        """Return the lines in a file, or an empty list."""
792
654
 
793
655
    def merge_executable(self, file_id, file_status):
794
656
        """Perform a merge on the execute bit."""
795
 
        executable = [self.executable(t, file_id) for t in (self.base_tree,
796
 
                      self.other_tree, self.this_tree)]
797
 
        self._merge_executable(file_id, executable, file_status)
798
 
 
799
 
    def _merge_executable(self, file_id, executable, file_status):
800
 
        """Perform a merge on the execute bit."""
801
 
        base_executable, other_executable, this_executable = executable
802
657
        if file_status == "deleted":
803
658
            return
804
659
        trans_id = self.tt.trans_id_file_id(file_id)
807
662
                return
808
663
        except NoSuchFile:
809
664
            return
810
 
        winner = self._three_way(*executable)
 
665
        winner = self.scalar_three_way(self.this_tree, self.base_tree, 
 
666
                                       self.other_tree, file_id, 
 
667
                                       self.executable)
811
668
        if winner == "conflict":
812
669
        # There must be a None in here, if we have a conflict, but we
813
670
        # need executability since file status was not deleted.
814
 
            if self.executable(self.other_tree, file_id) is None:
 
671
            if self.other_tree.is_executable(file_id) is None:
815
672
                winner = "this"
816
673
            else:
817
674
                winner = "other"
818
675
        if winner == "this":
819
676
            if file_status == "modified":
820
 
                executability = this_executable
 
677
                executability = self.this_tree.is_executable(file_id)
821
678
                if executability is not None:
822
679
                    trans_id = self.tt.trans_id_file_id(file_id)
823
680
                    self.tt.set_executability(executability, trans_id)
824
681
        else:
825
682
            assert winner == "other"
826
683
            if file_id in self.other_tree:
827
 
                executability = other_executable
 
684
                executability = self.other_tree.is_executable(file_id)
828
685
            elif file_id in self.this_tree:
829
 
                executability = this_executable
 
686
                executability = self.this_tree.is_executable(file_id)
830
687
            elif file_id in self.base_tree:
831
 
                executability = base_executable
 
688
                executability = self.base_tree.is_executable(file_id)
832
689
            if executability is not None:
833
690
                trans_id = self.tt.trans_id_file_id(file_id)
834
691
                self.tt.set_executability(executability, trans_id)
835
692
 
836
693
    def cook_conflicts(self, fs_conflicts):
837
694
        """Convert all conflicts into a form that doesn't depend on trans_id"""
838
 
        from conflicts import Conflict
839
695
        name_conflicts = {}
840
696
        self.cooked_conflicts.extend(cook_conflicts(fs_conflicts, self.tt))
841
697
        fp = FinalPaths(self.tt)
858
714
                    if path.endswith(suffix):
859
715
                        path = path[:-len(suffix)]
860
716
                        break
861
 
                c = Conflict.factory(conflict_type, path=path, file_id=file_id)
862
 
                self.cooked_conflicts.append(c)
 
717
                self.cooked_conflicts.append((conflict_type, file_id, path))
863
718
            if conflict_type == 'text conflict':
864
719
                trans_id = conflict[1]
865
720
                path = fp.get_path(trans_id)
866
721
                file_id = self.tt.final_file_id(trans_id)
867
 
                c = Conflict.factory(conflict_type, path=path, file_id=file_id)
868
 
                self.cooked_conflicts.append(c)
 
722
                self.cooked_conflicts.append((conflict_type, file_id, path))
869
723
 
870
724
        for trans_id, conflicts in name_conflicts.iteritems():
871
725
            try:
880
734
            except KeyError:
881
735
                this_name = other_name = self.tt.final_name(trans_id)
882
736
            other_path = fp.get_path(trans_id)
883
 
            if this_parent is not None and this_name is not None:
 
737
            if this_parent is not None:
884
738
                this_parent_path = \
885
739
                    fp.get_path(self.tt.trans_id_file_id(this_parent))
886
740
                this_path = pathjoin(this_parent_path, this_name)
887
741
            else:
888
742
                this_path = "<deleted>"
889
743
            file_id = self.tt.final_file_id(trans_id)
890
 
            c = Conflict.factory('path conflict', path=this_path,
891
 
                                 conflict_path=other_path, file_id=file_id)
892
 
            self.cooked_conflicts.append(c)
893
 
        self.cooked_conflicts.sort(key=Conflict.sort_key)
 
744
            self.cooked_conflicts.append(('path conflict', file_id, this_path, 
 
745
                                         other_path))
894
746
 
895
747
 
896
748
class WeaveMerger(Merge3Merger):
897
749
    """Three-way tree merger, text weave merger."""
898
 
    supports_reprocess = True
 
750
    supports_reprocess = False
899
751
    supports_show_base = False
900
752
 
901
753
    def __init__(self, working_tree, this_tree, base_tree, other_tree, 
902
 
                 interesting_ids=None, pb=DummyProgress(), pp=None,
903
 
                 reprocess=False, change_reporter=None,
904
 
                 interesting_files=None):
 
754
                 interesting_ids=None, pb=DummyProgress(), pp=None):
905
755
        self.this_revision_tree = self._get_revision_tree(this_tree)
906
756
        self.other_revision_tree = self._get_revision_tree(other_tree)
907
757
        super(WeaveMerger, self).__init__(working_tree, this_tree, 
908
758
                                          base_tree, other_tree, 
909
759
                                          interesting_ids=interesting_ids, 
910
 
                                          pb=pb, pp=pp, reprocess=reprocess,
911
 
                                          change_reporter=change_reporter)
 
760
                                          pb=pb, pp=pp)
912
761
 
913
762
    def _get_revision_tree(self, tree):
914
 
        """Return a revision tree related to this tree.
 
763
        """Return a revision tree releated to this tree.
915
764
        If the tree is a WorkingTree, the basis will be returned.
916
765
        """
917
766
        if getattr(tree, 'get_weave', False) is False:
938
787
        this_revision_id = self.this_revision_tree.inventory[file_id].revision
939
788
        other_revision_id = \
940
789
            self.other_revision_tree.inventory[file_id].revision
941
 
        wm = WeaveMerge(weave, this_revision_id, other_revision_id, 
942
 
                        '<<<<<<< TREE\n', '>>>>>>> MERGE-SOURCE\n')
943
 
        return wm.merge_lines(self.reprocess)
 
790
        plan =  weave.plan_merge(this_revision_id, other_revision_id)
 
791
        return weave.weave_merge(plan, '<<<<<<< TREE\n', 
 
792
                                       '>>>>>>> MERGE-SOURCE\n')
944
793
 
945
794
    def text_merge(self, file_id, trans_id):
946
795
        """Perform a (weave) text merge for a given file and file-id.
948
797
        and a conflict will be noted.
949
798
        """
950
799
        self._check_file(file_id)
951
 
        lines, conflicts = self._merged_lines(file_id)
952
 
        lines = list(lines)
953
 
        # Note we're checking whether the OUTPUT is binary in this case, 
954
 
        # because we don't want to get into weave merge guts.
955
 
        check_text_lines(lines)
 
800
        lines = self._merged_lines(file_id)
 
801
        conflicts = '<<<<<<< TREE\n' in lines
956
802
        self.tt.create_file(lines, trans_id)
957
803
        if conflicts:
958
804
            self._raw_conflicts.append(('text conflict', trans_id))
965
811
 
966
812
class Diff3Merger(Merge3Merger):
967
813
    """Three-way merger using external diff3 for text merging"""
968
 
 
969
814
    def dump_file(self, temp_dir, name, tree, file_id):
970
815
        out_path = pathjoin(temp_dir, name)
971
 
        out_file = open(out_path, "wb")
972
 
        try:
973
 
            in_file = tree.get_file(file_id)
974
 
            for line in in_file:
975
 
                out_file.write(line)
976
 
        finally:
977
 
            out_file.close()
 
816
        out_file = file(out_path, "wb")
 
817
        in_file = tree.get_file(file_id)
 
818
        for line in in_file:
 
819
            out_file.write(line)
978
820
        return out_path
979
821
 
980
822
    def text_merge(self, file_id, trans_id):
983
825
        will be dumped, and a will be conflict noted.
984
826
        """
985
827
        import bzrlib.patch
986
 
        temp_dir = osutils.mkdtemp(prefix="bzr-")
 
828
        temp_dir = mkdtemp(prefix="bzr-")
987
829
        try:
988
830
            new_file = pathjoin(temp_dir, "new")
989
831
            this = self.dump_file(temp_dir, "this", self.this_tree, file_id)
992
834
            status = bzrlib.patch.diff3(new_file, this, base, other)
993
835
            if status not in (0, 1):
994
836
                raise BzrError("Unhandled diff3 exit code")
995
 
            f = open(new_file, 'rb')
996
 
            try:
997
 
                self.tt.create_file(f, trans_id)
998
 
            finally:
999
 
                f.close()
 
837
            self.tt.create_file(file(new_file, "rb"), trans_id)
1000
838
            if status == 1:
1001
839
                name = self.tt.final_name(trans_id)
1002
840
                parent_id = self.tt.final_parent(trans_id)
1003
841
                self._dump_conflicts(name, parent_id, file_id)
1004
 
                self._raw_conflicts.append(('text conflict', trans_id))
 
842
            self._raw_conflicts.append(('text conflict', trans_id))
1005
843
        finally:
1006
 
            osutils.rmtree(temp_dir)
 
844
            rmtree(temp_dir)
1007
845
 
1008
846
 
1009
847
def merge_inner(this_branch, other_tree, base_tree, ignore_zero=False,
1010
 
                backup_files=False,
1011
 
                merge_type=Merge3Merger,
1012
 
                interesting_ids=None,
1013
 
                show_base=False,
1014
 
                reprocess=False,
 
848
                backup_files=False, 
 
849
                merge_type=Merge3Merger, 
 
850
                interesting_ids=None, 
 
851
                show_base=False, 
 
852
                reprocess=False, 
1015
853
                other_rev_id=None,
1016
854
                interesting_files=None,
1017
855
                this_tree=None,
1018
 
                pb=DummyProgress(),
1019
 
                change_reporter=None):
 
856
                pb=DummyProgress()):
1020
857
    """Primary interface for merging. 
1021
858
 
1022
859
        typical use is probably 
1024
861
                     branch.get_revision_tree(base_revision))'
1025
862
        """
1026
863
    if this_tree is None:
1027
 
        raise BzrError("bzrlib.merge.merge_inner requires a this_tree "
1028
 
            "parameter as of bzrlib version 0.8.")
1029
 
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
1030
 
                    pb=pb, change_reporter=change_reporter)
 
864
        warn("bzrlib.merge.merge_inner requires a this_tree parameter as of "
 
865
             "bzrlib version 0.8.",
 
866
             DeprecationWarning,
 
867
             stacklevel=2)
 
868
        this_tree = this_branch.bzrdir.open_workingtree()
 
869
    merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree, 
 
870
                    pb=pb)
1031
871
    merger.backup_files = backup_files
1032
872
    merger.merge_type = merge_type
1033
873
    merger.interesting_ids = interesting_ids
1035
875
    if interesting_files:
1036
876
        assert not interesting_ids, ('Only supply interesting_ids'
1037
877
                                     ' or interesting_files')
1038
 
        merger.interesting_files = interesting_files
1039
 
    merger.show_base = show_base
 
878
        merger._set_interesting_files(interesting_files)
 
879
    merger.show_base = show_base 
1040
880
    merger.reprocess = reprocess
1041
881
    merger.other_rev_id = other_rev_id
1042
882
    merger.other_basis = other_rev_id
1043
883
    return merger.do_merge()
1044
884
 
1045
 
def get_merge_type_registry():
1046
 
    """Merge type registry is in bzrlib.option to avoid circular imports.
1047
885
 
1048
 
    This method provides a sanctioned way to retrieve it.
1049
 
    """
1050
 
    from bzrlib import option
1051
 
    return option._merge_type_registry
 
886
merge_types = {     "merge3": (Merge3Merger, "Native diff3-style merge"), 
 
887
                     "diff3": (Diff3Merger,  "Merge using external diff3"),
 
888
                     'weave': (WeaveMerger, "Weave-based merge")
 
889
              }