From: Frank Terbeck <ft@bewatermyfriend.org>
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 [thread overview]
Message-ID: <1239039938-20782-3-git-send-email-ft@bewatermyfriend.org> (raw)
In-Reply-To: <1239039938-20782-1-git-send-email-ft@bewatermyfriend.org>
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
next prev 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 ` Frank Terbeck [this message]
2009-04-06 17:45 ` PATCH: (3/5) Add information about hg's local revision number and the commit's hash Frank Terbeck
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-3-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).