Expand description
The private per-user cache of the version text, keyed by the Git executable’s identity.
What:
A private, per-user cache of the text git version prints,
keyed by the identity of the Git executable that printed it.
Why:
Every commit starts git version to learn whether Git is new enough.
The text is fixed by the executable,
so while the executable is byte-for-byte the same file the answer is the same.
The identity is the canonical path,
size,
modification time,
change time,
device and inode:
an upgrade replaces the file (new inode) or rewrites it (new size, times),
so a replaced Git is noticed on the next start and a stale entry is never trusted.
The cache is used only for a real compiled executable named git:
a script,
or a shim such as a version manager’s git link to a dispatcher,
picks another Git by directory or environment,
so its own file proves nothing about the version it will run.
The cache lives in the user’s cache directory because the version check runs before any repository is known.
In TS you’d write (pseudocode):
const identity = await binaryIdentity(gitPath); // undefined: do not cache
const text = identity && (await readCache(dir, identity)) ?? (await runGitVersion());Structs§
- Binary
Identity - What: The identity of one Git executable, as the text that goes into a cache file and the canonical path that names the file. Why: The text is compared whole against what the cache file recorded.
Constants§
- VERSION_
KIND - The kind of the file that holds the text
git versionprints.
Functions§
- binary_
identity - What:
The identity of the executable at
real_git, orNonewhen its answer cannot be cached safely. Why: Only a compiled ELF file namedgitis identified: its version is a property of its bytes. A path or a field that would need escaping in the one-line text is refused too. - cache_
directory - What:
The directory that holds the cache files:
cli-gitunderXDG_CACHE_HOME, or under.cachein the home directory. Why: The injected environment decides the location, never a fixed path; a relativeXDG_CACHE_HOMEis ignored as the XDG rules say. - read_
cached_ text - What:
The text of
kindrecorded for exactly this identity, orNonefor a missing, foreign, unreadable or stale entry. Why: Every fact that is a property of the executable’s bytes (its version, its compiled-in configuration path) shares the identity check and the private-file check; only the file name and tag differ. - read_
version_ text - What:
The
git versiontext recorded for exactly this identity, orNonefor a missing, foreign, unreadable or stale entry. Why: Anything but an exact match of the whole identity line is stale, and the caller then asks Git. - store_
cached_ text - Record
textofkindfor this identity, replacing any earlier entry; seestore_version_text. - store_
version_ text - What:
Record
textfor this identity, replacing any earlier entry, and report nothing when recording is impossible. Why: The write goes to a private temporary file and is renamed over the entry, so a reader sees the old entry or the new one whole; it is not synced because a lost entry only costs onegit versionstart. A failure to record is logged and never fails the command.