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
18
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
2
19
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
3
20
from bzrlib.changeset import Inventory, Diff3Merge
4
from bzrlib import find_branch
21
from bzrlib.branch import find_branch
5
22
import bzrlib.osutils
6
23
from bzrlib.errors import BzrCommandError, UnrelatedBranches
7
24
from bzrlib.delta import compare_trees
110
128
if not self.ignore_zero:
111
129
print "%d conflicts encountered.\n" % self.conflicts
113
def get_tree(treespec, temp_root, label):
131
def get_tree(treespec, temp_root, label, local_branch=None):
114
132
location, revno = treespec
115
133
branch = find_branch(location)
116
134
if revno is None:
137
revision = branch.last_patch()
139
revision = branch.lookup_revision(revno)
140
return branch, get_revid_tree(branch, revision, temp_root, label,
143
def get_revid_tree(branch, revision, temp_root, label, local_branch):
117
145
base_tree = branch.working_tree()
119
base_tree = branch.basis_tree()
121
base_tree = branch.revision_tree(branch.lookup_revision(revno))
147
if local_branch is not None:
148
greedy_fetch(local_branch, branch, revision)
149
base_tree = local_branch.revision_tree(revision)
151
base_tree = branch.revision_tree(revision)
122
152
temp_path = os.path.join(temp_root, label)
123
153
os.mkdir(temp_path)
124
return branch, MergeTree(base_tree, temp_path)
154
return MergeTree(base_tree, temp_path)
127
157
def file_exists(tree, file_id):
197
227
If true, this_dir must have no uncommitted changes before the
229
all available ancestors of other_revision and base_revision are
230
automatically pulled into the branch.
232
from bzrlib.revision import common_ancestor, MultipleRevisionSources
233
from bzrlib.errors import NoSuchRevision
200
234
tempdir = tempfile.mkdtemp(prefix="bzr-")
202
236
if this_dir is None:
204
238
this_branch = find_branch(this_dir)
239
this_rev_id = this_branch.last_patch()
240
if this_rev_id is None:
241
raise BzrCommandError("This branch has no commits")
206
243
changes = compare_trees(this_branch.working_tree(),
207
244
this_branch.basis_tree(), False)
208
245
if changes.has_changed():
209
246
raise BzrCommandError("Working tree has uncommitted changes.")
210
other_branch, other_tree = get_tree(other_revision, tempdir, "other")
247
other_branch, other_tree = get_tree(other_revision, tempdir, "other",
249
if other_revision[1] == -1:
250
other_rev_id = other_branch.last_patch()
251
other_basis = other_rev_id
252
elif other_revision[1] is not None:
253
other_rev_id = other_branch.lookup_revision(other_revision[1])
254
other_basis = other_rev_id
257
other_basis = other_branch.last_patch()
211
258
if base_revision == [None, None]:
212
259
if other_revision[1] == -1:
215
262
o_revno = other_revision[1]
216
base_revno = this_branch.common_ancestor(other_branch,
217
other_revno=o_revno)[0]
218
if base_revno is None:
219
263
raise UnrelatedBranches()
220
base_revision = ['.', base_revno]
221
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
265
base_revision = this_branch.get_revision(base_rev_id)
266
base_branch = this_branch
267
except NoSuchRevision:
268
base_branch = other_branch
269
base_tree = get_revid_tree(base_branch, base_rev_id, tempdir,
271
base_is_ancestor = True
273
base_branch, base_tree = get_tree(base_revision, tempdir, "base")
274
if base_revision[1] == -1:
275
base_rev_id = base_branch.last_patch()
276
elif base_revision[1] is None:
279
base_rev_id = base_branch.lookup_revision(base_revision[1])
280
if base_rev_id is not None:
281
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
282
MultipleRevisionSources(
286
base_is_ancestor = False
222
287
if file_list is None:
223
288
interesting_ids = None
238
303
merge_inner(this_branch, other_tree, base_tree, tempdir,
239
304
ignore_zero=ignore_zero, backup_files=backup_files,
240
305
merge_type=merge_type, interesting_ids=interesting_ids)
306
if base_is_ancestor and other_rev_id is not None:
307
this_branch.add_pending_merge(other_rev_id)
242
309
shutil.rmtree(tempdir)