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
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
22
13
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
36
16
# comments from abentley on irc: merge happens in two stages, each
37
17
# of which generates a changeset object
39
19
# stage 1: generate OLD->OTHER,
40
20
# 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)
42
29
class MergeConflictHandler(ExceptionConflictHandler):
43
30
"""Handle conflicts encountered while merging.
197
184
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)
204
186
def readonly_path(self, id):
205
187
if id not in self.tree:
226
208
"""Merge changes into a tree.
229
tuple(path, revision) Base for three-way merge.
211
Base for three-way merge.
231
tuple(path, revision) Other revision for three-way merge.
213
Other revision for three-way merge.
233
215
Directory to merge changes into; '.' by default.
237
219
all available ancestors of other_revision and base_revision are
238
220
automatically pulled into the branch.
240
from bzrlib.revision import common_ancestor, MultipleRevisionSources
222
from bzrlib.revision import common_ancestor, is_ancestor
223
from bzrlib.revision import MultipleRevisionSources
241
224
from bzrlib.errors import NoSuchRevision
242
225
tempdir = tempfile.mkdtemp(prefix="bzr-")
281
264
base_rev_id = base_branch.lookup_revision(base_revision[1])
282
265
if base_rev_id is not None:
283
266
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
284
MultipleRevisionSources(this_branch,
267
MultipleRevisionSources(
287
271
base_is_ancestor = False
288
272
if file_list is None:
304
288
merge_inner(this_branch, other_tree, base_tree, tempdir,
305
289
ignore_zero=ignore_zero, backup_files=backup_files,
306
290
merge_type=merge_type, interesting_ids=interesting_ids)
307
if base_is_ancestor and other_rev_id is not None\
308
and other_rev_id not in this_branch.revision_history():
291
if base_is_ancestor and other_rev_id is not None:
309
292
this_branch.add_pending_merge(other_rev_id)
311
294
shutil.rmtree(tempdir)