mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
perf: avoid listing modified files twice in checkout-file (#546)
_forgit_checkout_file called _forgit_list_modified_files once to check for an empty result and again to feed fzf, running git diff twice on every invocation. Cache the result and reuse it for both checks.
This commit is contained in:
parent
9fa93b0861
commit
15db001662
|
|
@ -1123,12 +1123,13 @@ _forgit_git_checkout_file() {
|
|||
# git checkout-file selector
|
||||
_forgit_checkout_file() {
|
||||
_forgit_inside_work_tree || return 1
|
||||
local files opts
|
||||
local files opts modified_files
|
||||
_forgit_contains_non_flags "$@" && {
|
||||
_forgit_git_checkout_file "$@"
|
||||
return $?
|
||||
}
|
||||
[[ $(_forgit_list_modified_files | wc -l) -eq 0 ]] && echo 'Nothing to checkout.' && return 1
|
||||
modified_files="$(_forgit_list_modified_files)"
|
||||
[[ -z $modified_files ]] && echo 'Nothing to checkout.' && return 1
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
-m -0
|
||||
|
|
@ -1138,7 +1139,7 @@ _forgit_checkout_file() {
|
|||
files=()
|
||||
while IFS='' read -r file; do
|
||||
files+=("$file")
|
||||
done < <(_forgit_list_modified_files |
|
||||
done < <(printf '%s\n' "$modified_files" |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf)
|
||||
[[ ${#files[@]} -gt 0 ]] && _forgit_git_checkout_file "$@" "${files[@]}"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue