summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/contrib.yo22
-rw-r--r--Etc/CONTRIBUTORS3
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_git47
4 files changed, 71 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index fed7e8bbb..8d4d6cc59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-05-22  Peter Stephenson  <pws@csr.com>
 
+	* 26982: Julien Langer: Doc/Zsh/contrib.yo,
+	Functions/VCS_Info/Backends/VCS_INFO_get_data_git: support stgit
+
 	* 26970: Greg Klanderman: Completion/Unix/Command/_subversion: fix
 	caching.
 
@@ -11753,5 +11756,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4695 $
+* $Revision: 1.4696 $
 *****************************************************
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 620aaea3d..4131d6645 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -486,6 +486,13 @@ want var(vcs_info) to completely take over the generation of your prompt.
 You would do something like tt(PS1='${vcs_info_msg_0_}') to accomplish
 that.
 )
+kindex(stgitformat)
+item(tt(stgitformat))(
+The tt(git) backend replaces var(%m) in the formats and
+actionformats styles with tt(stgit)-specific information for
+tt(stgit)-initialized branches. This style let's you modify how that string
+should look like.
+)
 kindex(max-exports)
 item(tt(max-exports))(
 Defines the maximum number if
@@ -605,6 +612,7 @@ sitem(tt(formats))(" (%s)-[%b|%a]-")
 sitem(tt(actionformats))(" (%s)-[%b]-")
 sitem(tt(branchformat))("%b:%r" (for bzr, svn and svk))
 sitem(tt(nvcsformats))("")
+sitem(tt(stgitformat))(" %p (%c)")
 sitem(tt(max-exports))(2)
 sitem(tt(enable))(ALL)
 sitem(tt(disable))((empty list))
@@ -638,9 +646,10 @@ var(repoXY).)
 sitem(tt(%S))(subdirectory within a repository. If tt($PWD) is
 var(/foo/bar/reposXY/beer/tasty), tt(%S) is var(beer/tasty).)
 sitem(tt(%m))(A "misc" replacement. It is at the discretion of the backend
-to decide what this replacement expands to. It is currently used only by
-the tt(hg) backend. The hg backend replaces tt(%m) with the global hash
-value of the current revision.)
+to decide what this replacement expands to. It is currently used by
+the tt(hg) and tt(git) backends. The tt(hg) backend replaces tt(%m) with the
+global hash value of the current revision and the tt(git) backend replaces it
+with the string from the var(stgitformat) style.)
 endsitem()
 
 In tt(branchformat) these replacements are done:
@@ -650,6 +659,13 @@ sitem(tt(%b))(the branch name)
 sitem(tt(%r))(the current revision number)
 endsitem()
 
+In tt(stgitformat) these replacements are done:
+
+startsitem()
+sitem(tt(%p))(the name of the patch currently on top of the stack)
+sitem(tt(%c))(the number of unapplied patches)
+endsitem()
+
 Not all vcs backends have to support all replacements. For tt(nvcsformats)
 no replacements are performed at all. It is just a string.
 
diff --git a/Etc/CONTRIBUTORS b/Etc/CONTRIBUTORS
index 85e338091..72d798511 100644
--- a/Etc/CONTRIBUTORS
+++ b/Etc/CONTRIBUTORS
@@ -26,7 +26,8 @@ R. Ramkumar, François Revol, Bart Schaefer, Tomáš Smetana, Joerg
 Sonnenberger, Peter Stephenson, Jon Strait, Takimoto Jun, River Tarnell,
 Frank Terbeck, Philippe Troin, Geoff Wing, Matt Wozniski.
 
-The VCS_Info function system was written by Frank Terbeck.
+The VCS_Info function system was written by Frank Terbeck with
+contributions from Julien Langer.
 
 Contributors to completion and other shell functions include those above
 plus Nuno Alexandre, Ralph Amissah, Micah Anderson, arno, Frank Benkstein,
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index faab2b88a..a536165e1 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -89,6 +89,36 @@ VCS_INFO_git_getbranch () {
     return 0
 }
 
+VCS_INFO_git_get_stgit_top_patch () {
+    local patchdir=$1
+
+    if [[ -d "$patchdir" ]]; then
+        local -a patches
+        patches=(${(f)"$(< "${patchdir}/applied")"})
+        printf '%s' $patches[-1]
+        return 0
+    fi
+
+    return 1
+}
+
+VCS_INFO_git_get_stgit_unapplied() {
+    local patchdir=$1
+
+    if [[ -d "$patchdir" ]]; then
+        local -a patches
+        patches=(${(f)"$(< "${patchdir}/unapplied")"})
+        if [[ -z $patches[@] ]]; then
+            printf 0
+        else
+            printf '%d' $#patches
+        fi
+        return 0
+    fi
+
+    return 1
+}
+
 gitdir=${vcs_comm[gitdir]}
 gitbranch="$(VCS_INFO_git_getbranch ${gitdir})"
 if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision && \
@@ -117,5 +147,20 @@ VCS_INFO_adjust
 gitaction="$(VCS_INFO_git_getaction ${gitdir})"
 gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
 rrn=${gitbase:t}
-VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" ''
+
+local patchdir=${gitdir}/patches/${gitbranch}
+if [[ -d $patchdir ]] ; then
+    stgitpatch=$(VCS_INFO_git_get_stgit_top_patch "${patchdir}")
+    stgitunapplied=$(VCS_INFO_git_get_stgit_unapplied "${patchdir}")
+
+    stgitpatch=${stgitpatch:-"no patch applied"}
+
+    zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" stgitformat stgitmsg || stgitmsg=" %p (%c)"
+    zformat -f stgitmsg "${stgitmsg}" "p:${stgitpatch}" "c:${stgitunapplied}"
+    gitmisc=${stgitmsg}
+else
+    gitmisc=''
+fi
+
+VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" "${gitmisc}"
 return 0