Compare commits

..
Author SHA1 Message Date
copilot-swe-agent[bot]androbbyrussell 6b789c8bd6 fix(git plugin): include git exec path in version cache key
Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com>
2026-09-06 15:49:09 +00:00
Robby RussellandClaude Fable 5.1 984d07a53b perf(git): cache the git version used for alias selection
`git version` was forked on every startup so that four aliases could be
picked according to the installed git. Cache the version in
$ZSH_CACHE_DIR for a day, keyed on the git binary's path and mtime, so a
different or upgraded git is picked up right away and the fork otherwise
happens once a day.

Measured on macOS arm64, zsh 5.9: git.plugin.zsh 9.2 ms -> 2.0 ms per
interactive start.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-06 08:06:51 -07:00
2 changed files with 27 additions and 15 deletions
+7 -14
View File
@@ -146,23 +146,16 @@ esac
# the host name to disambiguate local vs. remote paths.
function omz_termsupport_cwd {
setopt localoptions unset
# Percent-encode the host and path names. Encoding forks a subshell each,
# so keep the result and only redo it when $HOST or $PWD changed.
local cache_key="$HOST:$PWD:${KONSOLE_PROFILE_NAME:+1}:${KONSOLE_DBUS_SESSION:+1}"
if [[ "$_omz_termsupport_cwd_key" != "$cache_key" ]]; then
local URL_HOST URL_PATH
URL_HOST="$(omz_urlencode -P "$HOST")" || return 1
URL_PATH="$(omz_urlencode -P "$PWD")" || return 1
# Percent-encode the host and path names.
local URL_HOST URL_PATH
URL_HOST="$(omz_urlencode -P $HOST)" || return 1
URL_PATH="$(omz_urlencode -P $PWD)" || return 1
# Konsole errors if the HOST is provided
[[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
typeset -g _omz_termsupport_cwd_key="$cache_key"
typeset -g _omz_termsupport_cwd_url="file://${URL_HOST}${URL_PATH}"
fi
# Konsole errors if the HOST is provided
[[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST=""
# common control sequence (OSC 7) to set current host and path
printf "\e]7;%s\e\\" "$_omz_termsupport_cwd_url"
printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}"
}
# Use a precmd hook instead of a chpwd hook to avoid contaminating output
+20 -1
View File
@@ -1,6 +1,25 @@
# Git version checking
autoload -Uz is-at-least
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
# Running `git version` forks on every startup, so cache the result for a day
# in $ZSH_CACHE_DIR, keyed on the git command path, mtime, and exec path.
() {
local cache="$ZSH_CACHE_DIR/git-version" key exec_path
local -a stat lines
zmodload -F zsh/stat b:zstat
zstat -A stat +mtime -- "$commands[git]" 2>/dev/null
exec_path="$(git --exec-path 2>/dev/null)"
key="$commands[git] $stat[1] $exec_path"
lines=("$cache"(Nm-1))
(( $#lines )) && lines=("${(@f)$(<"$cache")}")
if [[ "$lines[1]" = "$key" ]]; then
git_version="$lines[2]"
return
fi
git_version="${${(As: :)$(git version 2>/dev/null)}[3]}"
[[ ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$key" "$git_version" >| "$cache"
}
#
# Functions Current