1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-08 12:01:21 +02:00

38592 (plus tweak): _git: New recent branches completion, unused. (Joint with Nils Luxton)

This commit is contained in:
Daniel Shahaf 2016-06-04 09:19:54 +00:00
parent 769bd4070a
commit 6e834587eb
2 changed files with 65 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2016-06-07 Daniel Shahaf <d.s@daniel.shahaf.name>
* 38592 (plus tweak): Completion/Unix/Command/_git: New recent
branches completion, unused. (Joint with Nils Luxton)
2016-06-07 Barton E. Schaefer <schaefer@zsh.org>
* 38630: Src/builtin.c: fix infinite loop of "hash ="

View file

@ -5640,6 +5640,66 @@ __git_commit_objects_prefer_recent () {
__git_recent_commits $argument_array_names || __git_commit_objects
}
# This function returns in $reply recently-checked-out refs' names, in order
# from most to least recent.
(( $+functions[__git_recent_branches__names] )) ||
__git_recent_branches__names()
{
local -a reflog
local reflog_subject
local new_head
local -A seen
reply=()
reflog=(${(ps:\0:)"$(_call_program reflog git reflog -1000 -z --grep-reflog='\^checkout:\ moving\ from\ ' --pretty='%gs' 2>/dev/null)"})
for reflog_subject in $reflog; do
new_head=${${=reflog_subject}[4]}
# 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] )) ||
__git_recent_branches() {
local -a branches descriptions
local branch description
local -a reply
__git_recent_branches__names \
; for branch in $reply
do
# ### We'd want to convert all $reply to $descriptions in one shot,
# ### with this:
# ### array=("${(ps:\0:)"$(_call_program descriptions git --no-pager log --no-walk=unsorted -z --pretty=%s ${(q)reply} --)"}")
# ### , but git croaks if any of the positional arguments is a ref name
# ### that has been deleted. (So does 'git rev-parse'.)
# ### Hence, we resort to fetching the descriptions one-by-one.
# ### This would be costly if fork() is expensive.
description="$(_call_program description git --no-pager log --no-walk=unsorted --pretty=%s ${(q)branch} --)"
# If the ref has been deleted, $description would be empty.
if [[ -n "$description" ]]; then
branches+=$branch
descriptions+="${branch//:/\:}:${description}"
fi
done
_describe -V -t recent-branches "recent branches" descriptions branches
}
(( $+functions[__git_commits] )) ||
__git_commits () {
local -a argument_array_names