15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
from fetch import greedy_fetch
23
24
import bzrlib.osutils
24
25
import bzrlib.revision
25
26
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
26
27
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
27
28
from bzrlib.changeset import Inventory, Diff3Merge
28
from bzrlib.branch import Branch
29
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
30
from bzrlib.errors import NoCommits
29
from bzrlib.branch import find_branch
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches
31
31
from bzrlib.delta import compare_trees
32
32
from bzrlib.trace import mutter, warning
33
from bzrlib.fetch import greedy_fetch, fetch
33
from bzrlib.fetch import greedy_fetch
34
34
from bzrlib.revision import is_ancestor
35
from bzrlib.osutils import rename
36
from bzrlib.revision import common_ancestor, MultipleRevisionSources
37
from bzrlib.errors import NoSuchRevision
40
36
# comments from abentley on irc: merge happens in two stages, each
41
37
# of which generates a changeset object
50
46
conflict that are not explicitly handled cause an exception and
51
47
terminate the merge.
53
def __init__(self, ignore_zero=False):
54
ExceptionConflictHandler.__init__(self)
49
def __init__(self, dir, ignore_zero=False):
50
ExceptionConflictHandler.__init__(self, dir)
56
52
self.ignore_zero = ignore_zero
111
107
self.add_suffix(this_path, ".THIS")
112
108
self.dump(base_lines, this_path+".BASE")
113
109
self.dump(other_lines, this_path+".OTHER")
114
rename(new_file, this_path)
110
os.rename(new_file, this_path)
115
111
self.conflict("Diff3 conflict encountered in %s" % this_path)
117
113
def new_contents_conflict(self, filename, other_contents):
138
134
def get_tree(treespec, temp_root, label, local_branch=None):
139
135
location, revno = treespec
140
branch = Branch.open_containing(location)
136
branch = find_branch(location)
141
137
if revno is None:
143
139
elif revno == -1:
144
140
revision = branch.last_revision()
146
revision = branch.get_rev_id(revno)
142
revision = branch.lookup_revision(revno)
147
143
return branch, get_revid_tree(branch, revision, temp_root, label,
239
235
If true, this_dir must have no uncommitted changes before the
242
All available ancestors of other_revision and base_revision are
237
all available ancestors of other_revision and base_revision are
243
238
automatically pulled into the branch.
240
from bzrlib.revision import common_ancestor, MultipleRevisionSources
241
from bzrlib.errors import NoSuchRevision
245
242
tempdir = tempfile.mkdtemp(prefix="bzr-")
247
244
if this_dir is None:
249
this_branch = Branch.open_containing(this_dir)
246
this_branch = find_branch(this_dir)
250
247
this_rev_id = this_branch.last_revision()
251
248
if this_rev_id is None:
252
249
raise BzrCommandError("This branch has no commits")
260
257
if other_revision[1] == -1:
261
258
other_rev_id = other_branch.last_revision()
262
if other_rev_id is None:
263
raise NoCommits(other_branch)
264
259
other_basis = other_rev_id
265
260
elif other_revision[1] is not None:
266
other_rev_id = other_branch.get_rev_id(other_revision[1])
261
other_rev_id = other_branch.lookup_revision(other_revision[1])
267
262
other_basis = other_rev_id
269
264
other_rev_id = None
270
265
other_basis = other_branch.last_revision()
271
if other_basis is None:
272
raise NoCommits(other_branch)
273
266
if base_revision == [None, None]:
275
base_rev_id = common_ancestor(this_rev_id, other_basis,
277
except NoCommonAncestor:
267
base_rev_id = common_ancestor(this_rev_id, other_basis,
269
if base_rev_id is None:
278
270
raise UnrelatedBranches()
279
271
base_tree = get_revid_tree(this_branch, base_rev_id, tempdir,
286
278
elif base_revision[1] is None:
287
279
base_rev_id = None
289
base_rev_id = base_branch.get_rev_id(base_revision[1])
290
fetch(from_branch=base_branch, to_branch=this_branch)
291
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
281
base_rev_id = base_branch.lookup_revision(base_revision[1])
282
if base_rev_id is not None:
283
base_is_ancestor = is_ancestor(this_rev_id, base_rev_id,
284
MultipleRevisionSources(this_branch,
287
base_is_ancestor = False
293
288
if file_list is None:
294
289
interesting_ids = None
352
347
inv_changes = merge_flex(this_tree, base_tree, other_tree,
353
348
generate_cset_optimized, get_inventory,
354
MergeConflictHandler(ignore_zero=ignore_zero),
349
MergeConflictHandler(base_tree.root,
350
ignore_zero=ignore_zero),
355
351
merge_factory=merge_factory,
356
352
interesting_ids=interesting_ids)
364
assert path.startswith('.' + os.sep), "path is %s" % path
360
assert path.startswith('./'), "path is %s" % path
366
362
adjust_ids.append((path, id))
367
363
if len(adjust_ids) > 0: