Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 2/3] vcs_info: Deduplicate calling the set-branch-format hook.
- X-seq: zsh-workers 45626
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 2/3] vcs_info: Deduplicate calling the set-branch-format hook.
- Date: Thu, 26 Mar 2020 01:32:50 +0000
- In-reply-to: <20200326013251.21505-1-danielsh@tarpaulin.shahaf.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20200326013251.21505-1-danielsh@tarpaulin.shahaf.local2>
---
svk and p4 are untested.
.../VCS_Info/Backends/VCS_INFO_get_data_bzr | 11 ++--------
.../VCS_Info/Backends/VCS_INFO_get_data_p4 | 10 ++-------
.../VCS_Info/Backends/VCS_INFO_get_data_svk | 10 ++-------
.../VCS_Info/Backends/VCS_INFO_get_data_svn | 10 ++-------
Functions/VCS_Info/VCS_INFO_set-branch-format | 22 +++++++++++++++++++
Functions/VCS_Info/vcs_info | 1 +
6 files changed, 31 insertions(+), 33 deletions(-)
create mode 100644 Functions/VCS_Info/VCS_INFO_set-branch-format
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
index b30e0e12b..f1f5527e8 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr
@@ -100,14 +100,7 @@ else
fi
rrn=${bzrbase:t}
-zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat bzrbr || bzrbr="%b:%r"
-hook_com=( branch "${bzrinfo[2]}" revision "${bzrinfo[1]}" )
-if VCS_INFO_hook 'set-branch-format' "${bzrbr}"; then
- zformat -f bzrbr "${bzrbr}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
-else
- bzrbr=${hook_com[branch-replace]}
-fi
-hook_com=()
-
+VCS_INFO_set-branch-format "${bzrinfo[2]}" "${bzrinfo[1]}" &&
+ bzrbr="${REPLY}"
VCS_INFO_formats '' "${bzrbr}" "${bzrbase}" '' "${bzr_changes}" "${bzrinfo[1]}" "${bzr_changes}"
return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4 b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
index 815924c26..e8a08a663 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_p4
@@ -18,13 +18,7 @@ local p4branch change
# I suppose the following might be slow on a tortuous client view.
change="${${$(${vcs_comm[cmd]} changes -m 1 ...\#have)##Change }%% *}"
rrn=${p4base:t}
-zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat p4branch || p4branch="%b:%r"
-hook_com=( branch "${p4info[Client_name]}" revision "${change}" )
-if VCS_INFO_hook 'set-branch-format' "${p4branch}"; then
- zformat -f p4branch "${p4branch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
-else
- p4branch=${hook_com[branch-replace]}
-fi
-hook_com=()
+VCS_INFO_set-branch-format "${p4info[Client_name]}" "${change}" &&
+ p4branch="${REPLY}"
VCS_INFO_formats '' "${p4branch}" "${p4base}" '' '' "$change" ''
return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
index 1d2d22ffb..149e30222 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svk
@@ -8,13 +8,7 @@ local -A hook_com
svkbase=${vcs_comm[basedir]}
rrn=${svkbase:t}
-zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svkbranch || svkbranch="%b:%r"
-hook_com=( branch "${vcs_comm[branch]}" revision "${vcs_comm[revision]}" )
-if VCS_INFO_hook 'set-branch-format' "${svkbranch}"; then
- zformat -f svkbranch "${svkbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
-else
- svkbranch=${hook_com[branch-replace]}
-fi
-hook_com=()
+VCS_INFO_set-branch-format "${vcs_comm[branch]}" "${vcs_comm[revision]}" &&
+ svkbranch="${REPLY}"
VCS_INFO_formats '' "${svkbranch}" "${svkbase}" '' '' "${vcs_comm[revision]}" ''
return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index 21590addd..6fbd673a7 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -60,13 +60,7 @@ else
fi
rrn=${svnbase:t}
-zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
-hook_com=( branch "${svninfo[URL]##*/}" revision "${cwdinfo[Revision]}" )
-if VCS_INFO_hook 'set-branch-format' "${svnbranch}"; then
- zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
-else
- svnbranch=${hook_com[branch-replace]}
-fi
-hook_com=()
+VCS_INFO_set-branch-format "${svninfo[URL]##*/}" "${cwdinfo[Revision]}" &&
+ svnbranch="${REPLY}"
VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${cwdinfo[Revision]}" ''
return 0
diff --git a/Functions/VCS_Info/VCS_INFO_set-branch-format b/Functions/VCS_Info/VCS_INFO_set-branch-format
new file mode 100644
index 000000000..8cff51b9a
--- /dev/null
+++ b/Functions/VCS_Info/VCS_INFO_set-branch-format
@@ -0,0 +1,22 @@
+# A function for calling the branch-format hook
+#
+# Return the value to use in REPLY
+#
+# Parameters:
+readonly branch=$1
+readonly revision=$2
+#
+
+[[ -n $rrn ]] || return 1
+local -A hook_com
+local branchformat
+
+zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat branchformat || branchformat="%b:%r"
+hook_com=( branch "${branch}" revision "${revision}" )
+if VCS_INFO_hook 'set-branch-format' "${branchformat}"; then
+ zformat -f REPLY "${branchformat}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+else
+ REPLY=${hook_com[branch-replace]}
+fi
+hook_com=()
+return 0
diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index 9f48bee75..786b61918 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -22,6 +22,7 @@ static_functions=(
VCS_INFO_hexdump
VCS_INFO_hook
VCS_INFO_set-patch-format
+ VCS_INFO_set-branch-format
VCS_INFO_maxexports
VCS_INFO_nvcsformats
VCS_INFO_patch2subject
Messages sorted by:
Reverse Date,
Date,
Thread,
Author