~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge from mbp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
236
236
    def set_root_id(self, file_id):
237
237
        raise NotImplementedError('set_root_id is abstract')
238
238
 
239
 
    def print_file(self, file, revno):
 
239
    def print_file(self, file, revision_id):
240
240
        """Print `file` to stdout."""
241
241
        raise NotImplementedError('print_file is abstract')
242
242
 
355
355
        >>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
356
356
        >>> br1.missing_revisions(br2)
357
357
        Traceback (most recent call last):
358
 
        DivergedBranches: These branches have diverged.
 
358
        DivergedBranches: These branches have diverged.  Try merge.
359
359
        """
360
360
        self_history = self.revision_history()
361
361
        self_len = len(self_history)
568
568
            # or entirely uncompressed is tidy, but breaks upgrade from 
569
569
            # some existing branches where there's a mixture; we probably 
570
570
            # still want the option to look for both.
571
 
            relpath = self._rel_controlfilename(name)
 
571
            relpath = self._rel_controlfilename(unicode(name))
572
572
            store = TextStore(self._transport.clone(relpath),
573
573
                              prefixed=prefixed,
574
574
                              compressed=compressed)
577
577
            #    os.mkdir(cache_path)
578
578
            #    store = bzrlib.store.CachedStore(store, cache_path)
579
579
            return store
 
580
 
580
581
        def get_weave(name, prefixed=False):
581
 
            relpath = self._rel_controlfilename(name)
 
582
            relpath = self._rel_controlfilename(unicode(name))
582
583
            ws = WeaveStore(self._transport.clone(relpath), prefixed=prefixed)
583
584
            if self._transport.should_cache():
584
585
                ws.enable_cache = True
585
586
            return ws
586
587
 
587
588
        if self._branch_format == 4:
588
 
            self.inventory_store = get_store(u'inventory-store')
589
 
            self.text_store = get_store(u'text-store')
590
 
            self.revision_store = get_store(u'revision-store')
 
589
            self.inventory_store = get_store('inventory-store')
 
590
            self.text_store = get_store('text-store')
 
591
            self.revision_store = get_store('revision-store')
591
592
        elif self._branch_format == 5:
592
593
            self.control_weaves = get_weave(u'')
593
594
            self.weave_store = get_weave(u'weaves')
656
657
        self._transaction = new_transaction
657
658
 
658
659
    def lock_write(self):
659
 
        mutter("lock write: %s (%s)", self, self._lock_count)
 
660
        #mutter("lock write: %s (%s)", self, self._lock_count)
660
661
        # TODO: Upgrade locking to support using a Transport,
661
662
        # and potentially a remote locking protocol
662
663
        if self._lock_mode:
672
673
            self._set_transaction(transactions.PassThroughTransaction())
673
674
 
674
675
    def lock_read(self):
675
 
        mutter("lock read: %s (%s)", self, self._lock_count)
 
676
        #mutter("lock read: %s (%s)", self, self._lock_count)
676
677
        if self._lock_mode:
677
678
            assert self._lock_mode in ('r', 'w'), \
678
679
                   "invalid lock mode %r" % self._lock_mode
687
688
            self.get_transaction().set_cache_size(5000)
688
689
                        
689
690
    def unlock(self):
690
 
        mutter("unlock: %s (%s)", self, self._lock_count)
 
691
        #mutter("unlock: %s (%s)", self, self._lock_count)
691
692
        if not self._lock_mode:
692
693
            raise LockError('branch %r is not locked' % (self))
693
694
 
824
825
        return inv.root.file_id
825
826
 
826
827
    @needs_read_lock
827
 
    def print_file(self, file, revno):
 
828
    def print_file(self, file, revision_id):
828
829
        """See Branch.print_file."""
829
 
        tree = self.revision_tree(self.get_rev_id(revno))
 
830
        tree = self.revision_tree(revision_id)
830
831
        # use inventory as it was in that revision
831
832
        file_id = tree.inventory.path2id(file)
832
833
        if not file_id:
833
 
            raise BzrError("%r is not present in revision %s" % (file, revno))
 
834
            try:
 
835
                revno = self.revision_id_to_revno(revision_id)
 
836
            except errors.NoSuchRevision:
 
837
                # TODO: This should not be BzrError,
 
838
                # but NoSuchFile doesn't fit either
 
839
                raise BzrError('%r is not present in revision %s' 
 
840
                                % (file, revision_id))
 
841
            else:
 
842
                raise BzrError('%r is not present in revision %s'
 
843
                                % (file, revno))
834
844
        tree.print_file(file_id)
835
845
 
836
846
    @needs_write_lock
848
858
        old_revision = self.last_revision()
849
859
        new_revision = rev_history[-1]
850
860
        self.put_controlfile('revision-history', '\n'.join(rev_history))
851
 
        self.working_tree().set_last_revision(new_revision, old_revision)
 
861
        try:
 
862
            self.working_tree().set_last_revision(new_revision, old_revision)
 
863
        except NoWorkingTree:
 
864
            mutter('Unable to set_last_revision without a working tree.')
852
865
 
853
866
    def has_revision(self, revision_id):
854
867
        """See Branch.has_revision."""
1002
1015
            xml = self.working_tree().read_basis_inventory(revision_id)
1003
1016
            inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(xml)
1004
1017
            return RevisionTree(self.weave_store, inv, revision_id)
1005
 
        except (IndexError, NoSuchFile), e:
 
1018
        except (IndexError, NoSuchFile, NoWorkingTree), e:
1006
1019
            return self.revision_tree(self.last_revision())
1007
1020
 
1008
1021
    def working_tree(self):
1023
1036
            except DivergedBranches:
1024
1037
                if not overwrite:
1025
1038
                    raise
 
1039
            if overwrite:
1026
1040
                self.set_revision_history(source.revision_history())
1027
1041
            new_count = len(self.revision_history())
1028
1042
            return new_count - old_count
1036
1050
        for l in _locs:
1037
1051
            try:
1038
1052
                return self.controlfile(l, 'r').read().strip('\n')
1039
 
            except IOError, e:
1040
 
                if e.errno != errno.ENOENT:
1041
 
                    raise
 
1053
            except NoSuchFile:
 
1054
                pass
1042
1055
        return None
1043
1056
 
1044
1057
    def get_push_location(self):