37
37
from bzrlib.merge3 import Merge3
38
38
import bzrlib.osutils
39
39
from bzrlib.osutils import rename, pathjoin
40
from progress import DummyProgress
40
from progress import DummyProgress, ProgressPhase
41
41
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
42
42
from bzrlib.symbol_versioning import *
43
43
from bzrlib.trace import mutter, warning, note
44
44
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
45
45
conflicts_strings, FinalPaths, create_by_entry,
48
49
# TODO: Report back as changes are merged in
203
206
mutter("doing merge() with no base_revision specified")
204
207
if base_revision == [None, None]:
206
self.base_rev_id = common_ancestor(self.this_basis,
208
self.this_branch.repository,
209
pb = bzrlib.ui.ui_factory.nested_progress_bar()
211
this_repo = self.this_branch.repository
212
self.base_rev_id = common_ancestor(self.this_basis,
210
217
except NoCommonAncestor:
211
218
raise UnrelatedBranches()
212
219
self.base_tree = _get_revid_tree(self.this_branch, self.base_rev_id,
228
235
def do_merge(self):
229
236
kwargs = {'working_tree':self.this_tree, 'this_tree': self.this_tree,
230
237
'other_tree': self.other_tree,
231
'interesting_ids': self.interesting_ids}
238
'interesting_ids': self.interesting_ids,
232
240
if self.merge_type.requires_base:
233
241
kwargs['base_tree'] = self.base_tree
234
242
if self.merge_type.supports_reprocess:
321
329
def __init__(self, working_tree, this_tree, base_tree, other_tree,
322
330
interesting_ids=None, reprocess=False, show_base=False,
331
pb=DummyProgress(), pp=None):
324
332
"""Initialize the merger object and perform the merge."""
325
333
object.__init__(self)
326
334
self.this_tree = working_tree
331
339
self.reprocess = reprocess
332
340
self.show_base = show_base
344
self.pp = ProgressPhase("Merge phase", 3, self.pb)
335
346
if interesting_ids is not None:
336
347
all_ids = interesting_ids
338
349
all_ids = set(base_tree)
339
350
all_ids.update(other_tree)
351
working_tree.lock_write()
340
352
self.tt = TreeTransform(working_tree, self.pb)
342
for num, file_id in enumerate(all_ids):
343
self.pb.update('Preparing file merge', num+1, len(all_ids))
344
self.merge_names(file_id)
345
file_status = self.merge_contents(file_id)
346
self.merge_executable(file_id, file_status)
355
child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
357
for num, file_id in enumerate(all_ids):
358
child_pb.update('Preparing file merge', num, len(all_ids))
359
self.merge_names(file_id)
360
file_status = self.merge_contents(file_id)
361
self.merge_executable(file_id, file_status)
349
fs_conflicts = resolve_conflicts(self.tt, self.pb)
366
child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
368
fs_conflicts = resolve_conflicts(self.tt, child_pb)
350
371
self.cook_conflicts(fs_conflicts)
351
372
for line in conflicts_strings(self.cooked_conflicts):
375
results = self.tt.apply()
376
self.write_modified(results)
356
379
self.tt.finalize()
382
working_tree.unlock()
385
def write_modified(self, results):
387
for path in results.modified_paths:
388
file_id = self.this_tree.path2id(self.this_tree.relpath(path))
391
hash = self.this_tree.get_file_sha1(file_id)
394
modified_hashes[file_id] = hash
395
self.this_tree.set_merge_modified(modified_hashes)
361
398
def parent(entry, file_id):
362
399
"""Determine the parent for a file_id (used as a key method)"""
713
750
supports_show_base = False
715
752
def __init__(self, working_tree, this_tree, base_tree, other_tree,
716
interesting_ids=None, pb=DummyProgress()):
753
interesting_ids=None, pb=DummyProgress(), pp=None):
717
754
self.this_revision_tree = self._get_revision_tree(this_tree)
718
755
self.other_revision_tree = self._get_revision_tree(other_tree)
719
756
super(WeaveMerger, self).__init__(working_tree, this_tree,
720
757
base_tree, other_tree,
721
758
interesting_ids=interesting_ids,
724
761
def _get_revision_tree(self, tree):
725
762
"""Return a revision tree releated to this tree.
749
786
this_revision_id = self.this_revision_tree.inventory[file_id].revision
750
787
other_revision_id = \
751
788
self.other_revision_tree.inventory[file_id].revision
752
this_i = weave.lookup(this_revision_id)
753
other_i = weave.lookup(other_revision_id)
754
plan = weave.plan_merge(this_i, other_i)
789
plan = weave.plan_merge(this_revision_id, other_revision_id)
755
790
return weave.weave_merge(plan, '<<<<<<< TREE\n',
756
791
'>>>>>>> MERGE-SOURCE\n')
835
870
merger.backup_files = backup_files
836
871
merger.merge_type = merge_type
837
872
merger.interesting_ids = interesting_ids
873
merger.ignore_zero = ignore_zero
838
874
if interesting_files:
839
875
assert not interesting_ids, ('Only supply interesting_ids'
840
876
' or interesting_files')