Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: (3/5) Add information about hg's local revision number and the commit's hash
- X-seq: zsh-workers 26819
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: (3/5) Add information about hg's local revision number and the commit's hash
- Date: Mon, 6 Apr 2009 19:45:36 +0200
- In-reply-to: <1239039938-20782-1-git-send-email-ft@xxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <1239039938-20782-1-git-send-email-ft@xxxxxxxxxxxxxxxxxxx>
The local revision number is in %i and branchformat's %r (yes, the hg
backend has a branchformat now, but only if get-revision is set).
The commit's hash is in %m - the "misc" parameter to VCS_INFO_formats().
Example:
[snip]
autoload -Uz vcs_info; vcs_info
zstyle ':vcs_info:*' max-exports 2
zstyle ':vcs_info:*' formats '(%s)-[%b]-' '%m'
zstyle ':vcs_info:*' actionformats '(%s)-[%b|%a]-' '%m'
zstyle ':vcs_info:hg:*' get-revision true
function precmd() {
psvar=()
vcs_info
[[ -n "${vcs_info_msg_0_}" ]] && psvar[1]="${vcs_info_msg_0_}"
[[ -n "${vcs_info_msg_1_}" ]] && psvar[2]="${vcs_info_msg_1_}"
}
PS1='%~%(1v. %1v.)%# '
RPS1='%(2v.[%2v].)'
[snap]
---
Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 33 ++++++++++++++++++++--
1 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
index d70e03c..f8e21a9 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg
@@ -3,10 +3,37 @@
## Distributed under the same BSD-ish license as zsh itself.
setopt localoptions NO_shwordsplit
-local hgbranch hgbase
+local hgbranch hgbranch_name hgbase hghash hglrev r_branch r_info
hgbase=${vcs_comm[basedir]}
rrn=${hgbase:t}
-hgbranch=$(< ${hgbase}/.hg/branch)
-VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' '' ''
+hgbranch_name=$(< ${hgbase}/.hg/branch)
+
+hghash=''
+hglrev=''
+if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
+ # Calling the 'hg' program is quite a bit too slow for prompts.
+ # If there's a way around that, I'd be interested.
+ # Disabled by default anyway, so no harm done.
+
+ HGRCPATH="/dev/null" ${vcs_comm[cmd]} branches \
+ | while read -r r_branch r_info ; do
+ if [[ ${r_branch} == ${hgbranch_name} ]] ; then
+ match=()
+ : ${r_info/(#b)([^:]##):(*)}
+ hglrev=${match[1]}
+ hghash=${match[2]}
+ break
+ fi
+ done
+
+ if [[ -n ${hglrev} ]] ; then
+ zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat hgbranch || hgbranch="%b:%r"
+ zformat -f hgbranch "${hgbranch}" "b:${hgbranch_name}" "r:${hglrev}"
+ fi
+else
+ hgbranch="${hgbranch_name}"
+fi
+
+VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' '' "${hglrev}" "${hghash}"
return 0
--
1.6.2.1.136.g8e24
Messages sorted by:
Reverse Date,
Date,
Thread,
Author