~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

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
20
21
import warnings
21
22
 
22
 
from bzrlib import (
23
 
    osutils,
24
 
    )
25
23
from bzrlib.branch import Branch
26
24
from bzrlib.conflicts import ConflictList, Conflict
27
25
from bzrlib.errors import (BzrCommandError,
39
37
                           )
40
38
from bzrlib.merge3 import Merge3
41
39
import bzrlib.osutils
42
 
from bzrlib.osutils import rename, pathjoin
 
40
from bzrlib.osutils import rename, pathjoin, rmtree
43
41
from progress import DummyProgress, ProgressPhase
44
42
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
45
43
from bzrlib.textfile import check_text_lines
46
44
from bzrlib.trace import mutter, warning, note
47
45
from bzrlib.transform import (TreeTransform, resolve_conflicts, cook_conflicts,
48
 
                              FinalPaths, create_by_entry, unique_add,
49
 
                              ROOT_PARENT)
 
46
                              FinalPaths, create_by_entry, unique_add)
50
47
from bzrlib.versionedfile import WeaveMerge
51
48
from bzrlib import ui
52
49
 
186
183
        ancestry = self.this_branch.repository.get_ancestry(self.this_basis)
187
184
        if self.other_rev_id in ancestry:
188
185
            return
189
 
        self.this_tree.add_parent_tree((self.other_rev_id, self.other_tree))
 
186
        self.this_tree.add_pending_merge(self.other_rev_id)
190
187
 
191
188
    def set_other(self, other_revision):
192
 
        """Set the revision and tree to merge from.
193
 
 
194
 
        This sets the other_tree, other_rev_id, other_basis attributes.
195
 
 
196
 
        :param other_revision: The [path, revision] list to merge from.
197
 
        """
198
 
        other_branch, self.other_tree = _get_tree(other_revision,
 
189
        other_branch, self.other_tree = _get_tree(other_revision, 
199
190
                                                  self.this_branch)
200
191
        if other_revision[1] == -1:
201
192
            self.other_rev_id = other_branch.last_revision()
217
208
        self.set_base([None, None])
218
209
 
219
210
    def set_base(self, base_revision):
220
 
        """Set the base revision to use for the merge.
221
 
 
222
 
        :param base_revision: A 2-list containing a path and revision number.
223
 
        """
224
211
        mutter("doing merge() with no base_revision specified")
225
212
        if base_revision == [None, None]:
226
213
            try:
376
363
        else:
377
364
            all_ids = set(base_tree)
378
365
            all_ids.update(other_tree)
379
 
        working_tree.lock_tree_write()
 
366
        working_tree.lock_write()
380
367
        self.tt = TreeTransform(working_tree, self.pb)
381
368
        try:
382
369
            self.pp.next_phase()
389
376
                    self.merge_executable(file_id, file_status)
390
377
            finally:
391
378
                child_pb.finished()
392
 
            self.fix_root()
 
379
                
393
380
            self.pp.next_phase()
394
381
            child_pb = ui.ui_factory.nested_progress_bar()
395
382
            try:
411
398
            working_tree.unlock()
412
399
            self.pb.clear()
413
400
 
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
 
 
441
401
    def write_modified(self, results):
442
402
        modified_hashes = {}
443
403
        for path in results.modified_paths:
548
508
                        "conflict": other_entry}
549
509
        trans_id = self.tt.trans_id_file_id(file_id)
550
510
        parent_id = winner_entry[parent_id_winner].parent_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)
 
511
        parent_trans_id = self.tt.trans_id_file_id(parent_id)
 
512
        self.tt.adjust_path(winner_entry[name_winner].name, parent_trans_id,
 
513
                            trans_id)
555
514
 
556
515
    def merge_contents(self, file_id):
557
516
        """Performa a merge on file_id contents."""
899
858
        will be dumped, and a will be conflict noted.
900
859
        """
901
860
        import bzrlib.patch
902
 
        temp_dir = osutils.mkdtemp(prefix="bzr-")
 
861
        temp_dir = mkdtemp(prefix="bzr-")
903
862
        try:
904
863
            new_file = pathjoin(temp_dir, "new")
905
864
            this = self.dump_file(temp_dir, "this", self.this_tree, file_id)
917
876
                name = self.tt.final_name(trans_id)
918
877
                parent_id = self.tt.final_parent(trans_id)
919
878
                self._dump_conflicts(name, parent_id, file_id)
920
 
                self._raw_conflicts.append(('text conflict', trans_id))
 
879
            self._raw_conflicts.append(('text conflict', trans_id))
921
880
        finally:
922
 
            osutils.rmtree(temp_dir)
 
881
            rmtree(temp_dir)
923
882
 
924
883
 
925
884
def merge_inner(this_branch, other_tree, base_tree, ignore_zero=False,
954
913
        assert not interesting_ids, ('Only supply interesting_ids'
955
914
                                     ' or interesting_files')
956
915
        merger._set_interesting_files(interesting_files)
957
 
    merger.show_base = show_base
 
916
    merger.show_base = show_base 
958
917
    merger.reprocess = reprocess
959
918
    merger.other_rev_id = other_rev_id
960
919
    merger.other_basis = other_rev_id