Path: blob/master/modules/gitpython_hack.py
3055 views
from __future__ import annotations12import io3import subprocess45import git678class Git(git.Git):9"""10Git subclassed to never use persistent processes.11"""1213def _get_persistent_cmd(self, attr_name, cmd_name, *args, **kwargs):14raise NotImplementedError(f"Refusing to use persistent process: {attr_name} ({cmd_name} {args} {kwargs})")1516def get_object_header(self, ref: str | bytes) -> tuple[str, str, int]:17ret = subprocess.check_output(18[self.GIT_PYTHON_GIT_EXECUTABLE, "cat-file", "--batch-check"],19input=self._prepare_ref(ref),20cwd=self._working_dir,21timeout=2,22)23return self._parse_object_header(ret)2425def stream_object_data(self, ref: str) -> tuple[str, str, int, Git.CatFileContentStream]:26# Not really streaming, per se; this buffers the entire object in memory.27# Shouldn't be a problem for our use case, since we're only using this for28# object headers (commit objects).29ret = subprocess.check_output(30[self.GIT_PYTHON_GIT_EXECUTABLE, "cat-file", "--batch"],31input=self._prepare_ref(ref),32cwd=self._working_dir,33timeout=30,34)35bio = io.BytesIO(ret)36hexsha, typename, size = self._parse_object_header(bio.readline())37return (hexsha, typename, size, self.CatFileContentStream(size, bio))383940class Repo(git.Repo):41GitCommandWrapperType = Git424344