~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-31 21:29:02 UTC
  • mfrom: (2104 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2110.
  • Revision ID: john@arbash-meinel.com-20061031212902-4b33920b90e9ce92
[merge] bzr.dev 2104

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import os
19
19
import errno
20
 
from tempfile import mkdtemp
21
20
import warnings
22
21
 
 
22
from bzrlib import (
 
23
    osutils,
 
24
    )
23
25
from bzrlib.branch import Branch
24
26
from bzrlib.conflicts import ConflictList, Conflict
25
27
from bzrlib.errors import (BzrCommandError,
37
39
                           )
38
40
from bzrlib.merge3 import Merge3
39
41
import bzrlib.osutils
40
 
from bzrlib.osutils import rename, pathjoin, rmtree
 
42
from bzrlib.osutils import rename, pathjoin
41
43
from progress import DummyProgress, ProgressPhase
42
44
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
43
45
from bzrlib.textfile import check_text_lines
44
46
from bzrlib.trace import mutter, warning, note
45
47
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
46
 
                              FinalPaths, create_by_entry, unique_add)
 
48
                              FinalPaths, create_by_entry, unique_add,
 
49
                              ROOT_PARENT)
47
50
from bzrlib.versionedfile import WeaveMerge
48
51
from bzrlib import ui
49
52
 
373
376
        else:
374
377
            all_ids = set(base_tree)
375
378
            all_ids.update(other_tree)
376
 
        working_tree.lock_write()
 
379
        working_tree.lock_tree_write()
377
380
        self.tt = TreeTransform(working_tree, self.pb)
378
381
        try:
379
382
            self.pp.next_phase()
386
389
                    self.merge_executable(file_id, file_status)
387
390
            finally:
388
391
                child_pb.finished()
389
 
                
 
392
            self.fix_root()
390
393
            self.pp.next_phase()
391
394
            child_pb = ui.ui_factory.nested_progress_bar()
392
395
            try:
408
411
            working_tree.unlock()
409
412
            self.pb.clear()
410
413
 
 
414
    def fix_root(self):
 
415
        try:
 
416
            self.tt.final_kind(self.tt.root)
 
417
        except NoSuchFile:
 
418
            self.tt.cancel_deletion(self.tt.root)
 
419
        if self.tt.final_file_id(self.tt.root) is None:
 
420
            self.tt.version_file(self.tt.tree_file_id(self.tt.root), 
 
421
                                 self.tt.root)
 
422
        if self.other_tree.inventory.root is None:
 
423
            return
 
424
        other_root_file_id = self.other_tree.inventory.root.file_id
 
425
        other_root = self.tt.trans_id_file_id(other_root_file_id)
 
426
        if other_root == self.tt.root:
 
427
            return
 
428
        try:
 
429
            self.tt.final_kind(other_root)
 
430
        except NoSuchFile:
 
431
            return
 
432
        self.reparent_children(self.other_tree.inventory.root, self.tt.root)
 
433
        self.tt.cancel_creation(other_root)
 
434
        self.tt.cancel_versioning(other_root)
 
435
 
 
436
    def reparent_children(self, ie, target):
 
437
        for thing, child in ie.children.iteritems():
 
438
            trans_id = self.tt.trans_id_file_id(child.file_id)
 
439
            self.tt.adjust_path(self.tt.final_name(trans_id), target, trans_id)
 
440
 
411
441
    def write_modified(self, results):
412
442
        modified_hashes = {}
413
443
        for path in results.modified_paths:
518
548
                        "conflict": other_entry}
519
549
        trans_id = self.tt.trans_id_file_id(file_id)
520
550
        parent_id = winner_entry[parent_id_winner].parent_id
521
 
        parent_trans_id = self.tt.trans_id_file_id(parent_id)
522
 
        self.tt.adjust_path(winner_entry[name_winner].name, parent_trans_id,
523
 
                            trans_id)
 
551
        if parent_id is not None:
 
552
            parent_trans_id = self.tt.trans_id_file_id(parent_id)
 
553
            self.tt.adjust_path(winner_entry[name_winner].name, 
 
554
                                parent_trans_id, trans_id)
524
555
 
525
556
    def merge_contents(self, file_id):
526
557
        """Performa a merge on file_id contents."""
868
899
        will be dumped, and a will be conflict noted.
869
900
        """
870
901
        import bzrlib.patch
871
 
        temp_dir = mkdtemp(prefix="bzr-")
 
902
        temp_dir = osutils.mkdtemp(prefix="bzr-")
872
903
        try:
873
904
            new_file = pathjoin(temp_dir, "new")
874
905
            this = self.dump_file(temp_dir, "this", self.this_tree, file_id)
886
917
                name = self.tt.final_name(trans_id)
887
918
                parent_id = self.tt.final_parent(trans_id)
888
919
                self._dump_conflicts(name, parent_id, file_id)
889
 
            self._raw_conflicts.append(('text conflict', trans_id))
 
920
                self._raw_conflicts.append(('text conflict', trans_id))
890
921
        finally:
891
 
            rmtree(temp_dir)
 
922
            osutils.rmtree(temp_dir)
892
923
 
893
924
 
894
925
def merge_inner(this_branch, other_tree, base_tree, ignore_zero=False,