1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-12-09 06:41:22 +01:00
zsh/Functions/VCS_Info/VCS_INFO_set-patch-format
Daniel Shahaf 9211d7f277 40479: vcs_info set-patch-format: Prepare for more code sharing between the callers.
This changes hook invocation order in the hg backend.
2017-02-03 18:14:00 +00:00

54 lines
1.7 KiB
Text

# This function is the common guts of the gen-applied-string /
# gen-unapplied-string / set-patch-format dance of several backends.
#
# Parameters:
# $1 - name of an array parameter to be the argument to gen-applied-string
# $2 - name of a parameter to store the applied-string in
# $3 - name of an array parameter to be the argument to gen-unapplied-string
# $4 - name of a parameter to store the unapplied-string in
# $5 - context argument for use in zstyle getters
# $6 - name of a parameter to store a patch-format format string in
# $7 - name of an assoc parameter with extra $hook_com key-value pairs for the
# set-patch-format hook invocation, or '' for none
#
# Output:
# - $hook_com is overwritten and the keys 'applied', 'applied-n',
# 'unapplied', 'unapplied-n', 'all-n' are set.
{
local REPLY
if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then
if (( ${(P)#1} )); then
REPLY=${(P)1[1]}
else
REPLY=""
fi
else
REPLY=${hook_com[applied-string]}
fi
: ${(P)2::=$REPLY}
hook_com=()
if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then
REPLY=${(P)#3}
else
REPLY=${hook_com[unapplied-string]}
fi
: ${(P)4::=$REPLY}
hook_com=()
if (( ${(P)#1} )); then
zstyle -s "${5}" patch-format REPLY || REPLY="%p (%n applied)"
else
zstyle -s "${5}" nopatch-format REPLY || REPLY="no patch applied"
fi
: ${(P)6::=$REPLY}
hook_com=(
applied-n ${(P)#1}
applied "${(P)2}"
unapplied-n ${(P)#3}
unapplied "${(P)4}"
)
hook_com[all-n]=$(( ${hook_com[applied-n]} + ${hook_com[unapplied-n]} ))
hook_com+=( ${7:+"${(@kvP)7}"} )
}