122
122
location, revno = treespec
123
123
branch = find_branch(location)
124
124
if revno is None:
127
revision = branch.last_patch()
129
revision = branch.lookup_revision(revno)
130
return branch, get_revid_tree(branch, revision, temp_root, label,
133
def get_revid_tree(branch, revision, temp_root, label, local_branch):
125
135
base_tree = branch.working_tree()
128
revision = branch.last_patch()
130
revision = branch.lookup_revision(revno)
131
137
if local_branch is not None:
132
if revision is not None:
133
greedy_fetch(local_branch, branch, revision)
138
greedy_fetch(local_branch, branch, revision)
134
139
base_tree = local_branch.revision_tree(revision)
136
141
base_tree = branch.revision_tree(revision)
137
142
temp_path = os.path.join(temp_root, label)
138
143
os.mkdir(temp_path)
139
return branch, MergeTree(base_tree, temp_path)
144
return MergeTree(base_tree, temp_path)
142
147
def file_exists(tree, file_id):
209
214
all available ancestors of other_revision and base_revision are
210
215
automatically pulled into the branch.
217
from bzrlib.revision import common_ancestor, MultipleRevisionSources
218
from bzrlib.errors import NoSuchRevision
212
219
tempdir = tempfile.mkdtemp(prefix="bzr-")
214
221
if this_dir is None:
216
223
this_branch = find_branch(this_dir)
224
this_rev_id = this_branch.last_patch()
225
if this_rev_id is None:
226
raise BzrCommandError("This branch has no commits")
218
228
changes = compare_trees(this_branch.working_tree(),
219
229
this_branch.basis_tree(), False)
221
231
raise BzrCommandError("Working tree has uncommitted changes.")
222
232
other_branch, other_tree = get_tree(other_revision, tempdir, "other",
234
if other_revision[1] == -1:
235
other_rev_id = other_branch.last_patch()
236
other_basis = other_rev_id
237
elif other_revision[1] is not None:
238
other_rev_id = other_branch.lookup_revision(other_revision[1])
239
other_basis = other_rev_id
242
other_basis = other_branch.last_patch()
224
243
if base_revision == [None, None]:
225
244
if other_revision[1] == -1:
228
247
o_revno = other_revision[1]
229
base_revno = this_branch.common_ancestor(other_branch,
230
other_revno=o_revno)[0]
231
if base_revno is None:
232
248
raise UnrelatedBranches()
233
base_revision = ['.', base_revno]
234
base_branch, base_tree = get_tree(base_revision, tempdir, "base",
250
base_revision = this_branch.get_revision(base_rev_id)
251
base_branch = this_branch
252
except NoSuchRevision:
253
base_branch = other_branch
254
base_tree = get_revid_tree(base_branch, base_rev_id, tempdir,
256
base_is_ancestor = True
258
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
259
if base_revision[1] == -1:
260
base_rev_id = base_branch.last_patch()
261
elif base_revision[1] is None:
264
base_rev_id = base_branch.lookup_revision(base_revision[1])
265
if base_rev_id is not None:
266
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
267
MultipleRevisionSources(
271
base_is_ancestor = False
236
272
if file_list is None:
237
273
interesting_ids = None
252
288
merge_inner(this_branch, other_tree, base_tree, tempdir,
253
289
ignore_zero=ignore_zero, backup_files=backup_files,
254
290
merge_type=merge_type, interesting_ids=interesting_ids)
291
if base_is_ancestor and other_rev_id is not None:
292
this_branch.add_pending_merge(other_rev_id)
256
294
shutil.rmtree(tempdir)