Skip to main content

Module git_version_cache

Module git_version_cache 

Source
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§

BinaryIdentity
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.

Functions§

binary_identity
What: The identity of the executable at real_git, or None when its answer cannot be cached safely. Why: Only a compiled ELF file named git is 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-git under XDG_CACHE_HOME, or under .cache in the home directory. Why: The injected environment decides the location, never a fixed path; a relative XDG_CACHE_HOME is ignored as the XDG rules say.
read_version_text
What: The git version text recorded for exactly this identity, or None for 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_version_text
What: Record text for 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 one git version start. A failure to record is logged and never fails the command.