From a5417250d52320f25ffe9c2394a415013dbf03f0 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 19 Jun 2009 21:05:48 +0000 Subject: Frank Terbeck: 27049, 27050, 27051, 27052: VCS_INFO improvements --- Functions/VCS_Info/Backends/VCS_INFO_get_data_hg | 39 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'Functions/VCS_Info/Backends/VCS_INFO_get_data_hg') diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg index d70e03c00..d83521b14 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg @@ -3,10 +3,43 @@ ## Distributed under the same BSD-ish license as zsh itself. setopt localoptions NO_shwordsplit -local hgbranch hgbase +local file 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}" '' '' '' '' + +file="${hgbase}/.hg/branch" +if [[ -r ${file} ]] ; then + hgbranch_name=$(< ${file}) +else + hgbranch_name="default" +fi + +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 -- cgit 1.4.1