~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-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

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
 
from bzrlib.delta import compare_trees
26
27
from bzrlib.errors import (BzrCommandError,
27
28
                           BzrError,
28
29
                           NoCommonAncestor,
38
39
                           )
39
40
from bzrlib.merge3 import Merge3
40
41
import bzrlib.osutils
41
 
from bzrlib.osutils import rename, pathjoin, rmtree
 
42
from bzrlib.osutils import rename, pathjoin
42
43
from progress import DummyProgress, ProgressPhase
43
44
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
44
45
from bzrlib.textfile import check_text_lines
51
52
# TODO: Report back as changes are merged in
52
53
 
53
54
def _get_tree(treespec, local_branch=None):
 
55
    from bzrlib import workingtree
54
56
    location, revno = treespec
 
57
    if revno is None:
 
58
        tree = workingtree.WorkingTree.open_containing(location)[0]
 
59
        return tree.branch, tree
55
60
    branch = Branch.open_containing(location)[0]
56
 
    if revno is None:
57
 
        revision = None
58
 
    elif revno == -1:
 
61
    if revno == -1:
59
62
        revision = branch.last_revision()
60
63
    else:
61
64
        revision = branch.get_rev_id(revno)
116
119
 
117
120
        if self.other_rev_id is None:
118
121
            other_basis_tree = self.revision_tree(self.other_basis)
119
 
            changes = compare_trees(self.other_tree, other_basis_tree)
 
122
            changes = other_basis_tree.changes_from(self.other_tree)
120
123
            if changes.has_changed():
121
124
                raise WorkingTreeNotRevision(self.this_tree)
122
125
            other_rev_id = self.other_basis
145
148
                raise BzrCommandError("Working tree has uncommitted changes.")
146
149
 
147
150
    def compare_basis(self):
148
 
        changes = compare_trees(self.this_tree, 
149
 
                                self.this_tree.basis_tree(), False)
 
151
        changes = self.this_tree.changes_from(self.this_tree.basis_tree())
150
152
        if not changes.has_changed():
151
153
            self.this_rev_id = self.this_basis
152
154
 
183
185
        ancestry = self.this_branch.repository.get_ancestry(self.this_basis)
184
186
        if self.other_rev_id in ancestry:
185
187
            return
186
 
        self.this_tree.add_pending_merge(self.other_rev_id)
 
188
        self.this_tree.add_parent_tree((self.other_rev_id, self.other_tree))
187
189
 
188
190
    def set_other(self, other_revision):
189
 
        other_branch, self.other_tree = _get_tree(other_revision, 
 
191
        """Set the revision and tree to merge from.
 
192
 
 
193
        This sets the other_tree, other_rev_id, other_basis attributes.
 
194
 
 
195
        :param other_revision: The [path, revision] list to merge from.
 
196
        """
 
197
        other_branch, self.other_tree = _get_tree(other_revision,
190
198
                                                  self.this_branch)
191
199
        if other_revision[1] == -1:
192
200
            self.other_rev_id = other_branch.last_revision()
208
216
        self.set_base([None, None])
209
217
 
210
218
    def set_base(self, base_revision):
 
219
        """Set the base revision to use for the merge.
 
220
 
 
221
        :param base_revision: A 2-list containing a path and revision number.
 
222
        """
211
223
        mutter("doing merge() with no base_revision specified")
212
224
        if base_revision == [None, None]:
213
225
            try:
518
530
            if file_id not in tree:
519
531
                return (None, None)
520
532
            kind = tree.kind(file_id)
521
 
            if kind == "root_directory":
522
 
                kind = "directory"
523
533
            if kind == "file":
524
534
                contents = tree.get_file_sha1(file_id)
525
535
            elif kind == "symlink":
860
870
        will be dumped, and a will be conflict noted.
861
871
        """
862
872
        import bzrlib.patch
863
 
        temp_dir = mkdtemp(prefix="bzr-")
 
873
        temp_dir = osutils.mkdtemp(prefix="bzr-")
864
874
        try:
865
875
            new_file = pathjoin(temp_dir, "new")
866
876
            this = self.dump_file(temp_dir, "this", self.this_tree, file_id)
878
888
                name = self.tt.final_name(trans_id)
879
889
                parent_id = self.tt.final_parent(trans_id)
880
890
                self._dump_conflicts(name, parent_id, file_id)
881
 
            self._raw_conflicts.append(('text conflict', trans_id))
 
891
                self._raw_conflicts.append(('text conflict', trans_id))
882
892
        finally:
883
 
            rmtree(temp_dir)
 
893
            osutils.rmtree(temp_dir)
884
894
 
885
895
 
886
896
def merge_inner(this_branch, other_tree, base_tree, ignore_zero=False,
915
925
        assert not interesting_ids, ('Only supply interesting_ids'
916
926
                                     ' or interesting_files')
917
927
        merger._set_interesting_files(interesting_files)
918
 
    merger.show_base = show_base 
 
928
    merger.show_base = show_base
919
929
    merger.reprocess = reprocess
920
930
    merger.other_rev_id = other_rev_id
921
931
    merger.other_basis = other_rev_id