mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-18 23:09:58 -05:00
feat: cache git blobs
This commit is contained in:
@@ -17,6 +17,8 @@ class DotsSource:
|
|||||||
cfg = get_config().get("dots", {})
|
cfg = get_config().get("dots", {})
|
||||||
self.url = cfg.get("url", "https://github.com/caelestia-dots/caelestia.git")
|
self.url = cfg.get("url", "https://github.com/caelestia-dots/caelestia.git")
|
||||||
self.branch = cfg.get("branch", "main")
|
self.branch = cfg.get("branch", "main")
|
||||||
|
# Cache git blobs by (ref, relpath); objects are immutable for a given rev
|
||||||
|
self._blob_cache: dict[tuple[str, str], bytes] = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def remote_ref(self) -> str:
|
def remote_ref(self) -> str:
|
||||||
@@ -90,7 +92,10 @@ class DotsSource:
|
|||||||
return self._git("show", f"{ref}:{relpath}")
|
return self._git("show", f"{ref}:{relpath}")
|
||||||
|
|
||||||
def blob_at(self, ref: str, relpath: str) -> bytes:
|
def blob_at(self, ref: str, relpath: str) -> bytes:
|
||||||
return self._git_bytes("show", f"{ref}:{relpath}")
|
key = (ref, relpath)
|
||||||
|
if key not in self._blob_cache:
|
||||||
|
self._blob_cache[key] = self._git_bytes("show", f"{ref}:{relpath}")
|
||||||
|
return self._blob_cache[key]
|
||||||
|
|
||||||
def files_at(self, ref: str, relpath: str) -> list[str]:
|
def files_at(self, ref: str, relpath: str) -> list[str]:
|
||||||
"""Repo-relative paths of all files under relpath at ref (the path itself if it is a file)."""
|
"""Repo-relative paths of all files under relpath at ref (the path itself if it is a file)."""
|
||||||
|
|||||||
Reference in New Issue
Block a user