117
118
if not self.ignore_zero:
118
119
print "%d conflicts encountered.\n" % self.conflicts
120
def get_tree(treespec, temp_root, label):
121
def get_tree(treespec, temp_root, label, local_branch=None):
121
122
location, revno = treespec
122
123
branch = find_branch(location)
123
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):
124
135
base_tree = branch.working_tree()
126
base_tree = branch.basis_tree()
128
base_tree = branch.revision_tree(branch.lookup_revision(revno))
137
if local_branch is not None:
138
greedy_fetch(local_branch, branch, revision)
139
base_tree = local_branch.revision_tree(revision)
141
base_tree = branch.revision_tree(revision)
129
142
temp_path = os.path.join(temp_root, label)
130
143
os.mkdir(temp_path)
131
return branch, MergeTree(base_tree, temp_path)
144
return MergeTree(base_tree, temp_path)
134
147
def file_exists(tree, file_id):
165
178
def has_id(self, file_id):
166
179
return self.tree.has_id(file_id)
168
def has_or_had_id(self, file_id):
169
if file_id == self.tree.inventory.root.file_id:
171
return self.tree.inventory.has_id(file_id)
173
181
def readonly_path(self, id):
174
182
if id not in self.tree:
204
212
If true, this_dir must have no uncommitted changes before the
214
all available ancestors of other_revision and base_revision are
215
automatically pulled into the branch.
217
from bzrlib.revision import common_ancestor, is_ancestor
218
from bzrlib.revision import MultipleRevisionSources
219
from bzrlib.errors import NoSuchRevision
207
220
tempdir = tempfile.mkdtemp(prefix="bzr-")
209
222
if this_dir is None:
211
224
this_branch = find_branch(this_dir)
225
this_rev_id = this_branch.last_patch()
226
if this_rev_id is None:
227
raise BzrCommandError("This branch has no commits")
213
229
changes = compare_trees(this_branch.working_tree(),
214
230
this_branch.basis_tree(), False)
215
231
if changes.has_changed():
216
232
raise BzrCommandError("Working tree has uncommitted changes.")
217
other_branch, other_tree = get_tree(other_revision, tempdir, "other")
233
other_branch, other_tree = get_tree(other_revision, tempdir, "other",
235
if other_revision[1] == -1:
236
other_rev_id = other_branch.last_patch()
237
other_basis = other_rev_id
238
elif other_revision[1] is not None:
239
other_rev_id = other_branch.lookup_revision(other_revision[1])
240
other_basis = other_rev_id
243
other_basis = other_branch.last_patch()
218
244
if base_revision == [None, None]:
219
if other_revision[1] == -1:
222
o_revno = other_revision[1]
223
base_revno = this_branch.common_ancestor(other_branch,
224
other_revno=o_revno)[0]
225
if base_revno is None:
245
base_rev_id = common_ancestor(this_rev_id, other_basis,
247
if base_rev_id is None:
226
248
raise UnrelatedBranches()
227
base_revision = ['.', base_revno]
228
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
249
base_tree = get_revid_tree(this_branch, base_rev_id, tempdir,
251
base_is_ancestor = True
253
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
254
if base_revision[1] == -1:
255
base_rev_id = base_branch.last_patch()
256
elif base_revision[1] is None:
259
base_rev_id = base_branch.lookup_revision(base_revision[1])
260
if base_rev_id is not None:
261
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
262
MultipleRevisionSources(
266
base_is_ancestor = False
229
267
if file_list is None:
230
268
interesting_ids = None
245
283
merge_inner(this_branch, other_tree, base_tree, tempdir,
246
284
ignore_zero=ignore_zero, backup_files=backup_files,
247
285
merge_type=merge_type, interesting_ids=interesting_ids)
286
if base_is_ancestor and other_rev_id is not None:
287
this_branch.add_pending_merge(other_rev_id)
249
289
shutil.rmtree(tempdir)