/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Jan Balster
  • Date: 2006-08-15 12:39:42 UTC
  • mfrom: (1923 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1928.
  • Revision ID: jan@merlinux.de-20060815123942-22c388c6e9a8ac91
merge bzr.dev 1923

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib.branch import Branch
24
24
from bzrlib.conflicts import ConflictList, Conflict
25
 
from bzrlib.delta import compare_trees
26
25
from bzrlib.errors import (BzrCommandError,
27
26
                           BzrError,
28
27
                           NoCommonAncestor,
51
50
# TODO: Report back as changes are merged in
52
51
 
53
52
def _get_tree(treespec, local_branch=None):
 
53
    from bzrlib import workingtree
54
54
    location, revno = treespec
 
55
    if revno is None:
 
56
        tree = workingtree.WorkingTree.open_containing(location)[0]
 
57
        return tree.branch, tree
55
58
    branch = Branch.open_containing(location)[0]
56
 
    if revno is None:
57
 
        revision = None
58
 
    elif revno == -1:
 
59
    if revno == -1:
59
60
        revision = branch.last_revision()
60
61
    else:
61
62
        revision = branch.get_rev_id(revno)
116
117
 
117
118
        if self.other_rev_id is None:
118
119
            other_basis_tree = self.revision_tree(self.other_basis)
119
 
            changes = compare_trees(self.other_tree, other_basis_tree)
 
120
            changes = other_basis_tree.changes_from(self.other_tree)
120
121
            if changes.has_changed():
121
122
                raise WorkingTreeNotRevision(self.this_tree)
122
123
            other_rev_id = self.other_basis
145
146
                raise BzrCommandError("Working tree has uncommitted changes.")
146
147
 
147
148
    def compare_basis(self):
148
 
        changes = compare_trees(self.this_tree, 
149
 
                                self.this_tree.basis_tree(), False)
 
149
        changes = self.this_tree.changes_from(self.this_tree.basis_tree())
150
150
        if not changes.has_changed():
151
151
            self.this_rev_id = self.this_basis
152
152
 
390
390
            results = self.tt.apply()
391
391
            self.write_modified(results)
392
392
            try:
393
 
                working_tree.set_conflicts(ConflictList(self.cooked_conflicts))
 
393
                working_tree.add_conflicts(self.cooked_conflicts)
394
394
            except UnsupportedOperation:
395
395
                pass
396
396
        finally:
397
 
            try:
398
 
                self.tt.finalize()
399
 
            except:
400
 
                pass
 
397
            self.tt.finalize()
401
398
            working_tree.unlock()
402
399
            self.pb.clear()
403
400
 
521
518
            if file_id not in tree:
522
519
                return (None, None)
523
520
            kind = tree.kind(file_id)
524
 
            if kind == "root_directory":
525
 
                kind = "directory"
526
521
            if kind == "file":
527
522
                contents = tree.get_file_sha1(file_id)
528
523
            elif kind == "symlink":
693
688
        if winner == "conflict":
694
689
        # There must be a None in here, if we have a conflict, but we
695
690
        # need executability since file status was not deleted.
696
 
            if self.other_tree.is_executable(file_id) is None:
 
691
            if self.executable(self.other_tree, file_id) is None:
697
692
                winner = "this"
698
693
            else:
699
694
                winner = "other"
845
840
 
846
841
class Diff3Merger(Merge3Merger):
847
842
    """Three-way merger using external diff3 for text merging"""
 
843
 
848
844
    def dump_file(self, temp_dir, name, tree, file_id):
849
845
        out_path = pathjoin(temp_dir, name)
850
 
        out_file = file(out_path, "wb")
851
 
        in_file = tree.get_file(file_id)
852
 
        for line in in_file:
853
 
            out_file.write(line)
 
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()
854
853
        return out_path
855
854
 
856
855
    def text_merge(self, file_id, trans_id):
868
867
            status = bzrlib.patch.diff3(new_file, this, base, other)
869
868
            if status not in (0, 1):
870
869
                raise BzrError("Unhandled diff3 exit code")
871
 
            self.tt.create_file(file(new_file, "rb"), trans_id)
 
870
            f = open(new_file, 'rb')
 
871
            try:
 
872
                self.tt.create_file(f, trans_id)
 
873
            finally:
 
874
                f.close()
872
875
            if status == 1:
873
876
                name = self.tt.final_name(trans_id)
874
877
                parent_id = self.tt.final_parent(trans_id)