~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-09-13 02:11:41 UTC
  • Revision ID: mbp@sourcefrog.net-20050913021141-263bfc2655ac3ed2
- store inventories in weave

- put more intelligence into WeaveStore

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import sys
19
19
import os
 
20
from cStringIO import StringIO
20
21
 
21
22
import bzrlib
22
23
from bzrlib.trace import mutter, note
36
37
import bzrlib.ui
37
38
 
38
39
 
 
40
INVENTORY_FILEID = '__inventory'
 
41
ANCESTRY_FILEID = '__ancestry'
 
42
 
39
43
 
40
44
BZR_BRANCH_FORMAT_4 = "Bazaar-NG branch, format 0.0.4\n"
41
45
BZR_BRANCH_FORMAT_5 = "Bazaar-NG branch, format 5\n"
44
48
 
45
49
# TODO: Some operations like log might retrieve the same revisions
46
50
# repeatedly to calculate deltas.  We could perhaps have a weakref
47
 
# cache in memory to make this faster.
 
51
# cache in memory to make this faster.  In general anything can be
 
52
# cached in memory between lock and unlock operations.
48
53
 
49
54
# TODO: please move the revision-string syntax stuff out of the branch
50
55
# object; it's clutter
167
172
    _lock_mode = None
168
173
    _lock_count = None
169
174
    _lock = None
 
175
    _inventory_weave = None
170
176
    
171
177
    # Map some sort of prefix into a namespace
172
178
    # stuff like "revno:10", "revid:", etc.
205
211
 
206
212
        self.weave_store = WeaveStore(self.controlfilename('weaves'))
207
213
        self.revision_store = ImmutableStore(self.controlfilename('revision-store'))
208
 
        self.inventory_store = ImmutableStore(self.controlfilename('inventory-store'))
209
214
 
210
215
 
211
216
    def __str__(self):
309
314
            "This is a Bazaar-NG control directory.\n"
310
315
            "Do not change any files in this directory.\n")
311
316
        self.controlfile('branch-format', 'w').write(BZR_BRANCH_FORMAT_5)
312
 
        for d in ('text-store', 'inventory-store', 'revision-store',
 
317
        for d in ('text-store', 'revision-store',
313
318
                  'weaves'):
314
319
            os.mkdir(self.controlfilename(d))
315
320
        for f in ('revision-history', 'merged-patches',
645
650
        return bzrlib.osutils.sha_file(self.get_revision_xml(revision_id))
646
651
 
647
652
 
 
653
    def get_inventory_weave(self):
 
654
        return self.weave_store.get_weave(INVENTORY_FILEID)
 
655
 
 
656
 
648
657
    def get_inventory(self, revision_id):
649
 
        """Get Inventory object by hash.
650
 
 
651
 
        TODO: Perhaps for this and similar methods, take a revision
652
 
               parameter which can be either an integer revno or a
653
 
               string hash."""
654
 
        f = self.get_inventory_xml_file(revision_id)
 
658
        """Get Inventory object by hash."""
 
659
        # FIXME: The text gets passed around a lot coming from the weave.
 
660
        f = StringIO(self.get_inventory_xml(revision_id))
655
661
        return bzrlib.xml5.serializer_v5.read_inventory(f)
656
662
 
657
663
 
659
665
        """Get inventory XML as a file object."""
660
666
        try:
661
667
            assert isinstance(revision_id, basestring), type(revision_id)
662
 
            return self.inventory_store[revision_id]
 
668
            iw = self.get_inventory_weave()
 
669
            return iw.get_text(iw.lookup(revision_id))
663
670
        except IndexError:
664
671
            raise bzrlib.errors.HistoryMissing(self, 'inventory', revision_id)
665
672
 
666
 
    get_inventory_xml_file = get_inventory_xml
667
 
            
668
673
 
669
674
    def get_inventory_sha1(self, revision_id):
670
675
        """Return the sha1 hash of the inventory entry
671
676
        """
672
 
        return sha_file(self.get_inventory_xml_file(revision_id))
 
677
        return self.get_revision(revision_id).inventory_sha1
673
678
 
674
679
 
675
680
    def get_revision_inventory(self, revision_id):