11from base import (
2- CompoundDB ,
3- FileDBBase ,
4- )
2+ CompoundDB ,
3+ ObjectDBW ,
4+ FileDBBase
5+ )
56
67from loose import LooseObjectDB
78from pack import PackedDB
1314
1415__all__ = ('GitDB' , )
1516
16- class GitDB (FileDBBase , CompoundDB ):
17+ class GitDB (FileDBBase , ObjectDBW , CompoundDB ):
1718 """A git-style object database, which contains all objects in the 'objects'
1819 subdirectory"""
1920 # Configuration
@@ -22,7 +23,7 @@ class GitDB(FileDBBase, CompoundDB):
2223 ReferenceDBCls = ReferenceDB
2324
2425 # Directories
25- packs_dir = 'packs '
26+ packs_dir = 'pack '
2627 loose_dir = ''
2728 alternates_dir = os .path .join ('info' , 'alternates' )
2829
@@ -31,19 +32,42 @@ def __init__(self, root_path):
3132 super (GitDB , self ).__init__ (root_path )
3233
3334 def _set_cache_ (self , attr ):
34- if attr == '_dbs' :
35+ if attr == '_dbs' or attr == '_loose_db' :
3536 self ._dbs = list ()
37+ loose_db = None
3638 for subpath , dbcls in ((self .packs_dir , self .PackDBCls ),
3739 (self .loose_dir , self .LooseDBCls ),
3840 (self .alternates_dir , self .ReferenceDBCls )):
3941 path = self .db_path (subpath )
4042 if os .path .exists (path ):
4143 self ._dbs .append (dbcls (path ))
44+ if dbcls is self .LooseDBCls :
45+ loose_db = self ._dbs [- 1 ]
46+ # END remember loose db
4247 # END check path exists
4348 # END for each db type
4449
4550 # should have at least one subdb
4651 if not self ._dbs :
4752 raise InvalidDBRoot (self .root_path ())
53+ # END handle error
54+
55+ # we the first one should have the store method
56+ assert loose_db is not None and hasattr (loose_db , 'store' ), "First database needs store functionality"
57+
58+ # finally set the value
59+ self ._loose_db = loose_db
60+
4861 # END handle dbs
4962
63+ #{ ObjectDBW interface
64+
65+ def store (self , istream ):
66+ return self ._loose_db .store (istream )
67+
68+ def ostream (self ):
69+ return self ._loose_db .ostream ()
70+
71+ def set_ostream (self , ostream ):
72+ return self ._loose_db .set_ostream (ostream )
73+ #} END objectdbw interface
0 commit comments