Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works
Code Observatory / class
Checkout
codeintel.git_source.Checkout
PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.
PHAROS at 975a38dMIT license
Around this symbol
Search all symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| open_checkout | git_source.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| __enter__ | git_source.py | same file |
| __exit__ | git_source.py | same file |
| __init__ | git_source.py | same file |
| _git | git_source.py | same file |
| close | git_source.py | same file |
| list_files | git_source.py | same file |
| read_blob | git_source.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| git_source | git_source.py | same file |
codeintel.git_source.Checkoutbackend/app/codeintel/git_source.py, lines 333–392Open source
class Checkout: """A repository at a pinned commit, ready to be read. Use as a context manager; remote clones are deleted on exit. """ def __init__(self, git_dir: str, commit: str, *, temp_dir: str | None = None, branch: str | None = None) -> None: self.git_dir = git_dir self.commit = commit self.branch = branch self._temp_dir = temp_dir self._reader: subprocess.Popen | None = None def __enter__(self) -> Checkout: return self def __exit__(self, *_exc) -> None: self.close() def close(self) -> None: if self._reader is not None: try: self._reader.stdin.close() # type: ignore[union-attr] self._reader.wait(timeout=10) except Exception: self._reader.kill() self._reader = None if self._temp_dir: shutil.rmtree(self._temp_dir, ignore_errors=True) self._temp_dir = None def _git(self, *args: str, timeout: int = GIT_TIMEOUT_SECONDS) -> str: return _run(["git", f"--git-dir={self.git_dir}", *args], timeout=timeout) def list_files(self) -> Iterator[TreeEntry]: """Regular files tracked at the commit (symlinks and submodules excluded).""" out = self._git("ls-tree", "-r", "-z", "--long", "--full-tree", self.commit, timeout=300) for record in out.split("\0"): if not record: continue meta, _, path = record.partition("\t") fields = meta.split() if len(fields) != 4: continue mode, obj_type, sha, size = fields if obj_type != "blob" or mode not in ("100644", "100755"): continue yield TreeEntry(path=path, blob_sha=sha, size=int(size) if size.isdigit() else 0, mode=mode) def read_blob(self, sha: str) -> bytes: """Read one blob through a persistent ``git cat-file --batch`` process.""" if not re.fullmatch(r"[0-9a-f]{40,64}", sha): raise ValueError("invalid blob sha") if self._reader is None: self._reader = subprocess.Popen( ["git", f"--git-dir={self.git_dir}", "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,Shows the first 60 of 74 lines. The rest is on GitHub at this commit.
What the index recorded
- Signature
class Checkout:- File
backend/app/codeintel/git_source.py- Lines
- 333–406
- Parser
- python-ast
- Git blob
6f88470169e4935929c5f865a974bd86da564c1a
