260
261
All available ancestors of other_revision and base_revision are
261
262
automatically pulled into the branch.
263
tempdir = tempfile.mkdtemp(prefix="bzr-")
267
this_branch = Branch.open_containing(this_dir)[0]
268
this_rev_id = this_branch.last_revision()
269
if this_rev_id is None:
270
raise BzrCommandError("This branch has no commits")
272
changes = compare_trees(this_branch.working_tree(),
273
this_branch.basis_tree(), False)
274
if changes.has_changed():
275
raise BzrCommandError("Working tree has uncommitted changes.")
276
other_branch, other_tree = get_tree(other_revision, this_branch)
277
if other_revision[1] == -1:
278
other_rev_id = other_branch.last_revision()
279
if other_rev_id is None:
280
raise NoCommits(other_branch)
281
other_basis = other_rev_id
282
elif other_revision[1] is not None:
283
other_rev_id = other_branch.get_rev_id(other_revision[1])
284
other_basis = other_rev_id
287
other_basis = other_branch.last_revision()
288
if other_basis is None:
289
raise NoCommits(other_branch)
290
if base_revision == [None, None]:
292
base_rev_id = common_ancestor(this_rev_id, other_basis,
294
except NoCommonAncestor:
295
raise UnrelatedBranches()
296
base_tree = get_revid_tree(this_branch, base_rev_id, None)
297
base_is_ancestor = True
299
base_branch, base_tree = get_tree(base_revision)
300
if base_revision[1] == -1:
301
base_rev_id = base_branch.last_revision()
302
elif base_revision[1] is None:
305
base_rev_id = base_branch.get_rev_id(base_revision[1])
306
fetch(from_branch=base_branch, to_branch=this_branch)
307
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
309
if file_list is None:
310
interesting_ids = None
312
interesting_ids = set()
313
this_tree = this_branch.working_tree()
314
for fname in file_list:
315
path = this_tree.relpath(fname)
317
for tree in (this_tree, base_tree, other_tree):
318
file_id = tree.inventory.path2id(path)
319
if file_id is not None:
320
interesting_ids.add(file_id)
323
raise BzrCommandError("%s is not a source file in any"
325
merge_inner(this_branch, other_tree, base_tree, tempdir,
326
ignore_zero=ignore_zero, backup_files=backup_files,
327
merge_type=merge_type, interesting_ids=interesting_ids)
328
if base_is_ancestor and other_rev_id is not None\
329
and other_rev_id not in this_branch.revision_history():
330
this_branch.add_pending_merge(other_rev_id)
332
shutil.rmtree(tempdir)
266
this_branch = Branch.open_containing(this_dir)[0]
267
this_rev_id = this_branch.last_revision()
268
if this_rev_id is None:
269
raise BzrCommandError("This branch has no commits")
271
changes = compare_trees(this_branch.working_tree(),
272
this_branch.basis_tree(), False)
273
if changes.has_changed():
274
raise BzrCommandError("Working tree has uncommitted changes.")
275
other_branch, other_tree = get_tree(other_revision, this_branch)
276
if other_revision[1] == -1:
277
other_rev_id = other_branch.last_revision()
278
if other_rev_id is None:
279
raise NoCommits(other_branch)
280
other_basis = other_rev_id
281
elif other_revision[1] is not None:
282
other_rev_id = other_branch.get_rev_id(other_revision[1])
283
other_basis = other_rev_id
286
other_basis = other_branch.last_revision()
287
if other_basis is None:
288
raise NoCommits(other_branch)
289
if base_revision == [None, None]:
291
base_rev_id = common_ancestor(this_rev_id, other_basis,
293
except NoCommonAncestor:
294
raise UnrelatedBranches()
295
base_tree = get_revid_tree(this_branch, base_rev_id, None)
296
base_is_ancestor = True
298
base_branch, base_tree = get_tree(base_revision)
299
if base_revision[1] == -1:
300
base_rev_id = base_branch.last_revision()
301
elif base_revision[1] is None:
304
base_rev_id = base_branch.get_rev_id(base_revision[1])
305
fetch(from_branch=base_branch, to_branch=this_branch)
306
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
308
if file_list is None:
309
interesting_ids = None
311
interesting_ids = set()
312
this_tree = this_branch.working_tree()
313
for fname in file_list:
314
path = this_tree.relpath(fname)
316
for tree in (this_tree, base_tree, other_tree):
317
file_id = tree.inventory.path2id(path)
318
if file_id is not None:
319
interesting_ids.add(file_id)
322
raise BzrCommandError("%s is not a source file in any"
324
merge_inner(this_branch, other_tree, base_tree, tempdir=None,
325
ignore_zero=ignore_zero, backup_files=backup_files,
326
merge_type=merge_type, interesting_ids=interesting_ids)
327
if base_is_ancestor and other_rev_id is not None\
328
and other_rev_id not in this_branch.revision_history():
329
this_branch.add_pending_merge(other_rev_id)
335
332
def set_interesting(inventory_a, inventory_b, interesting_ids):
340
337
source_file.interesting = source_file.id in interesting_ids
343
def merge_inner(this_branch, other_tree, base_tree, tempdir,
344
ignore_zero=False, merge_type=ApplyMerge3, backup_files=False,
345
interesting_ids=None):
340
def merge_inner(this_branch, other_tree, base_tree, tempdir=None,
341
ignore_zero=False, merge_type=ApplyMerge3, backup_files=False,
342
interesting_ids=None):
343
"""Primary interface for merging.
345
typical use is probably
346
'merge_inner(branch, branch.get_revision_tree(other_revision),
347
branch.get_revision_tree(base_revision))'
350
_tempdir = tempfile.mkdtemp(prefix="bzr-")
354
_merge_inner(this_branch, other_tree, base_tree, _tempdir,
355
ignore_zero, merge_type, backup_files, interesting_ids)
358
shutil.rmtree(_tempdir)
361
def _merge_inner(this_branch, other_tree, base_tree, user_tempdir,
362
ignore_zero=False, merge_type=ApplyMerge3, backup_files=False,
363
interesting_ids=None):
347
364
def merge_factory(file_id, base, other):
348
365
contents_change = merge_type(file_id, base, other)