1
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
2
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
3
from bzrlib.changeset import Inventory, Diff3Merge
4
from bzrlib import find_branch
6
from bzrlib.errors import BzrCommandError
7
from bzrlib.delta import compare_trees
8
from trace import mutter, warning
1
# Copyright (C) 2005 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13
22
from fetch import greedy_fetch
25
import bzrlib.revision
26
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
27
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
28
from bzrlib.changeset import Inventory, Diff3Merge
29
from bzrlib.branch import find_branch
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches
31
from bzrlib.delta import compare_trees
32
from bzrlib.trace import mutter, warning
33
from bzrlib.fetch import greedy_fetch
34
from bzrlib.revision import is_ancestor
16
36
# comments from abentley on irc: merge happens in two stages, each
17
37
# of which generates a changeset object
19
39
# stage 1: generate OLD->OTHER,
20
40
# stage 2: use MINE and OLD->OTHER to generate MINE -> RESULT
22
class UnrelatedBranches(BzrCommandError):
24
msg = "Branches have no common ancestor, and no base revision"\
26
BzrCommandError.__init__(self, msg)
29
42
class MergeConflictHandler(ExceptionConflictHandler):
30
43
"""Handle conflicts encountered while merging.
184
197
return self.tree.inventory.has_id(file_id)
199
def has_or_had_id(self, file_id):
200
if file_id == self.tree.inventory.root.file_id:
202
return self.tree.inventory.has_id(file_id)
186
204
def readonly_path(self, id):
187
205
if id not in self.tree:
208
226
"""Merge changes into a tree.
211
Base for three-way merge.
229
tuple(path, revision) Base for three-way merge.
213
Other revision for three-way merge.
231
tuple(path, revision) Other revision for three-way merge.
215
233
Directory to merge changes into; '.' by default.
219
237
all available ancestors of other_revision and base_revision are
220
238
automatically pulled into the branch.
222
from bzrlib.revision import common_ancestor, is_ancestor
223
from bzrlib.revision import MultipleRevisionSources
240
from bzrlib.revision import common_ancestor, MultipleRevisionSources
224
241
from bzrlib.errors import NoSuchRevision
225
242
tempdir = tempfile.mkdtemp(prefix="bzr-")
264
281
base_rev_id = base_branch.lookup_revision(base_revision[1])
265
282
if base_rev_id is not None:
266
283
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
267
MultipleRevisionSources(
284
MultipleRevisionSources(this_branch,
271
287
base_is_ancestor = False
272
288
if file_list is None: