summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-10-04 18:18:12 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-10-04 18:18:12 +0000
commit179cd828a57c36f312ed7f95abf5e7d8d5fe44a2 (patch)
tree5e7019d246e4093cc233edc61cc3ce5e817d8761
parent500431077b5a8e9ba1af3e2cb87bae5d4701c799 (diff)
downloadzsh-179cd828a57c36f312ed7f95abf5e7d8d5fe44a2.tar.gz
zsh-179cd828a57c36f312ed7f95abf5e7d8d5fe44a2.zip
Lionel Flandrin: 27307: enhanced Mecurial VCS_INFO support
-rw-r--r--Doc/Zsh/contrib.yo24
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_hg30
2 files changed, 48 insertions, 6 deletions
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index feda95210..51a8e83bf 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -493,6 +493,13 @@ 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(hgrevformat)
+item(tt(hgrevformat))(
+tt(hg) uses both a hash and a revision number to reference a specific
+changeset in a repository. With this style you can format the revision
+string (see var(branchformat)) to include either of both. It's only
+useful when var(get-revision) is true.
+)
kindex(max-exports)
item(tt(max-exports))(
Defines the maximum number if
@@ -610,9 +617,10 @@ The default values for these styles in all contexts are:
startsitem()
sitem(tt(formats))(" (%s)-[%b|%a]-")
sitem(tt(actionformats))(" (%s)-[%b]-")
-sitem(tt(branchformat))("%b:%r" (for bzr, svn and svk))
+sitem(tt(branchformat))("%b:%r" (for bzr, svn, svk and hg))
sitem(tt(nvcsformats))("")
sitem(tt(stgitformat))(" %p (%c)")
+sitem(tt(hgrevformat))("%r:%h")
sitem(tt(max-exports))(2)
sitem(tt(enable))(ALL)
sitem(tt(disable))((empty list))
@@ -635,7 +643,8 @@ sitem(tt(%s))(The vcs in use (git, hg, svn etc.))
sitem(tt(%b))(Information about the current branch.)
sitem(tt(%a))(An identifier, that describes the action. Only makes sense in
actionformats.)
-sitem(tt(%i))(The current revision number or identifier.)
+sitem(tt(%i))(The current revision number or identifier. For tt(hg)
+the var(hgrevformat) style may be used to customize the output.)
sitem(tt(%c))(The string from the var(stagedstr) style if there are staged
changes in the repository.)
sitem(tt(%u))(The string from the var(unstagedstr) style if there are unstaged
@@ -648,7 +657,7 @@ 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 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
+topmost Mq patch applied (qtop) and the tt(git) backend replaces it
with the string from the var(stgitformat) style.)
endsitem()
@@ -656,7 +665,7 @@ In tt(branchformat) these replacements are done:
startsitem()
sitem(tt(%b))(the branch name)
-sitem(tt(%r))(the current revision number)
+sitem(tt(%r))(the current revision number or the var(hgrevformat) style for tt(hg))
endsitem()
In tt(stgitformat) these replacements are done:
@@ -666,6 +675,13 @@ sitem(tt(%p))(the name of the patch currently on top of the stack)
sitem(tt(%c))(the number of unapplied patches)
endsitem()
+In tt(hgrevformat) these replacements are done:
+
+startsitem()
+sitem(tt(%r))(the current revision number)
+sitem(tt(%h))(the hash identifier for the current resivion in short form)
+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/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index d83521b14..0b66463fa 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -3,7 +3,21 @@
## Distributed under the same BSD-ish license as zsh itself.
setopt localoptions NO_shwordsplit
-local file hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info
+local file hgbranch hgbranch_name hgbase hghash hglrev hgmisc r_branch r_info revformat
+
+VCS_INFO_hg_get_mq_top_patch () {
+ local patchdir=$1
+
+ if [[ -e "${patchdir}/status" ]]; then
+ local -a patches
+ patches=(${(f)"$(< "${patchdir}/status")"})
+ printf "%s" "${patches[-1]/[^:]*:/}"
+ return 0
+ fi
+
+ return 1
+}
+
hgbase=${vcs_comm[basedir]}
rrn=${hgbase:t}
@@ -34,6 +48,8 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
done
if [[ -n ${hglrev} ]] ; then
+ zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" hgrevformat revformat || revformat="%r:%h"
+ zformat -f hglrev "${revformat}" "r:${hglrev}" "h:${hghash}"
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat hgbranch || hgbranch="%b:%r"
zformat -f hgbranch "${hgbranch}" "b:${hgbranch_name}" "r:${hglrev}"
fi
@@ -41,5 +57,15 @@ else
hgbranch="${hgbranch_name}"
fi
-VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' "${hglrev}" "${hghash}"
+local patchdir=${hgbase}/.hg/patches/
+
+if [[ -d $patchdir ]] ; then
+ hgmisc=$(VCS_INFO_hg_get_mq_top_patch "${patchdir}")
+
+ hgmisc=${hgmisc:-"no patch applied"}
+else
+ hgmisc=''
+fi
+
+VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' "${hglrev}" "${hgmisc}"
return 0