15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
19
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
20
from bzrlib.changeset import Inventory, Diff3Merge
21
from bzrlib.branch import find_branch
22
from bzrlib.revision import is_ancestor
24
from bzrlib.errors import BzrCommandError, UnrelatedBranches
25
from bzrlib.delta import compare_trees
26
from trace import mutter, warning
22
31
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 Branch
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
31
from bzrlib.errors import NoCommits
32
from bzrlib.delta import compare_trees
33
from bzrlib.trace import mutter, warning
34
from bzrlib.fetch import greedy_fetch
35
from bzrlib.revision import is_ancestor
37
34
# comments from abentley on irc: merge happens in two stages, each
38
35
# of which generates a changeset object
47
44
conflict that are not explicitly handled cause an exception and
48
45
terminate the merge.
50
def __init__(self, ignore_zero=False):
51
ExceptionConflictHandler.__init__(self)
47
def __init__(self, dir, ignore_zero=False):
48
ExceptionConflictHandler.__init__(self, dir)
53
50
self.ignore_zero = ignore_zero
135
132
def get_tree(treespec, temp_root, label, local_branch=None):
136
133
location, revno = treespec
137
branch = Branch.open(location)
134
branch = find_branch(location)
138
135
if revno is None:
140
137
elif revno == -1:
141
138
revision = branch.last_patch()
143
revision = branch.get_rev_id(revno)
140
revision = branch.lookup_revision(revno)
144
141
return branch, get_revid_tree(branch, revision, temp_root, label,
258
250
if other_revision[1] == -1:
259
251
other_rev_id = other_branch.last_patch()
260
if other_rev_id is None:
261
raise NoCommits(other_branch)
262
252
other_basis = other_rev_id
263
253
elif other_revision[1] is not None:
264
other_rev_id = other_branch.get_rev_id(other_revision[1])
254
other_rev_id = other_branch.lookup_revision(other_revision[1])
265
255
other_basis = other_rev_id
267
257
other_rev_id = None
268
258
other_basis = other_branch.last_patch()
269
if other_basis is None:
270
raise NoCommits(other_branch)
271
259
if base_revision == [None, None]:
260
if other_revision[1] == -1:
263
o_revno = other_revision[1]
264
raise UnrelatedBranches()
273
base_rev_id = common_ancestor(this_rev_id, other_basis,
275
except NoCommonAncestor:
276
raise UnrelatedBranches()
277
base_tree = get_revid_tree(this_branch, base_rev_id, tempdir,
266
base_revision = this_branch.get_revision(base_rev_id)
267
base_branch = this_branch
268
except NoSuchRevision:
269
base_branch = other_branch
270
base_tree = get_revid_tree(base_branch, base_rev_id, tempdir,
279
272
base_is_ancestor = True
281
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
282
274
if base_revision[1] == -1:
275
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
283
276
base_rev_id = base_branch.last_patch()
284
277
elif base_revision[1] is None:
287
base_rev_id = base_branch.get_rev_id(base_revision[1])
288
multi_source = MultipleRevisionSources(this_branch, base_branch)
289
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
278
base_revno, base_rev_id = this_branch.common_ancestor(other_branch)
279
base_branch, base_tree = get_tree((base_revision[0], "revid:%s" % base_rev_id), tempdir, "base")
281
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
282
base_rev_id = base_branch.lookup_revision(base_revision[1])
283
if base_rev_id is not None:
284
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
285
MultipleRevisionSources(
289
base_is_ancestor = False
291
290
if file_list is None:
292
291
interesting_ids = None
307
306
merge_inner(this_branch, other_tree, base_tree, tempdir,
308
307
ignore_zero=ignore_zero, backup_files=backup_files,
309
308
merge_type=merge_type, interesting_ids=interesting_ids)
310
if base_is_ancestor and other_rev_id is not None\
311
and other_rev_id not in this_branch.revision_history():
309
if base_is_ancestor and other_rev_id is not None:
312
310
this_branch.add_pending_merge(other_rev_id)
314
312
shutil.rmtree(tempdir)
350
348
inv_changes = merge_flex(this_tree, base_tree, other_tree,
351
349
generate_cset_optimized, get_inventory,
352
MergeConflictHandler(ignore_zero=ignore_zero),
350
MergeConflictHandler(base_tree.root,
351
ignore_zero=ignore_zero),
353
352
merge_factory=merge_factory,
354
353
interesting_ids=interesting_ids)