Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
automatic1111
GitHub Repository: automatic1111/stable-diffusion-webui
Path: blob/master/modules/gitpython_hack.py
3055 views
1
from __future__ import annotations
2
3
import io
4
import subprocess
5
6
import git
7
8
9
class Git(git.Git):
10
"""
11
Git subclassed to never use persistent processes.
12
"""
13
14
def _get_persistent_cmd(self, attr_name, cmd_name, *args, **kwargs):
15
raise NotImplementedError(f"Refusing to use persistent process: {attr_name} ({cmd_name} {args} {kwargs})")
16
17
def get_object_header(self, ref: str | bytes) -> tuple[str, str, int]:
18
ret = subprocess.check_output(
19
[self.GIT_PYTHON_GIT_EXECUTABLE, "cat-file", "--batch-check"],
20
input=self._prepare_ref(ref),
21
cwd=self._working_dir,
22
timeout=2,
23
)
24
return self._parse_object_header(ret)
25
26
def stream_object_data(self, ref: str) -> tuple[str, str, int, Git.CatFileContentStream]:
27
# Not really streaming, per se; this buffers the entire object in memory.
28
# Shouldn't be a problem for our use case, since we're only using this for
29
# object headers (commit objects).
30
ret = subprocess.check_output(
31
[self.GIT_PYTHON_GIT_EXECUTABLE, "cat-file", "--batch"],
32
input=self._prepare_ref(ref),
33
cwd=self._working_dir,
34
timeout=30,
35
)
36
bio = io.BytesIO(ret)
37
hexsha, typename, size = self._parse_object_header(bio.readline())
38
return (hexsha, typename, size, self.CatFileContentStream(size, bio))
39
40
41
class Repo(git.Repo):
42
GitCommandWrapperType = Git
43
44