~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Robert Collins
  • Date: 2006-03-03 07:00:50 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060303070050-5219f1cd68b5e6b9
Add add_revision and get_revision methods to RevisionStore

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        """Construct the current default format repository in a_bzrdir."""
94
94
        return RepositoryFormat.get_default_format().initialize(a_bzrdir)
95
95
 
96
 
    def __init__(self, _format, a_bzrdir, control_files, revision_store, text_store):
 
96
    def __init__(self, _format, a_bzrdir, control_files, revision_store, control_store, text_store):
97
97
        """instantiate a Repository.
98
98
 
99
99
        :param _format: The format of the repository on disk.
114
114
        self.text_store = text_store
115
115
        # backwards compatability
116
116
        self.weave_store = text_store
 
117
        # not right yet - should be more semantically clear ? 
 
118
        # 
 
119
        self.control_store = control_store
 
120
        self.control_weaves = control_store
117
121
 
118
122
    def lock_write(self):
119
123
        self.control_files.lock_write()
204
208
    @needs_read_lock
205
209
    def get_revision(self, revision_id):
206
210
        """Return the Revision object for a named revision"""
207
 
        xml_file = self.get_revision_xml_file(revision_id)
208
 
 
209
 
        try:
210
 
            r = bzrlib.xml5.serializer_v5.read_revision(xml_file)
211
 
        except SyntaxError, e:
212
 
            raise bzrlib.errors.BzrError('failed to unpack revision_xml',
213
 
                                         [revision_id,
214
 
                                          str(e)])
215
 
            
216
 
        assert r.revision_id == revision_id
217
 
        return r
218
 
 
219
 
    @needs_read_lock
220
 
    def get_revision_sha1(self, revision_id):
221
 
        """Hash the stored value of a revision, and return it."""
222
 
        # In the future, revision entries will be signed. At that
223
 
        # point, it is probably best *not* to include the signature
224
 
        # in the revision hash. Because that lets you re-sign
225
 
        # the revision, (add signatures/remove signatures) and still
226
 
        # have all hash pointers stay consistent.
227
 
        # But for now, just hash the contents.
228
 
        return bzrlib.osutils.sha_file(self.get_revision_xml_file(revision_id))
 
211
        if not revision_id or not isinstance(revision_id, basestring):
 
212
            raise InvalidRevisionId(revision_id=revision_id, branch=self)
 
213
        return self._revision_store.get_revision(revision_id,
 
214
                                                 self.get_transaction())
229
215
 
230
216
    @needs_write_lock
231
217
    def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
467
453
class AllInOneRepository(Repository):
468
454
    """Legacy support - the repository behaviour for all-in-one branches."""
469
455
 
470
 
    def __init__(self, _format, a_bzrdir, revision_store, text_store):
 
456
    def __init__(self, _format, a_bzrdir, revision_store, control_store, text_store):
471
457
        # we reuse one control files instance.
472
458
        dir_mode = a_bzrdir._control_files._dir_mode
473
459
        file_mode = a_bzrdir._control_files._file_mode
505
491
        # not broken out yet because the controlweaves|inventory_store
506
492
        # and text_store | weave_store bits are still different.
507
493
        if isinstance(_format, RepositoryFormat4):
 
494
            # cannot remove these - there is still no consistent api 
 
495
            # which allows access to this old info.
508
496
            self.inventory_store = get_store('inventory-store')
509
497
            text_store = get_store('text-store')
510
 
        elif isinstance(_format, RepositoryFormat5):
511
 
            self.control_weaves = get_weave('')
512
 
        elif isinstance(_format, RepositoryFormat6):
513
 
            self.control_weaves = get_weave('')
514
 
        else:
515
 
            raise errors.BzrError('unreachable code: unexpected repository'
516
 
                                  ' format.')
517
 
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store, text_store)
 
498
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, revision_store, control_store, text_store)
518
499
 
519
500
 
520
501
class MetaDirRepository(Repository):
521
502
    """Repositories in the new meta-dir layout."""
522
503
 
523
 
    def __init__(self, _format, a_bzrdir, control_files, revision_store, text_store):
 
504
    def __init__(self, _format, a_bzrdir, control_files, revision_store, control_store, text_store):
524
505
        super(MetaDirRepository, self).__init__(_format,
525
506
                                                a_bzrdir,
526
507
                                                control_files,
527
508
                                                revision_store,
 
509
                                                control_store,
528
510
                                                text_store)
529
511
 
530
512
        dir_mode = self.control_files._dir_mode
544
526
                ws.enable_cache = True
545
527
            return ws
546
528
 
547
 
        if isinstance(self._format, RepositoryFormat7):
548
 
            self.control_weaves = get_weave('')
549
 
        elif isinstance(self._format, RepositoryFormatKnit1):
550
 
            self.control_weaves = get_weave('control')
551
 
        else:
552
 
            raise errors.BzrError('unreachable code: unexpected repository'
553
 
                                  ' format.')
554
 
 
555
529
 
556
530
class RepositoryFormat(object):
557
531
    """A repository format.
