zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
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	[thread overview]
Message-ID: <1239039938-20782-4-git-send-email-ft@bewatermyfriend.org> (raw)
In-Reply-To: <1239039938-20782-1-git-send-email-ft@bewatermyfriend.org>

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


  parent reply	other threads:[~2009-04-06 17:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-06 17:45 PATCH: (0/5) Updates for vcs_info Frank Terbeck
2009-04-06 17:45 ` PATCH: (1/5) vcs_info: add revision and "misc" argument to VCS_INFO_formats() Frank Terbeck
2009-04-06 17:45 ` PATCH: (2/5) Add git's sha1 hash as revision information Frank Terbeck
2009-04-06 17:45 ` Frank Terbeck [this message]
2009-04-06 17:45 ` PATCH: (4/5) contrib.yo: updates for get-revision, %i and %m Frank Terbeck
2009-04-06 17:45 ` PATCH: (5/5) Make the hg backend work with new versions of mercurial Frank Terbeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1239039938-20782-4-git-send-email-ft@bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).