~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Aaron Bentley
  • Date: 2006-05-30 15:53:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: abentley@panoramicfeedback.com-20060530155333-2fd164d1cdf2afc3
Move BadBundle error (and subclasses) to errors.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
import os
19
19
import errno
20
20
from tempfile import mkdtemp
21
 
import warnings
22
21
 
 
22
import bzrlib
23
23
from bzrlib.branch import Branch
24
24
from bzrlib.conflicts import ConflictList, Conflict
 
25
from bzrlib.delta import compare_trees
25
26
from bzrlib.errors import (BzrCommandError,
26
27
                           BzrError,
27
28
                           NoCommonAncestor,
40
41
from bzrlib.osutils import rename, pathjoin, rmtree
41
42
from progress import DummyProgress, ProgressPhase
42
43
from bzrlib.revision import common_ancestor, is_ancestor, NULL_REVISION
 
44
from bzrlib.symbol_versioning import *
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
48
                              FinalPaths, create_by_entry, unique_add)
47
49
from bzrlib.versionedfile import WeaveMerge
48
 
from bzrlib import ui
 
50
import bzrlib.ui
49
51
 
50
52
# TODO: Report back as changes are merged in
51
53
 
52
54
def _get_tree(treespec, local_branch=None):
53
 
    from bzrlib import workingtree
54
55
    location, revno = treespec
 
56
    branch = Branch.open_containing(location)[0]
55
57
    if revno is None:
56
 
        tree = workingtree.WorkingTree.open_containing(location)[0]
57
 
        return tree.branch, tree
58
 
    branch = Branch.open_containing(location)[0]
59
 
    if revno == -1:
 
58
        revision = None
 
59
    elif revno == -1:
60
60
        revision = branch.last_revision()
61
61
    else:
62
62
        revision = branch.get_rev_id(revno)
117
117
 
118
118
        if self.other_rev_id is None:
119
119
            other_basis_tree = self.revision_tree(self.other_basis)
120
 
            changes = other_basis_tree.changes_from(self.other_tree)
 
120
            changes = compare_trees(self.other_tree, other_basis_tree)
121
121
            if changes.has_changed():
122
122
                raise WorkingTreeNotRevision(self.this_tree)
123
 
            other_rev_id = self.other_basis
 
123
            other_rev_id = other_basis
124
124
            self.other_tree = other_basis_tree
125
125
 
126
126
    def file_revisions(self, file_id):
146
146
                raise BzrCommandError("Working tree has uncommitted changes.")
147
147
 
148
148
    def compare_basis(self):
149
 
        changes = self.this_tree.changes_from(self.this_tree.basis_tree())
 
149
        changes = compare_trees(self.this_tree, 
 
150
                                self.this_tree.basis_tree(), False)
150
151
        if not changes.has_changed():
151
152
            self.this_rev_id = self.this_basis
152
153
 
367
368
        self.tt = TreeTransform(working_tree, self.pb)
368
369
        try:
369
370
            self.pp.next_phase()
370
 
            child_pb = ui.ui_factory.nested_progress_bar()
 
371
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
371
372
            try:
372
373
                for num, file_id in enumerate(all_ids):
373
374
                    child_pb.update('Preparing file merge', num, len(all_ids))
378
379
                child_pb.finished()
379
380
                
380
381
            self.pp.next_phase()
381
 
            child_pb = ui.ui_factory.nested_progress_bar()
 
382
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
382
383
            try:
383
384
                fs_conflicts = resolve_conflicts(self.tt, child_pb)
384
385
            finally:
390
391
            results = self.tt.apply()
391
392
            self.write_modified(results)
392
393
            try:
393
 
                working_tree.add_conflicts(self.cooked_conflicts)
 
394
                working_tree.set_conflicts(ConflictList(self.cooked_conflicts))
394
395
            except UnsupportedOperation:
395
396
                pass
396
397
        finally:
397
 
            self.tt.finalize()
 
398
            try:
 
399
                self.tt.finalize()
 
400
            except:
 
401
                pass
398
402
            working_tree.unlock()
399
403
            self.pb.clear()
400
404
 
518
522
            if file_id not in tree:
519
523
                return (None, None)
520
524
            kind = tree.kind(file_id)
 
525
            if kind == "root_directory":
 
526
                kind = "directory"
521
527
            if kind == "file":
522
528
                contents = tree.get_file_sha1(file_id)
523
529
            elif kind == "symlink":
688
694
        if winner == "conflict":
689
695
        # There must be a None in here, if we have a conflict, but we
690
696
        # need executability since file status was not deleted.
691
 
            if self.executable(self.other_tree, file_id) is None:
 
697
            if self.other_tree.is_executable(file_id) is None:
692
698
                winner = "this"
693
699
            else:
694
700
                winner = "other"
786
792
                                          pb=pb, pp=pp, reprocess=reprocess)
787
793
 
788
794
    def _get_revision_tree(self, tree):
789
 
        """Return a revision tree related to this tree.
 
795
        """Return a revision tree releated to this tree.
790
796
        If the tree is a WorkingTree, the basis will be returned.
791
797
        """
792
798
        if getattr(tree, 'get_weave', False) is False:
840
846
 
841
847
class Diff3Merger(Merge3Merger):
842
848
    """Three-way merger using external diff3 for text merging"""
843
 
 
844
849
    def dump_file(self, temp_dir, name, tree, file_id):
845
850
        out_path = pathjoin(temp_dir, name)
846
 
        out_file = open(out_path, "wb")
847
 
        try:
848
 
            in_file = tree.get_file(file_id)
849
 
            for line in in_file:
850
 
                out_file.write(line)
851
 
        finally:
852
 
            out_file.close()
 
851
        out_file = file(out_path, "wb")
 
852
        in_file = tree.get_file(file_id)
 
853
        for line in in_file:
 
854
            out_file.write(line)
853
855
        return out_path
854
856
 
855
857
    def text_merge(self, file_id, trans_id):
867
869
            status = bzrlib.patch.diff3(new_file, this, base, other)
868
870
            if status not in (0, 1):
869
871
                raise BzrError("Unhandled diff3 exit code")
870
 
            f = open(new_file, 'rb')
871
 
            try:
872
 
                self.tt.create_file(f, trans_id)
873
 
            finally:
874
 
                f.close()
 
872
            self.tt.create_file(file(new_file, "rb"), trans_id)
875
873
            if status == 1:
876
874
                name = self.tt.final_name(trans_id)
877
875
                parent_id = self.tt.final_parent(trans_id)
898
896
                     branch.get_revision_tree(base_revision))'
899
897
        """
900
898
    if this_tree is None:
901
 
        warnings.warn("bzrlib.merge.merge_inner requires a this_tree parameter as of "
 
899
        warn("bzrlib.merge.merge_inner requires a this_tree parameter as of "
902
900
             "bzrlib version 0.8.",
903
901
             DeprecationWarning,
904
902
             stacklevel=2)