about summary refs log tree commit diff
path: root/Functions/VCS_Info
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/VCS_Info')
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_git51
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_hg8
-rw-r--r--Functions/VCS_Info/VCS_INFO_formats2
-rw-r--r--Functions/VCS_Info/VCS_INFO_patch2subject2
-rw-r--r--Functions/VCS_Info/VCS_INFO_quilt54
-rw-r--r--Functions/VCS_Info/VCS_INFO_set-branch-format2
-rw-r--r--Functions/VCS_Info/VCS_INFO_set-patch-format10
-rwxr-xr-xFunctions/VCS_Info/test-repo-git-rebase-apply12
l---------Functions/VCS_Info/test-repo-git-rebase-merge1
9 files changed, 99 insertions, 43 deletions
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index eb04d4b41..9a608adab 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ VCS_INFO_git_handle_patches () {
     VCS_INFO_set-patch-format 'git_patches_applied' 'git_applied_s' \
                               'git_patches_unapplied' 'git_unapplied_s' \
                               ":vcs_info:${vcs}:${usercontext}:${rrn}" gitmsg \
-                              '' ''
+                              '' '' ''
     gitmisc=$REPLY
 }
 
@@ -184,18 +184,12 @@ fi
 VCS_INFO_adjust
 VCS_INFO_git_getaction ${gitdir}
 
-local patchdir=${gitdir}/patches/${gitbranch}
-if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \
-   && [[ -f $patchdir/unapplied ]]
-then
-    # stgit
-    git_patches_applied=(${(f)"$(< "${patchdir}/applied")"})
-    git_patches_unapplied=(${(f)"$(< "${patchdir}/unapplied")"})
-    VCS_INFO_git_handle_patches
-elif [[ -d "${gitdir}/rebase-merge" ]]; then
+local patchdir
+if [[ -d "${gitdir}/rebase-merge" ]]; then
     # 'git rebase -i'
     patchdir="${gitdir}/rebase-merge"
     local p
