From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8841 invoked from network); 6 Apr 2009 17:47:04 -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:04 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 87463 invoked from network); 6 Apr 2009 17:46:33 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Apr 2009 17:46:32 -0000 Received: (qmail 609 invoked by alias); 6 Apr 2009 17:46:02 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26818 Received: (qmail 481 invoked from network); 6 Apr 2009 17:45:59 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 6 Apr 2009 17:45:59 -0000 Received: from smtprelay09.ispgateway.de (smtprelay09.ispgateway.de [80.67.29.23]) by bifrost.dotsrc.org (Postfix) with ESMTP id D71A382D4B6B for ; Mon, 6 Apr 2009 19:45:55 +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 1LqstK-0001Kq-W8 for zsh-workers@sunsite.dk; Mon, 06 Apr 2009 19:45:51 +0200 Received: from hawk by fsst.voodoo.lan with local (Exim 4.69) (envelope-from ) id 1Lqst8-0005Pr-W7 for zsh-workers@sunsite.dk; Mon, 06 Apr 2009 19:45:38 +0200 From: Frank Terbeck To: zsh-workers@sunsite.dk Subject: PATCH: (2/5) Add git's sha1 hash as revision information Date: Mon, 6 Apr 2009 19:45:35 +0200 Message-Id: <1239039938-20782-3-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 This does not mean, that the git backend supports a branchformat now. Most people probably don't care about the sha1, so its retrieval is even disabled by default. Still, I've seen people add such information to their prompts, so vcs_info can do that now, too. Example: [snip] autoload -Uz vcs_info; vcs_info zstyle ':vcs_info:*' max-exports 2 zstyle ':vcs_info:*' formats '(%s)-[%b]-' '%i' zstyle ':vcs_info:*' actionformats '(%s)-[%b|%a]-' '%i' zstyle ':vcs_info:git:*' 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_[1,8]}" } PS1='%~%(1v. %1v.)%# ' RPS1='%(2v.[%2v].)' [snap] --- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 745be34..faab2b8 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -3,7 +3,7 @@ ## Distributed under the same BSD-ish license as zsh itself. setopt localoptions extendedglob NO_shwordsplit -local gitdir gitbase gitbranch gitaction gitunstaged gitstaged +local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1 VCS_INFO_git_getaction () { local gitaction='' gitdir=$1 @@ -77,7 +77,7 @@ VCS_INFO_git_getbranch () { gitbranch="$(${(z)gitsymref} 2> /dev/null)" if [[ $? -ne 0 ]] ; then - gitbranch="$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)" + gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)" if [[ $? -ne 0 ]] ; then gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..." @@ -85,12 +85,21 @@ VCS_INFO_git_getbranch () { fi fi - printf '%s' "${gitbranch##refs/heads/}" + printf '%s' "${gitbranch}" return 0 } gitdir=${vcs_comm[gitdir]} gitbranch="$(VCS_INFO_git_getbranch ${gitdir})" +if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision && \ + [[ ${gitbranch} == refs/* ]] && \ + [[ -r "${gitdir}/${gitbranch}" ]] ; then + + gitsha1="${"$(< $gitdir/$gitbranch)"}" +else + gitsha1='' +fi +gitbranch="${gitbranch##refs/[^/]##/}" if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then return 1 @@ -108,5 +117,5 @@ VCS_INFO_adjust gitaction="$(VCS_INFO_git_getaction ${gitdir})" gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}} rrn=${gitbase:t} -VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" '' '' +VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" '' return 0 -- 1.6.2.1.136.g8e24