You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 line
1.9KB

  1. """Module with our own gitdb implementation - it uses the git command"""
  2. from git.util import bin_to_hex, hex_to_bin
  3. from gitdb.base import (
  4. OInfo,
  5. OStream
  6. )
  7. from gitdb.db import GitDB # @UnusedImport
  8. from gitdb.db import LooseObjectDB
  9. from .exc import (
  10. GitCommandError,
  11. BadObject
  12. )
  13. __all__ = ('GitCmdObjectDB', 'GitDB')
  14. # class GitCmdObjectDB(CompoundDB, ObjectDBW):
  15. class GitCmdObjectDB(LooseObjectDB):
  16. """A database representing the default git object store, which includes loose
  17. objects, pack files and an alternates file
  18. It will create objects only in the loose object database.
  19. :note: for now, we use the git command to do all the lookup, just until he
  20. have packs and the other implementations
  21. """
  22. def __init__(self, root_path, git):
  23. """Initialize this instance with the root and a git command"""
  24. super(GitCmdObjectDB, self).__init__(root_path)
  25. self._git = git
  26. def info(self, sha):
  27. hexsha, typename, size = self._git.get_object_header(bin_to_hex(sha))
  28. return OInfo(hex_to_bin(hexsha), typename, size)
  29. def stream(self, sha):
  30. """For now, all lookup is done by git itself"""
  31. hexsha, typename, size, stream = self._git.stream_object_data(bin_to_hex(sha))
  32. return OStream(hex_to_bin(hexsha), typename, size, stream)
  33. # { Interface
  34. def partial_to_complete_sha_hex(self, partial_hexsha):
  35. """:return: Full binary 20 byte sha from the given partial hexsha
  36. :raise AmbiguousObjectName:
  37. :raise BadObject:
  38. :note: currently we only raise BadObject as git does not communicate
  39. AmbiguousObjects separately"""
  40. try:
  41. hexsha, typename, size = self._git.get_object_header(partial_hexsha) # @UnusedVariable
  42. return hex_to_bin(hexsha)
  43. except (GitCommandError, ValueError):
  44. raise BadObject(partial_hexsha)
  45. # END handle exceptions
  46. #} END interface