- Notifications
You must be signed in to change notification settings - Fork68
Expand file tree
/
Copy pathgit.py
More file actions
85 lines (66 loc) · 2.6 KB
/
git.py
File metadata and controls
85 lines (66 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
#
# This module is part of GitDB and is released under
# the New BSD License: https://opensource.org/license/bsd-3-clause/
fromgitdb.db.baseimport (
CompoundDB,
ObjectDBW,
FileDBBase
)
fromgitdb.db.looseimportLooseObjectDB
fromgitdb.db.packimportPackedDB
fromgitdb.db.refimportReferenceDB
fromgitdb.excimportInvalidDBRoot
importos
__all__= ('GitDB', )
classGitDB(FileDBBase,ObjectDBW,CompoundDB):
"""A git-style object database, which contains all objects in the 'objects'
subdirectory
``IMPORTANT``: The usage of this implementation is highly discouraged as it fails to release file-handles.
This can be a problem with long-running processes and/or big repositories.
"""
# Configuration
PackDBCls=PackedDB
LooseDBCls=LooseObjectDB
ReferenceDBCls=ReferenceDB
# Directories
packs_dir='pack'
loose_dir=''
alternates_dir=os.path.join('info','alternates')
def__init__(self,root_path):
"""Initialize ourselves on a git objects directory"""
super().__init__(root_path)
def_set_cache_(self,attr):
ifattr=='_dbs'orattr=='_loose_db':
self._dbs=list()
loose_db=None
forsubpath,dbclsin ((self.packs_dir,self.PackDBCls),
(self.loose_dir,self.LooseDBCls),
(self.alternates_dir,self.ReferenceDBCls)):
path=self.db_path(subpath)
ifos.path.exists(path):
self._dbs.append(dbcls(path))
ifdbclsisself.LooseDBCls:
loose_db=self._dbs[-1]
# END remember loose db
# END check path exists
# END for each db type
# should have at least one subdb
ifnotself._dbs:
raiseInvalidDBRoot(self.root_path())
# END handle error
# we the first one should have the store method
assertloose_dbisnotNoneandhasattr(loose_db,'store'),"First database needs store functionality"
# finally set the value
self._loose_db=loose_db
else:
super()._set_cache_(attr)
# END handle attrs
#{ ObjectDBW interface
defstore(self,istream):
returnself._loose_db.store(istream)
defostream(self):
returnself._loose_db.ostream()
defset_ostream(self,ostream):
returnself._loose_db.set_ostream(ostream)
#} END objectdbw interface