mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
38624: _git: Optimize the last commit's __git_recent_branches__names as suggested by Matthew.
This commit is contained in:
parent
6e834587eb
commit
0516736eae
2 changed files with 12 additions and 24 deletions
|
@ -1,5 +1,8 @@
|
||||||
2016-06-07 Daniel Shahaf <d.s@daniel.shahaf.name>
|
2016-06-07 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
|
* 38624: Completion/Unix/Command/_git: Optimize the last commit's
|
||||||
|
__git_recent_branches__names as suggested by Matthew.
|
||||||
|
|
||||||
* 38592 (plus tweak): Completion/Unix/Command/_git: New recent
|
* 38592 (plus tweak): Completion/Unix/Command/_git: New recent
|
||||||
branches completion, unused. (Joint with Nils Luxton)
|
branches completion, unused. (Joint with Nils Luxton)
|
||||||
|
|
||||||
|
|
|
@ -5645,30 +5645,15 @@ __git_commit_objects_prefer_recent () {
|
||||||
(( $+functions[__git_recent_branches__names] )) ||
|
(( $+functions[__git_recent_branches__names] )) ||
|
||||||
__git_recent_branches__names()
|
__git_recent_branches__names()
|
||||||
{
|
{
|
||||||
local -a reflog
|
# This parameter expansion does the following:
|
||||||
local reflog_subject
|
# 1. Obtains the last 1000 'checkout' operations from the reflog
|
||||||
local new_head
|
# 2. Extracts the move-source from each
|
||||||
local -A seen
|
# 3. Eliminates duplicates
|
||||||
reply=()
|
# 4. Eliminates commit hashes (leaving only ref names)
|
||||||
|
#
|
||||||
reflog=(${(ps:\0:)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs' 2>/dev/null)"})
|
# See workers/38592 for an equivalent long-hand implementation, and the rest
|
||||||
for reflog_subject in $reflog; do
|
# of that thread for why this implementation was chosen instead.
|
||||||
new_head=${${=reflog_subject}[4]}
|
reply=(${${(u)${${(0)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs')"}#checkout: moving from }%% *}:#[[:xdigit:]](#c40)})
|
||||||
|
|
||||||
# Skip values added in previous iterations.
|
|
||||||
if (( ${+seen[$new_head]} )); then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
seen[$new_head]="" # value is ignored
|
|
||||||
|
|
||||||
# Filter out hashes, to leave only ref names.
|
|
||||||
if [[ $new_head =~ '^[0-9a-f]{40}$' ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# All checks passed. Add it.
|
|
||||||
reply+=( $new_head )
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(( $+functions[__git_recent_branches] )) ||
|
(( $+functions[__git_recent_branches] )) ||
|
||||||
|
|
Loading…
Reference in a new issue