+    (( ${+functions[VCS_INFO_git_map_rebase_line_to_hash_and_subject]} )) ||
     VCS_INFO_git_map_rebase_line_to_hash_and_subject() {
         local p=$1
         unset REPLY
@@ -207,7 +201,7 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then
                 # Comment line.  Skip.
                 return 0
                 ;; 
-            ((p|pick|e|edit|r|reword|f|fixup|s|squash)' '*)
+            (''(p|pick|e|edit|r|reword|f|fixup|s|squash)' '*)
                 # The line is of the form "pick $hash $subject".
                 # Just strip the verb and we're good to go.
                 p=${p#* }
@@ -230,7 +224,7 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then
                         p="${p%% *} ?"
                 fi
                 ;;
-            ((x|exec) *)
+            (''(x|exec) *)
                 # The line is of the form 'exec foo bar baz' where 'foo bar
                 # baz' is a shell command.  There's no way to map _that_ to
                 # "$hash $subject", but I hope this counts as making an effort.
@@ -250,7 +244,9 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then
             (( $+REPLY )) && git_patches_applied+=( "$REPLY" )
         done
     fi
-    if [[ -f "${patchdir}/git-rebase-todo" ]] ; then
+    if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-unapplied &&
+       [[ -f "${patchdir}/git-rebase-todo" ]]
+    then
         for p in ${(f)"$(< "${patchdir}/git-rebase-todo")"}; do
             VCS_INFO_git_map_rebase_line_to_hash_and_subject "$p"
             (( $+REPLY )) && git_patches_unapplied+=( "$REPLY" )
@@ -380,7 +376,9 @@ elif [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]]; then
     # TODO: maybe read up to the first blank line
     IFS='' read -r subject < "${gitdir}/MERGE_MSG"
     git_patches_applied=( "$(<${gitdir}/CHERRY_PICK_HEAD) ${subject}" )
-    if [[ -f "${gitdir}/sequencer/todo" ]]; then
+    if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-unapplied &&
+       [[ -f "${gitdir}/sequencer/todo" ]]
+    then
         # Get the next patches, and remove the one that's in CHERRY_PICK_HEAD.
         git_patches_unapplied=( ${${(M)${(f)"$(<"${gitdir}/sequencer/todo")"}:#pick *}#pick } )
         git_patches_unapplied[1]=()
@@ -388,6 +386,31 @@ elif [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]]; then
         git_patches_unapplied=()
     fi
     VCS_INFO_git_handle_patches
+elif command -v stg >/dev/null &&
+        ${vcs_comm[cmd]} show-ref --quiet refs/stacks/${gitbranch} refs/heads/${gitbranch}.stgit 2>/dev/null &&
+        git_patches_applied=(${${(f)"$(stg series --noprefix --applied --description 2>/dev/null)"}/ #[#]})
+then
+    # Testing for StGit patches is done after testing for all git-proper
+    # patches/states. If a StGit user's repo is in one of those states, they
+    # will want to see that instead of the StGit patch info.
+
+    # Performance note: testing for the stg executable is done first because it
+    # is extremely cheap and there is nothing else to do if it isn't present.
+    # Using git to test whether a StGit stack is initialized is cheaper than
+    # running stg itself; especially for versions of StGit <= 2.0. Thus getting
+    # StGit patch info should only have a material runtime cost if StGit is
+    # installed and in-use for the current branch.
+
+    # In StGit >=1.2, the existence of refs/stacks/<branch> indicates StGit is
+    # initialized. In StGit >=0.15, it is refs/heads/<branch>.stgit.
+
+    # N.B. the "--noprefix" option is available in StGit 2.x as an alias for
+    # --no-prefix.  The former is compatible with StGit versions going back to
+    # 2008.
+    if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-unapplied; then
+        git_patches_unapplied=(${${(f)"$(stg series --noprefix --unapplied --description 2>/dev/null)"}/ #[#]})
+    fi
+    VCS_INFO_git_handle_patches
 else
     gitmisc=''
 fi
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index 2806aee1d..ea3798b81 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -14,7 +14,7 @@ local hgbase bmfile branchfile topicfile rebasefile dirstatefile mqseriesfile \
 
 local -a hgid_args defrevformat defbranchformat \
     hgbmarks mqpatches mqguards mqunapplied hgmisc \
-    i_patchguards i_negguards i_posguards
+    i_patch i_patchguards i_negguards i_posguards
 
 local -A hook_com
 
@@ -56,7 +56,6 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
         zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" \
             "check-for-changes" || hgid_args+=( -r. )
 
-        local HGPLAIN
         HGPLAIN=1 ${vcs_comm[cmd]} ${(z)hgid_args} 2> /dev/null \
             | read -r r_csetid r_lrev
     fi
@@ -184,6 +183,9 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
             # Skip commented lines
             [[ ${i_patch} == [[:space:]]#"#"* ]] && continue
 
+            # Skip applied patches
+            (( ${+mqpatches[(re)${i_patch}]} )) && continue
+
             # Separate negative and positive guards to more easily find the
             # intersection of active guards with patch guards
             i_patchguards=( ${(s: :)i_patchguards} )
@@ -226,7 +228,7 @@ if zstyle -T ":vcs_info:${vcs}:${usercontext}:${rrn}" get-mq \
     VCS_INFO_set-patch-format 'mqpatches' 'applied_string' \
                               'mqunapplied' 'unapplied_string' \
                               ":vcs_info:${vcs}:${usercontext}:${rrn}" hgmqstring \
-                              extra_hook_com VCS_INFO_hg_extra_zformats
+                              extra_hook_com VCS_INFO_hg_extra_zformats ''
     hgmqstring=$REPLY
 fi
 
diff --git a/Functions/VCS_Info/VCS_INFO_formats b/Functions/VCS_Info/VCS_INFO_formats
index e0e1dc738..daf169f26 100644
--- a/Functions/VCS_Info/VCS_INFO_formats
+++ b/Functions/VCS_Info/VCS_INFO_formats
@@ -28,7 +28,7 @@ hook_com=(
     vcs_orig      "${vcs}"
 )
 hook_com[base-name]="${${hook_com[base]}:t}"
-hook_com[base-name_orig]="${hook_com[base_name]}"
+hook_com[base-name_orig]="${hook_com[base-name]}"
 hook_com[subdir]="$(VCS_INFO_reposub ${hook_com[base]})"
 hook_com[subdir_orig]="${hook_com[subdir]}"
 
diff --git a/Functions/VCS_Info/VCS_INFO_patch2subject b/Functions/VCS_Info/VCS_INFO_patch2subject
index a467edcdb..5aa9efd23 100644
--- a/Functions/VCS_Info/VCS_INFO_patch2subject
+++ b/Functions/VCS_Info/VCS_INFO_patch2subject
@@ -1,3 +1,5 @@
+## vim:ft=zsh
+#
 # This function takes as an argument a filename of a patch and sets $REPLY to
 # a single-line "subject", or unsets it if no subject could be extracted.
 {
diff --git a/Functions/VCS_Info/VCS_INFO_quilt b/Functions/VCS_Info/VCS_INFO_quilt
index 264dbed0e..ce5b41f24 100644
--- a/Functions/VCS_Info/VCS_INFO_quilt
+++ b/Functions/VCS_Info/VCS_INFO_quilt
@@ -92,7 +92,7 @@ function VCS_INFO_quilt-patch2subject() {
     emulate -L zsh
     setopt extendedglob
     local mode="$1"
-    local patches pc tmp qstring root
+    local patches pc qstring root
     local -i ret
     local context
     local -a applied unapplied applied_string unapplied_string quiltcommand quilt_env
@@ -113,9 +113,12 @@ function VCS_INFO_quilt-patch2subject() {
         ;;
     esac
 
-    VCS_INFO_quilt-dirfind .pc .version
-    ret=$? pc=$REPLY
-    if (( ret == 0 )); then
+    # Look for the patches directory.
+    #
+    # 1. Check if there's a .pc/.version file in a parent dir.  If so, use the
+    # patches dir from the corresponding .pc/.quilt_patches.
+    if VCS_INFO_quilt-dirfind .pc .version; then
+        pc=$REPLY
         [[ ${quiltmode} == 'standalone' ]] && root=${pc}
         pc=${pc}/.pc
         if [[ -e ${pc}/applied-patches ]]; then
@@ -128,25 +131,27 @@ function VCS_INFO_quilt-patch2subject() {
         fi
         patches=$(<$pc/.quilt_patches)
         patches=`builtin cd -q "${pc:h}" && print -r - ${patches:P}`
+    # 2. Else, locate a patches dir using the style settings.
+    else
+        zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}"
+        : ${patches:="patches"}
+        if [[ "${patches}" != /* ]]; then
+            if VCS_INFO_quilt-dirfind "${patches}"; then
+                patches=$REPLY/$patches
+            else
+                return $?
+            fi
+        else
+            [[ -d ${patches} ]] || return 1
+        fi
+        quilt_env+=(QUILT_PATCHES="$patches")
     fi
+    # At this point, $patches is set and points to an existing directory.
+
     if zstyle -t "${context}" get-unapplied; then
         # This zstyle call needs to be moved further up if `quilt' needs
         # to be run in more places than this one.
         zstyle -s "${context}" quiltcommand quiltcommand || quiltcommand='quilt'
-        quilt_env=()
-        if [ -z "$patches" ]; then
-            zstyle -s "${context}" quilt-patch-dir patches || patches="${QUILT_PATCHES}"
-            if [[ "${patches}" != /* ]]; then
-                tmp=${patches:-patches}
-                VCS_INFO_quilt-dirfind "${tmp}"
-                ret=$? patches=$REPLY
-                (( ret )) && return ${ret}
-                patches=${patches}/${tmp}
-            else
-                [[ -d ${patches} ]] || return 1
-            fi
-            quilt_env+=(QUILT_PATCHES="$patches")
-        fi
         unapplied=( ${(f)"$(if (( $+quilt_env[1] )); then export ${quilt_env[@]}; fi
                             $quiltcommand --quiltrc /dev/null unapplied 2> /dev/null)"} )
         unapplied=( ${unapplied:#} )
@@ -154,8 +159,7 @@ function VCS_INFO_quilt-patch2subject() {
         unapplied=()
     fi
 
-    if [[ -n $patches ]]; then
-      () {
+    {
         local i
         for ((i=1; i<=$#applied; i++)); do
           if VCS_INFO_quilt-patch2subject "$patches/$applied[$i]" && (( $+REPLY ))
@@ -173,13 +177,17 @@ function VCS_INFO_quilt-patch2subject() {
             unapplied[$i]+=" ?"
           fi
         done
-      }
-    fi
+    }
+
+    typeset -A quilt_extra_info=(
+        quilt-patches-dir ${patches}
+        ${pc:+"quilt-pc-dir"} $pc
+    )
 
     VCS_INFO_set-patch-format 'applied' 'applied_string' \
                               'unapplied' 'unapplied_string' \
                               ${context} qstring \
-                              '' ''
+                              quilt_extra_info '' quilt_extra_info
     qstring=$REPLY
 
     case ${mode} in
diff --git a/Functions/VCS_Info/VCS_INFO_set-branch-format b/Functions/VCS_Info/VCS_INFO_set-branch-format
index 8cff51b9a..cbab60e29 100644
--- a/Functions/VCS_Info/VCS_INFO_set-branch-format
+++ b/Functions/VCS_Info/VCS_INFO_set-branch-format
@@ -1,3 +1,5 @@
+## vim:ft=zsh
+#
 # A function for calling the branch-format hook
 #
 # Return the value to use in REPLY
diff --git a/Functions/VCS_Info/VCS_INFO_set-patch-format b/Functions/VCS_Info/VCS_INFO_set-patch-format
index e387110a2..1c774a7f6 100644
--- a/Functions/VCS_Info/VCS_INFO_set-patch-format
+++ b/Functions/VCS_Info/VCS_INFO_set-patch-format
@@ -1,3 +1,5 @@
+## vim:ft=zsh
+#
 # This function is the common guts of the gen-applied-string /
 # gen-unapplied-string / set-patch-format dance of several backends.
 #
@@ -13,6 +15,8 @@
 # $7 - name of an assoc parameter with extra $hook_com key-value pairs for the
 #      set-patch-format hook invocation, or '' for none
 # $8 - name of a function that sets $reply to extra arguments for the patch-format zformat call, or '' for none
+# $9 - name of an assoc parameter with extra $hook_com key-value pairs for the
+#      gen-applied-string & gen-unapplied-string hook invocations, or '' for none
 #
 # The expanded patch-format string is returned in $REPLY.
 #
@@ -20,8 +24,10 @@
 # - $hook_com is overwritten and the keys 'applied', 'applied-n',
 #   'unapplied', 'unapplied-n', 'all-n' are set.
 {
+    hook_com=()
+
     local applied_needs_escaping='unknown'
-    local unapplied_needs_escaping='unknown'
+    hook_com+=( ${9:+"${(@kvP)9}"} )
     if VCS_INFO_hook 'gen-applied-string' "${(@P)1}"; then
         if (( ${(P)#1} )); then
             REPLY=${(P)1[1]}
@@ -35,6 +41,8 @@
     : ${(P)2::=$REPLY}
     hook_com=()
 
+    local unapplied_needs_escaping='unknown'
+    hook_com+=( ${9:+"${(@kvP)9}"} )
     if VCS_INFO_hook 'gen-unapplied-string' "${(@P)3}"; then
         REPLY=${(P)#3}
         unapplied_needs_escaping='yes'
diff --git a/Functions/VCS_Info/test-repo-git-rebase-apply b/Functions/VCS_Info/test-repo-git-rebase-apply
index cb4ea4f58..ce49690cd 100755
--- a/Functions/VCS_Info/test-repo-git-rebase-apply
+++ b/Functions/VCS_Info/test-repo-git-rebase-apply
@@ -44,6 +44,16 @@ append_lines 7 8 9
 # Specify a rebase that would create the history [1,3,4,5,6,7,8,9].
 # This will conflict because r7 depends on r2 which is not included.
 git checkout -b myref
-git rebase --onto=rebase_onto_this rebase_from_this myref
+case $0:P in
+    (*/test-repo-git-rebase-apply)
+        git rebase --onto=rebase_onto_this rebase_from_this myref
+        ;;
+    (*/test-repo-git-rebase-merge)
+        git -c core.editor=true rebase -i --onto=rebase_onto_this rebase_from_this myref
+        ;;
+    (*)
+        echo >&2 "$0: unrecognized basename"
+        ;;
+esac
 
 
diff --git a/Functions/VCS_Info/test-repo-git-rebase-merge b/Functions/VCS_Info/test-repo-git-rebase-merge
new file mode 120000
index 000000000..fce9e9178
--- /dev/null
+++ b/Functions/VCS_Info/test-repo-git-rebase-merge
@@ -0,0 +1 @@
+test-repo-git-rebase-apply
\ No newline at end of file