Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 8/9] vcs_info git: consider patches for rebase
- X-seq: zsh-workers 33153
- From: Marc Finet <m.dreadlock@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 8/9] vcs_info git: consider patches for rebase
- Date: Fri, 12 Sep 2014 23:30:42 +0200
- Cc: Marc Finet <m.dreadlock@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dXKayyyAOapWSq/SV0lxTEBaYOVejwtzvtJTJG+4YI4=; b=dvwQMXXqLX2Sppg0Ke/SMktyeQ5C27Me/bmMpjvNyGT4fLfTmbDzmoby0j/hBIA77t I+gBBrQrz8uXV2U+jg51StPzdZur+GqybI/nFV+jFZyY9GZTVyxHxye/mTg51LwpLzsL GARQhgVRzV/VGaDgs37sVxRIAquHYU2Rtb8s9tjQj4lL0ddjYAmCUS09Pb355wjtKRMR VSMMyCXyU+NIRO5OnAaV6qDwBxRr15pWIKvcer1XQgkqDNZS0diRXeDxqM7zyBHmT5k2 ax56eVpaReu5xCBwTSNZIUpx1i2iN19I6LjjH83HPmmkmcIshJgdbVU9zFfORyiFSa7a Oy0A==
- In-reply-to: <1410557443-24178-1-git-send-email-m.dreadlock@gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1410557443-24178-1-git-send-email-m.dreadlock@gmail.com>
Since a rebase contains a list of patches to re-apply, re-use the
facility for stgit to have the same mechanism.
The patch list given to the gen-{un,}applied-string hooks is an array
with the sha1 and the subject of the commit. On rebase merge, the
applied patches prior to current contains only a number and "?".
---
Doc/Zsh/contrib.yo | 14 +--
Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 116 ++++++++++++++--------
2 files changed, 81 insertions(+), 49 deletions(-)
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 1c1a66a..361e866 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -1296,10 +1296,10 @@ tt(formats) and tt(actionformats) and will be availabe in the global
tt(backend_misc) array as tt(${backend_misc[bookmarks]}).
)
item(tt(gen-applied-string))(
-Called in the tt(git) (with tt(stgit)), and tt(hg) (with tt(mq)) backends
-and in tt(quilt) support when the tt(applied-string) is generated; the
-tt(use-quilt) zstyle must be true for tt(quilt) (the tt(mq) and tt(stgit)
-backends are active by default).
+Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg)
+(with tt(mq)) backends and in tt(quilt) support when the tt(applied-string)
+is generated; the tt(use-quilt) zstyle must be true for tt(quilt) (the tt(mq)
+and tt(stgit) backends are active by default).
This hook gets the names of all applied patches which tt(vcs_info) collected
so far in the opposite order, which means that the first argument is the
@@ -1312,9 +1312,9 @@ tt(backend_misc) array as tt($backend_misc[patches]}); and it will be
available as tt(%p) in the tt(patch-format) and tt(nopatch-format) styles.
)
item(tt(gen-unapplied-string))(
-Called in the tt(git) (with tt(stgit)), and tt(hg) (with tt(mq)) backend
-and in tt(quilt) support when the tt(unapplied-string) is generated; the
-tt(get-unapplied) style must be true.
+Called in the tt(git) (with tt(stgit) or during rebase), and tt(hg) (with
+tt(mq)) backend and in tt(quilt) support when the tt(unapplied-string) is
+generated; the tt(get-unapplied) style must be true.
This hook gets the names of all unapplied patches which tt(vcs_info)
collected so far in the opposite order, which mean that the first argument is
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 188f204..a0fd85d 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -3,9 +3,9 @@
## Distributed under the same BSD-ish license as zsh itself.
setopt localoptions extendedglob NO_shwordsplit
-local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
-local stgitpatch stgitunapplied
+local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1 gitmisc
local -i querystaged queryunstaged
+local -a git_patches_applied git_patches_unapplied
local -A hook_com
VCS_INFO_git_getaction () {
@@ -113,6 +113,44 @@ VCS_INFO_git_getbranch () {
return 0
}
+VCS_INFO_git_handle_patches () {
+ local git_applied_s git_unapplied_s gitmsg git_all
+ git_patches_applied=(${(Oa)git_patches_applied})
+ 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=()
+ if VCS_INFO_hook 'gen-unapplied-string' "${git_patches_unapplied[@]}"; then
+ git_patches_unapplied=${#git_patches_unapplied}
+ else
+ git_patches_unapplied=${hook_com[unapplied-string]}
+ fi
+
+ if (( ${#git_patches_applied} )); then
+ zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" patch-format gitmsg || gitmsg="%p (%n applied)"
+ else
+ zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" nopatch-format gitmsg || gitmsg="no patch applied"
+ fi
+ hook_com=( applied "${git_applied_s}" unapplied "${git_patches_unapplied}"
+ 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}"
+ else
+ gitmisc=${hook_com[patch-replace]}
+ fi
+ hook_com=()
+}
+
gitdir=${vcs_comm[gitdir]}
VCS_INFO_git_getbranch ${gitdir}
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
@@ -157,52 +195,46 @@ fi
VCS_INFO_adjust
VCS_INFO_git_getaction ${gitdir}
+
+VCS_INFO_get_get_rebase()
+{
+ if [[ -f "$1" ]]; then
+ echo "$(< "$1")"
+ fi
+}
+
local patchdir=${gitdir}/patches/${gitbranch}
if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \
&& [[ -f $patchdir/unapplied ]]
then
- local -a stgit_applied stgit_unapplied stgit_all
-
- stgit_applied=(${(f)"$(< "${patchdir}/applied")"})
- stgit_applied=( ${(Oa)stgit_applied} )
- stgit_unapplied=(${(f)"$(< "${patchdir}/unapplied")"})
- stgit_unapplied=( ${(oa)stgit_unapplied} )
- stgit_all=( ${(Oa)stgit_applied} ${stgit_unapplied} )
-
- if VCS_INFO_hook 'gen-applied-string' "${stgit_applied[@]}"; then
- if (( ${#stgit_applied} )); then
- stgitpatch=${stgit_applied[1]}
- else
- stgitpatch=""
- fi
- else
- stgitpatch=${hook_com[applied-string]}
- fi
- hook_com=()
- if VCS_INFO_hook 'gen-unapplied-string' "${stgit_unapplied[@]}"; then
- stgitunapplied=${#stgit_unapplied}
- else
- stgitunapplied=${hook_com[unapplied-string]}
- fi
+ git_patches_applied=(${(f)"$(< "${patchdir}/applied")"})
+ git_patches_unapplied=(${(f)"$(< "${patchdir}/unapplied")"})
+ VCS_INFO_git_handle_patches
+elif [[ -d "${gitdir}/rebase-merge" ]]; then
+ patchdir="${gitdir}/rebase-merge"
+ local p
+ for p in ${(f)"$(< "${patchdir}/done")"}; do
+ # remove action
+ git_patches_applied+=("${${(s: :)p}[2,-1]}")
+ done
+ git_patches_unapplied=(${(f)"$(grep -v '^$' "${patchdir}/git-rebase-todo" | grep -v '^#')"})
+ VCS_INFO_git_handle_patches
+elif [[ -d "${gitdir}/rebase-apply" ]]; then
+ # Fake patch names for all but current patch
+ patchdir="${gitdir}/rebase-apply"
+ local cur=$(< "${patchdir}/next")
+ local p
+ for p in $(seq $(($cur - 1))); do
+ git_patches_applied+=("$(printf "%04d" $p) ?")
+ done
+ git_patches_applied+=("$(< "${patchdir}/original-commit") ${${(f)$(< "${patchdir}/msg-clean")}[1]}")
+ git_patches_unapplied=($(seq $cur $(< "${patchdir}/last")))
- if (( ${#stgit_applied} )); then
- zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" patch-format stgitmsg || stgitmsg="%p (%n applied)"
- else
- zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" nopatch-format stgitmsg || stgitmsg="no patch applied"
- fi
- hook_com=( applied "${stgitpatch}" unapplied "${stgitunapplied}"
- applied-n ${#stgit_applied} unapplied-n ${#stgit_unapplied} all-n ${#stgit_all} )
- if VCS_INFO_hook 'set-patch-format' "${stgitmsg}"; then
- zformat -f stgitmsg "${stgitmsg}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
- "n:${#stgit_applied}" "c:${#stgit_unapplied}" "a:${#stgit_all}"
- else
- stgitmsg=${hook_com[patch-replace]}
- fi
- hook_com=()
+ VCS_INFO_git_handle_patches
else
- stgitmsg=''
+ gitmisc=''
fi
-backend_misc[patches]="${stgitmsg}"
-VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" "${stgitmsg}"
+backend_misc[patches]="${gitmisc}"
+VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" "${gitmisc}"
return 0
--
2.1.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author