595
569
        except KeyError:
596
570
            raise errors.UnknownFormatError(format_string)
597
571
 
 
572
    def _get_control_store(self, repo_transport, control_files):
 
573
        """Return the control store for this repository."""
 
574
        raise NotImplementedError(self._get_control_store)
 
575
    
598
576
    @classmethod
599
577
    def get_default_format(klass):
600
578
        """Return the current default format."""
732
710
            control_files.unlock()
733
711
        return self.open(a_bzrdir, _found=True)
734
712
 
 
713
    def _get_control_store(self, repo_transport, control_files):
 
714
        """Return the control store for this repository."""
 
715
        return self._get_versioned_file_store('',
 
716
                                              repo_transport,
 
717
                                              control_files,
 
718
                                              prefixed=False)
 
719
 
735
720
    def _get_text_store(self, transport, control_files):
736
721
        """Get a store for file texts for this format."""
737
722
        raise NotImplementedError(self._get_text_store)
744
729
 
745
730
        repo_transport = a_bzrdir.get_repository_transport(None)
746
731
        control_files = a_bzrdir._control_files
 
732
        text_store = self._get_text_store(repo_transport, control_files)
 
733
        control_store = self._get_control_store(repo_transport, control_files)
747
734
        revision_store = self._get_revision_store(repo_transport, control_files)
748
 
        text_store = self._get_text_store(repo_transport, control_files)
749
735
        return AllInOneRepository(_format=self,
750
736
                                  a_bzrdir=a_bzrdir,
751
737
                                  revision_store=revision_store,
 
738
                                  control_store=control_store,
752
739
                                  text_store=text_store)
753
740
 
754
741
 
781
768
        """
782
769
        return False
783
770
 
 
771
    def _get_control_store(self, repo_transport, control_files):
 
772
        """Format 4 repositories have no formal control store at this point.
 
773
        
 
774
        This will cause any control-file-needing apis to fail - this is desired.
 
775
        """
 
776
        return None
 
777
    
784
778
    def _get_revision_store(self, repo_transport, control_files):
785
779
        """See RepositoryFormat._get_revision_store()."""
786
780
        return self._get_text_rev_store(repo_transport,
860
854
        control_files = LockableFiles(repository_transport, 'lock')
861
855
        return control_files
862
856
 
 
857
    def _get_control_store(self, repo_transport, control_files):
 
858
        """Return the control store for this repository."""
 
859
        return self._get_versioned_file_store('',
 
860
                                              repo_transport,
 
861
                                              control_files,
 
862
                                              prefixed=False)
 
863
 
863
864
    def _get_revision_store(self, repo_transport, control_files):
864
865
        """See RepositoryFormat._get_revision_store()."""
865
866
        return self._get_text_rev_store(repo_transport,
884
885
        else:
885
886
            repo_transport = a_bzrdir.get_repository_transport(None)
886
887
        control_files = LockableFiles(repo_transport, 'lock')
 
888
        text_store = self._get_text_store(repo_transport, control_files)
 
889
        control_store = self._get_control_store(repo_transport, control_files)
887
890
        revision_store = self._get_revision_store(repo_transport, control_files)
888
 
        text_store = self._get_text_store(repo_transport, control_files)
889
891
        return MetaDirRepository(_format=self,
890
892
                                 a_bzrdir=a_bzrdir,
891
893
                                 control_files=control_files,
892
894
                                 revision_store=revision_store,
 
895
                                 control_store=control_store,
893
896
                                 text_store=text_store)
894
897
 
895
898
    def _upload_blank_content(self, a_bzrdir, dirs, files, utf8_files, shared):