1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-11-01 18:30:55 +01:00

40403/0004: vcs_info set-patch-format helper: Part #4.

This also fixes the %a (${hook_com[all-n]}) expando in the hg backend:
before this change, it counted only unapplied changes.
This commit is contained in:
Daniel Shahaf 2017-01-23 18:15:35 +00:00
parent edd9798de7
commit 2854a67e09
5 changed files with 26 additions and 20 deletions

View file

@ -1,5 +1,11 @@
2017-01-25 Daniel Shahaf <d.s@daniel.shahaf.name>
* 40403/0004: Functions/VCS_Info/Backends/VCS_INFO_get_data_git,
Functions/VCS_Info/Backends/VCS_INFO_get_data_hg,
Functions/VCS_Info/VCS_INFO_quilt,
Functions/VCS_Info/VCS_INFO_set-patch-format: vcs_info
set-patch-format helper: Part #4.
* 40403/0003: Functions/VCS_Info/Backends/VCS_INFO_get_data_git,
Functions/VCS_Info/Backends/VCS_INFO_get_data_hg,
Functions/VCS_Info/VCS_INFO_quilt,

View file

@ -120,20 +120,18 @@ VCS_INFO_git_getbranch () {
}
VCS_INFO_git_handle_patches () {
local git_applied_s git_unapplied_s gitmsg git_all
local git_applied_s git_unapplied_s gitmsg
git_patches_applied=(${(Oa)git_patches_applied})
git_patches_unapplied=(${(Oa)git_patches_unapplied})
(( git_all = ${#git_patches_applied} + ${#git_patches_unapplied} ))
VCS_INFO_set-patch-format 'git_patches_applied' 'git_applied_s' \
'git_patches_unapplied' 'git_unapplied_s' \
":vcs_info:${vcs}:${usercontext}:${rrn}" gitmsg
hook_com=( applied "${git_applied_s}" unapplied "${git_unapplied_s}"
applied-n ${#git_patches_applied} unapplied-n ${#git_patches_unapplied} all-n ${git_all} )
if VCS_INFO_hook 'set-patch-format' "${gitmsg}"; then
zformat -f gitmisc "${gitmsg}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
"n:${#git_patches_applied}" "c:${#git_patches_unapplied}" "a:${git_all}"
"n:${#git_patches_applied}" "c:${#git_patches_unapplied}" \
"a:${hook_com[all-n]}"
else
gitmisc=${hook_com[patch-replace]}
fi

View file

@ -13,7 +13,7 @@ local hgbase bmfile branchfile rebasefile dirstatefile mqseriesfile \
hgbmstring hgmqstring applied_string unapplied_string guards_string
local -a hgid_args defrevformat defbranchformat \
hgbmarks mqpatches mqseries mqguards mqunapplied hgmisc \
hgbmarks mqpatches mqguards mqunapplied hgmisc \
i_patchguards i_negguards i_posguards
local -A hook_com
@ -175,9 +175,6 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
# Skip commented lines
[[ ${i_patch} == [[:space:]]#"#"* ]] && continue
# Keep list of all patches
mqseries+=( $i_patch )
# Separate negative and positive guards to more easily find the
# intersection of active guards with patch guards
i_patchguards=( ${(s: :)i_patchguards} )
@ -212,14 +209,12 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
guards_string=${hook_com[guards-string]}
fi
hook_com=( applied "${applied_string}" unapplied "${unapplied_string}"
applied-n ${#mqpatches} unapplied-n ${#mqunapplied} all-n ${#mqseries}
guards "${guards_string}" guards-n ${#mqguards} )
hook_com+=( guards "${guards_string}" guards-n ${#mqguards} )
if VCS_INFO_hook 'set-patch-format' ${qstring}; then
zformat -f hgmqstring "${hgmqstring}" \
"p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
"n:${#mqpatches}" "c:${#mqunapplied}" "a:${#mqseries}" \
"n:${#mqpatches}" "c:${#mqunapplied}" "a:${hook_com[all-n]}" \
"g:${hook_com[guards]}" "G:${#mqguards}"
else
hgmqstring=${hook_com[patch-replace]}

View file

@ -91,7 +91,7 @@ function VCS_INFO_quilt() {
local patches pc tmp qstring root
local -i ret
local context
local -a applied unapplied all applied_string unapplied_string quiltcommand quilt_env
local -a applied unapplied applied_string unapplied_string quiltcommand quilt_env
local -A hook_com
context=":vcs_info:${vcs}.quilt-${mode}:${usercontext}:${rrn}"
@ -171,17 +171,12 @@ function VCS_INFO_quilt() {
}
fi
all=( ${(Oa)applied} ${unapplied} )
VCS_INFO_set-patch-format 'applied' 'applied_string' \
'unapplied' 'unapplied_string' \
${context} qstring
hook_com=( applied "${applied_string}" unapplied "${unapplied_string}"
applied-n ${#applied} unapplied-n ${#unapplied} all-n ${#all} )
if VCS_INFO_hook 'set-patch-format' ${qstring}; then
zformat -f qstring "${qstring}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
"n:${#applied}" "c:${#unapplied}" "a:${#all}"
"n:${#applied}" "c:${#unapplied}" "a:${hook_com[all-n]}"
else
qstring=${hook_com[patch-replace]}
fi

View file

@ -8,6 +8,10 @@
# $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
#
# 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
@ -36,4 +40,12 @@
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]} ))
}