11"""Module containing a database to deal with packs"""
22from base import (
33 FileDBBase ,
4- ObjectDBR
4+ ObjectDBR ,
5+ CachingDB
56 )
67
78from gitdb .util import (
1819
1920import os
2021import glob
21- __all__ = ('PackedDB' , )
2222
23+ __all__ = ('PackedDB' , )
2324
2425#{ Utilities
2526
2627
27- class PackedDB (FileDBBase , ObjectDBR , LazyMixin ):
28+ class PackedDB (FileDBBase , ObjectDBR , CachingDB , LazyMixin ):
2829 """A database operating on a set of object packs"""
2930
3031 # sort the priority list every N queries
@@ -43,9 +44,10 @@ def __init__(self, root_path):
4344 self ._st_mtime = 0 # last modification data of our root path
4445
4546 def _set_cache_ (self , attr ):
46- # currently it can only be our _entities attribute
47- self ._entities = list ()
48- self .update_pack_entity_cache ()
47+ if attr == '_entities' :
48+ self ._entities = list ()
49+ self .update_cache ()
50+ # END handle entities initialization
4951
5052 def _sort_entities (self ):
5153 self ._entities .sort (key = lambda l : l [0 ], reverse = True )
@@ -95,6 +97,20 @@ def info(self, sha):
9597 def stream (self , sha ):
9698 entity , index = self ._pack_info (sha )
9799 return entity .stream_at_index (index )
100+
101+ def sha_iter (self ):
102+ sha_list = list ()
103+ for entity in self .entities ():
104+ index = entity .index ()
105+ sha_by_index = index .sha
106+ for index in xrange (index .size ()):
107+ yield sha_by_index (index )
108+ # END for each index
109+ # END for each entity
110+
111+ def size (self ):
112+ sizes = [item [1 ].index ().size () for item in self ._entities ]
113+ return reduce (lambda x ,y : x + y , sizes )
98114
99115 #} END object db read
100116
@@ -115,7 +131,7 @@ def store_async(self, reader):
115131
116132 #{ Interface
117133
118- def update_pack_entity_cache (self , force = False ):
134+ def update_cache (self , force = False ):
119135 """Update our cache with the acutally existing packs on disk. Add new ones,
120136 and remove deleted ones. We keep the unchanged ones
121137 :param force: If True, the cache will be updated even though the directory
@@ -162,19 +178,4 @@ def entities(self):
162178 """:return: list of pack entities operated upon by this database"""
163179 return [ item [1 ] for item in self ._entities ]
164180
165- def sha_iter (self ):
166- """Return iterator yielding 20 byte shas for the packed objects in this data base"""
167- sha_list = list ()
168- for entity in self .entities ():
169- index = entity .index ()
170- sha_by_index = index .sha
171- for index in xrange (index .size ()):
172- yield sha_by_index (index )
173- # END for each index
174- # END for each entity
175-
176- def size (self ):
177- """:return: amount of packed objects in this database"""
178- sizes = [item [1 ].index ().size () for item in self ._entities ]
179- return reduce (lambda x ,y : x + y , sizes )
180181 #} END interface
0 commit comments