INNER CODE UNIT · Python
Tree
pineforge-4pass/pineforge-engine · benchmarks/check_provenance.py:77
class Tree:
"""The repository's files: the working tree (tracked files only) or commit ``rev``."""
def __init__(self, rev: str | None = None):
self.rev = rev
self.reads: list[str] = []
self._read: dict[str, bytes] = {}
def _git(self, *args: str, text: bool = True) -> subprocess.CompletedProcess:
return subprocess.run(["git", "-C", str(REPO), *args], capture_output=True, text=text)
def bytes(self, path: str) -> bytes:
self.reads.append(path)
if path not in self._read:
if self.rev:
res = self._git("show", f"{self.rev}:{path}", text=False)
if res.returncode:
raise Unsourced(f"{path} is not committed at {self.rev}")