Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/git/db.py: 58%

27 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1"""Module with our own gitdb implementation - it uses the git command""" 

2from git.util import bin_to_hex, hex_to_bin 

3from gitdb.base import OInfo, OStream 

4from gitdb.db import GitDB # @UnusedImport 

5from gitdb.db import LooseObjectDB 

6 

7from gitdb.exc import BadObject 

8from git.exc import GitCommandError 

9 

10# typing------------------------------------------------- 

11 

12from typing import TYPE_CHECKING 

13from git.types import PathLike 

14 

15if TYPE_CHECKING: 15 ↛ 16line 15 didn't jump to line 16, because the condition on line 15 was never true

16 from git.cmd import Git 

17 

18 

19# -------------------------------------------------------- 

20 

21__all__ = ("GitCmdObjectDB", "GitDB") 

22 

23 

24class GitCmdObjectDB(LooseObjectDB): 

25 

26 """A database representing the default git object store, which includes loose 

27 objects, pack files and an alternates file 

28 

29 It will create objects only in the loose object database. 

30 :note: for now, we use the git command to do all the lookup, just until he 

31 have packs and the other implementations 

32 """ 

33 

34 def __init__(self, root_path: PathLike, git: "Git") -> None: 

35 """Initialize this instance with the root and a git command""" 

36 super(GitCmdObjectDB, self).__init__(root_path) 

37 self._git = git 

38 

39 def info(self, binsha: bytes) -> OInfo: 

40 hexsha, typename, size = self._git.get_object_header(bin_to_hex(binsha)) 

41 return OInfo(hex_to_bin(hexsha), typename, size) 

42 

43 def stream(self, binsha: bytes) -> OStream: 

44 """For now, all lookup is done by git itself""" 

45 hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(binsha)) 

46 return OStream(hex_to_bin(hexsha), typename, size, stream) 

47 

48 # { Interface 

49 

50 def partial_to_complete_sha_hex(self, partial_hexsha: str) -> bytes: 

51 """:return: Full binary 20 byte sha from the given partial hexsha 

52 :raise AmbiguousObjectName: 

53 :raise BadObject: 

54 :note: currently we only raise BadObject as git does not communicate 

55 AmbiguousObjects separately""" 

56 try: 

57 hexsha, _typename, _size = self._git.get_object_header(partial_hexsha) 

58 return hex_to_bin(hexsha) 

59 except (GitCommandError, ValueError) as e: 

60 raise BadObject(partial_hexsha) from e 

61 # END handle exceptions 

62 

63 # } END interface