Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/gitdb/db/git.py: 51%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

37 statements  

1# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors 

2# 

3# This module is part of GitDB and is released under 

4# the New BSD License: https://opensource.org/license/bsd-3-clause/ 

5from gitdb.db.base import ( 

6 CompoundDB, 

7 ObjectDBW, 

8 FileDBBase 

9) 

10 

11from gitdb.db.loose import LooseObjectDB 

12from gitdb.db.pack import PackedDB 

13from gitdb.db.ref import ReferenceDB 

14 

15from gitdb.exc import InvalidDBRoot 

16 

17import os 

18 

19__all__ = ('GitDB', ) 

20 

21 

22class GitDB(FileDBBase, ObjectDBW, CompoundDB): 

23 

24 """A git-style object database, which contains all objects in the 'objects' 

25 subdirectory 

26 

27 ``IMPORTANT``: The usage of this implementation is highly discouraged as it fails to release file-handles. 

28 This can be a problem with long-running processes and/or big repositories. 

29 """ 

30 # Configuration 

31 PackDBCls = PackedDB 

32 LooseDBCls = LooseObjectDB 

33 ReferenceDBCls = ReferenceDB 

34 

35 # Directories 

36 packs_dir = 'pack' 

37 loose_dir = '' 

38 alternates_dir = os.path.join('info', 'alternates') 

39 

40 def __init__(self, root_path): 

41 """Initialize ourselves on a git objects directory""" 

42 super().__init__(root_path) 

43 

44 def _set_cache_(self, attr): 

45 if attr == '_dbs' or attr == '_loose_db': 

46 self._dbs = list() 

47 loose_db = None 

48 for subpath, dbcls in ((self.packs_dir, self.PackDBCls), 

49 (self.loose_dir, self.LooseDBCls), 

50 (self.alternates_dir, self.ReferenceDBCls)): 

51 path = self.db_path(subpath) 

52 if os.path.exists(path): 

53 self._dbs.append(dbcls(path)) 

54 if dbcls is self.LooseDBCls: 

55 loose_db = self._dbs[-1] 

56 # END remember loose db 

57 # END check path exists 

58 # END for each db type 

59 

60 # should have at least one subdb 

61 if not self._dbs: 

62 raise InvalidDBRoot(self.root_path()) 

63 # END handle error 

64 

65 # we the first one should have the store method 

66 assert loose_db is not None and hasattr(loose_db, 'store'), "First database needs store functionality" 

67 

68 # finally set the value 

69 self._loose_db = loose_db 

70 else: 

71 super()._set_cache_(attr) 

72 # END handle attrs 

73 

74 #{ ObjectDBW interface 

75 

76 def store(self, istream): 

77 return self._loose_db.store(istream) 

78 

79 def ostream(self): 

80 return self._loose_db.ostream() 

81 

82 def set_ostream(self, ostream): 

83 return self._loose_db.set_ostream(ostream) 

84 

85 #} END objectdbw interface