~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
 
26
26
import bzrlib
27
 
import bzrlib.inventory as inventory
28
27
from bzrlib.trace import mutter, note
29
28
from bzrlib.osutils import (isdir, quotefn,
30
29
                            rename, splitpath, sha_file, appendpath, 
38
37
from bzrlib.textui import show_status
39
38
from bzrlib.config import TreeConfig
40
39
from bzrlib.delta import compare_trees
41
 
from bzrlib.tree import EmptyTree, RevisionTree
 
40
import bzrlib.inventory as inventory
42
41
from bzrlib.inventory import Inventory
43
42
from bzrlib.lockable_files import LockableFiles
44
43
from bzrlib.revision import (Revision, is_ancestor, get_intervening_revisions)
46
45
from bzrlib.store import copy_all
47
46
import bzrlib.transactions as transactions
48
47
from bzrlib.transport import Transport, get_transport
 
48
from bzrlib.tree import EmptyTree, RevisionTree
49
49
import bzrlib.ui
50
50
import bzrlib.xml5
51
51
 
141
141
    @staticmethod
142
142
    def initialize(base):
143
143
        """Create a new branch, rooted at 'base' (url)"""
144
 
        t = get_transport(base)
 
144
        t = get_transport(unicode(base))
145
145
        return BzrBranch(t, init=True)
146
146
 
147
147
    def setup_caching(self, cache_root):
186
186
        """Return the id of this branches root"""
187
187
        raise NotImplementedError('get_root_id is abstract')
188
188
 
189
 
    def print_file(self, file, revno):
 
189
    def print_file(self, file, revision_id):
190
190
        """Print `file` to stdout."""
191
191
        raise NotImplementedError('print_file is abstract')
192
192
 
402
402
        if revision is None:
403
403
            revision = self.last_revision()
404
404
        br_to.update_revisions(self, stop_revision=revision)
405
 
        from bzrlib.merge import build_working_dir
406
 
        build_working_dir(to_location)
407
405
        br_to.set_parent(self.base)
 
406
        # circular import protection
 
407
        from bzrlib.merge import build_working_dir
 
408
        build_working_dir(to_location)
408
409
        mutter("copied")
409
410
        return br_to
410
411
 
411
 
class BzrBranch(Branch, LockableFiles):
 
412
class BzrBranch(Branch):
412
413
    """A branch stored in the actual filesystem.
413
414
 
414
415
    Note that it's "local" in the context of the filesystem; it doesn't
612
613
        self.control_files.unlock()
613
614
 
614
615
    @needs_read_lock
615
 
    def print_file(self, file, revno):
 
616
    def print_file(self, file, revision_id):
616
617
        """See Branch.print_file."""
617
 
        return self.storage.print_file(file, self.get_rev_id(revno))
 
618
        return self.storage.print_file(file, revision_id)
618
619
 
619
620
    @needs_write_lock
620
621
    def append_revision(self, *revision_ids):
628
629
    @needs_write_lock
629
630
    def set_revision_history(self, rev_history):
630
631
        """See Branch.set_revision_history."""
 
632
        old_revision = self.last_revision()
 
633
        new_revision = rev_history[-1]
631
634
        self.control_files.put_utf8(
632
635
            'revision-history', '\n'.join(rev_history))
 
636
        try:
 
637
            # FIXME: RBC 20051207 this smells wrong, last_revision in the 
 
638
            # working tree may be != to last_revision in the branch - so
 
639
            # why is this passing in the branches last_revision ?
 
640
            self.working_tree().set_last_revision(new_revision, old_revision)
 
641
        except NoWorkingTree:
 
642
            mutter('Unable to set_last_revision without a working tree.')
 
643
 
633
644
 
634
645
    def get_revision_delta(self, revno):
635
646
        """Return the delta for one revision.
701
712
                else:
702
713
                    raise e
703
714
        
 
715
    def basis_tree(self):
 
716
        """See Branch.basis_tree."""
 
717
        try:
 
718
            revision_id = self.revision_history()[-1]
 
719
            # FIXME: This is an abstraction violation, the basis tree 
 
720
            # here as defined is on the working tree, the method should
 
721
            # be too. The basis tree for a branch can be different than
 
722
            # that for a working tree. RBC 20051207
 
723
            xml = self.working_tree().read_basis_inventory(revision_id)
 
724
            inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
 
725
            return RevisionTree(self.storage.weave_store, inv, revision_id)
 
726
        except (IndexError, NoSuchFile, NoWorkingTree), e:
 
727
            return self.storage.revision_tree(self.last_revision())
 
728
 
704
729
    def working_tree(self):
705
730
        """See Branch.working_tree."""
706
731
        from bzrlib.workingtree import WorkingTree
719
744
            except DivergedBranches:
720
745
                if not overwrite:
721
746
                    raise
 
747
            if overwrite:
722
748
                self.set_revision_history(source.revision_history())
723
749
            new_count = len(self.revision_history())
724
750
            return new_count - old_count
732
758
        for l in _locs:
733
759
            try:
734
760
                return self.control_files.controlfile(l, 'r').read().strip('\n')
735
 
            except IOError, e:
736
 
                if e.errno != errno.ENOENT:
737
 
                    raise
 
761
            except NoSuchFile:
 
762
                pass
738
763
        return None
739
764
 
740
765
    def get_push_location(self):
785
810
        branch_to = Branch.initialize(to_location)
786
811
        mutter("copy branch from %s to %s", self, branch_to)
787
812
        branch_to.working_tree().set_root_id(self.get_root_id())
788
 
        branch_to.set_revision_history(history)
789
813
 
790
814
        self.storage.copy(branch_to.storage)
791
815
        
792
 
        from bzrlib.merge import build_working_dir
793
 
        build_working_dir(to_location)
 
816
        # must be done *after* history is copied across
 
817
        # FIXME duplicate code with base .clone().
 
818
        # .. would template method be useful here.  RBC 20051207
794
819
        branch_to.set_parent(self.base)
 
820
        branch_to.append_revision(*history)
 
821
        # circular import protection
 
822
        from bzrlib.merge import build_working_dir
 
823
        build_working_dir(to_location)
795
824
        mutter("copied")
796
825
        return branch_to
797
826