def test_deflated_smaller_window_buffer(self): # zlib on some systems uses smaller buffers, # resulting in a different header. # See https://github.com/libgit2/libgit2/pull/464 sf = ShaFile.from_file(BytesIO(small_buffer_zlib_object)) self.assertEqual(sf.type_name, "tag") self.assertEqual(sf.tagger, " <@localhost>")
def _get_loose_object(self, sha): path = osutils.joinpath(self._split_loose_object(sha)) try: with self.transport.get(urlutils.quote_from_bytes(path)) as f: return ShaFile.from_file(f) except NoSuchFile: return None
def test_deflated_smaller_window_buffer(self): # zlib on some systems uses smaller buffers, # resulting in a different header. # See https://github.com/libgit2/libgit2/pull/464 sf = ShaFile.from_file(BytesIO(small_buffer_zlib_object)) self.assertEqual(sf.type_name, b'tag') self.assertEqual(sf.tagger, b' <@localhost>')
def _get_loose_object(self, sha): path = self._get_shafile_path(sha) try: return ShaFile.from_file(path) except (OSError, IOError), e: if e.errno == errno.ENOENT: return None raise
def _get_git_object(self, sha: bytes) -> ShaFile: # try to get the object from a pack file first to avoid flooding # git server with numerous HTTP requests for pack in list(self.packs): try: if sha in pack: return pack[sha] except (NotGitRepository, struct.error): # missing (dulwich http client raises NotGitRepository on 404) # or invalid pack index/content, remove it from global packs list logger.debug( "A pack file is missing or its content is invalid") self.packs.remove(pack) # fetch it from objects/ directory otherwise sha_hex = sha.decode() object_path = f"objects/{sha_hex[:2]}/{sha_hex[2:]}" return ShaFile.from_file(self._http_get(object_path))
def _get_shafile(self, sha): path = self._get_shafile_path(sha) if os.path.exists(path): return ShaFile.from_file(path) return None