Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Updated StGit patch detection in vcs_info



The vcs_info patch detection code attempted to interrogate StGit patch
stack state by inspecting .git/patches/applied and
.git/patches/unapplied. As of StGit 1.0, StGit stack and patch state is
no longer maintained via files in the .git/ directory, but is instead
captured in the repo's object database, accessible via the
refs/stacks/<branch> reference.

Thus zsh's approach for interrogating StGit patch state is long
obsoleted.

This patch updates vcs_info to use StGit's prescribed interface for
interrogating applied and unapplied patch state: the `stg series` command.
This approach will work with effectively all versions of StGit, pre-1.0,
1.x, and 2.x.

The new test for StGit patches is moved to the end of the if/elif chain
that also tests for git rebase, merge, and cherrypick states. If any of
those operations are in progress, a StGit user will want to know about that
instead of the StGit stack state.

N.B. it may be possible for vcs_info to interrogate StGit stack state
in a faster manner by probing the filesystem and git object database
directly instead of executing `stg series`, but this would require vcs_info
to have knowledge of StGit internals across many versions.

Signed-off-by: Peter Grayson <pete@xxxxxxxxxxxxx>
---
 .../VCS_Info/Backends/VCS_INFO_get_data_git    | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index e45eebc8e..9edc2d140 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -184,15 +184,8 @@ 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
@@ -389,6 +382,13 @@ elif [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]]; then
         git_patches_unapplied=()
     fi
     VCS_INFO_git_handle_patches
+elif git_patches_applied=(${(f)"$(stg series --noprefix --applied 2>/dev/null)"}); then
+    # 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 2>/dev/null)"})
+    fi
+    VCS_INFO_git_handle_patches
 else
     gitmisc=''
 fi
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author