From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15167 invoked from network); 6 Apr 2009 17:47:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Apr 2009 17:47:22 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 87994 invoked from network); 6 Apr 2009 17:46:39 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Apr 2009 17:46:39 -0000 Received: (qmail 632 invoked by alias); 6 Apr 2009 17:46:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26819 Received: (qmail 527 invoked from network); 6 Apr 2009 17:46:00 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 6 Apr 2009 17:46:00 -0000 Received: from smtprelay09.ispgateway.de (smtprelay09.ispgateway.de [80.67.29.23]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5010F82D4B6A for ; Mon, 6 Apr 2009 19:45:57 +0200 (CEST) Received: from [89.245.57.95] (helo=fsst.voodoo.lan) by smtprelay09.ispgateway.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1LqstL-0001Lb-Bp for zsh-workers@sunsite.dk; Mon, 06 Apr 2009 19:45:52 +0200 Received: from hawk by fsst.voodoo.lan with local (Exim 4.69) (envelope-from ) id 1Lqst9-0005Pu-2P for zsh-workers@sunsite.dk; Mon, 06 Apr 2009 19:45:39 +0200 From: Frank Terbeck To: zsh-workers@sunsite.dk 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 Message-Id: <1239039938-20782-4-git-send-email-ft@bewatermyfriend.org> X-Mailer: git-send-email 1.6.2.1.136.g8e24 In-Reply-To: <1239039938-20782-1-git-send-email-ft@bewatermyfriend.org> References: <1239039938-20782-1-git-send-email-ft@bewatermyfriend.org> X-Df-Sender: 430444 X-Virus-Scanned: ClamAV 0.92.1/9207/Mon Apr 6 13:58:21 2009 on bifrost X-Virus-Status: Clean 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