summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2017-01-23 18:15:35 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2017-01-25 04:22:30 +0000
commit0ea1957608a6b496fc244078ce9e24f00327aba9 (patch)
tree860183613739ec834e774961f2fb0799ab690c9f /Functions
parent57013f8b96520057fda4b0d5057646c83465d1b6 (diff)
downloadzsh-0ea1957608a6b496fc244078ce9e24f00327aba9.tar.gz
zsh-0ea1957608a6b496fc244078ce9e24f00327aba9.tar.xz
zsh-0ea1957608a6b496fc244078ce9e24f00327aba9.zip
40403/0001: vcs_info set-patch-format helper: Part #1.
Diffstat (limited to 'Functions')
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_git11
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_hg9
-rw-r--r--Functions/VCS_Info/VCS_INFO_quilt11
-rw-r--r--Functions/VCS_Info/VCS_INFO_set-patch-format20
-rw-r--r--Functions/VCS_Info/vcs_info1
5 files changed, 24 insertions, 28 deletions
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 69ed24a2c..9e0749cf5 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -125,16 +125,7 @@ VCS_INFO_git_handle_patches () {
     git_patches_unapplied=(${(Oa)git_patches_unapplied})
     (( git_all = ${#git_patches_applied} + ${#git_patches_unapplied} ))
 
-    if VCS_INFO_hook 'gen-applied-string' "${git_patches_applied[@]}"; then
-        if (( ${#git_patches_applied} )); then
-            git_applied_s=${git_patches_applied[1]}
-        else
-            git_applied_s=""
-        fi
-    else
-        git_applied_s=${hook_com[applied-string]}
-    fi
-    hook_com=()
+    VCS_INFO_set-patch-format 'git_patches_applied' 'git_applied_s'
     if VCS_INFO_hook 'gen-unapplied-string' "${git_patches_unapplied[@]}"; then
         git_unapplied_s=${#git_patches_unapplied}
     else
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index 69b7db304..19bec7af1 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -203,14 +203,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
         done < ${mqseriesfile}
     fi
 
-    if VCS_INFO_hook 'gen-applied-string' "${mqpatches[@]}"; then
-        (( ${#mqpatches} )) && applied_string=${mqpatches[1]}
-    else
-        applied_string=${hook_com[applied-string]}
-    fi
-
-    hook_com=()
-
+    VCS_INFO_set-patch-format 'mqpatches' 'applied_string'
     if VCS_INFO_hook 'gen-unapplied-string' "${mqunapplied[@]}"; then
         unapplied_string=${#mqunapplied}
     else
diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt
index 4c61506cd..dd3f4959b 100644
--- a/Functions/VCS_Info/VCS_INFO_quilt
+++ b/Functions/VCS_Info/VCS_INFO_quilt
@@ -173,16 +173,7 @@ function VCS_INFO_quilt() {
 
     all=( ${(Oa)applied} ${unapplied} )
 
-    if VCS_INFO_hook 'gen-applied-string' "${applied[@]}"; then
-        if (( ${#applied} )); then
-            applied_string=${applied[1]}
-        else
-            applied_string=""
-        fi
-    else
-        applied_string=${hook_com[applied-string]}
-    fi
-    hook_com=()
+    VCS_INFO_set-patch-format 'applied' 'applied_string' 
     if VCS_INFO_hook 'gen-unapplied-string' "${unapplied[@]}"; then
         unapplied_string="${#unapplied}"
     else
diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format
new file mode 100644
index 000000000..310df9625
--- /dev/null
+++ b/Functions/VCS_Info/VCS_INFO_set-patch-format
@@ -0,0 +1,20 @@
+# 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
+{
+    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=()
+}
diff --git a/Functions/VCS_Info/vcs_info b/Functions/VCS_Info/vcs_info
index 24ae98e52..4e9ac6c6a 100644
--- a/Functions/VCS_Info/vcs_info
+++ b/Functions/VCS_Info/vcs_info
@@ -21,6 +21,7 @@ static_functions=(
     VCS_INFO_get_cmd
     VCS_INFO_hexdump
     VCS_INFO_hook
+    VCS_INFO_set-patch-format
     VCS_INFO_maxexports
     VCS_INFO_nvcsformats
     VCS_INFO_patch2subject