Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: (2/5) Add git's sha1 hash as revision information
- X-seq: zsh-workers 26818
- From: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: (2/5) Add git's sha1 hash as revision information
- Date: Mon, 6 Apr 2009 19:45:35 +0200
- In-reply-to: <1239039938-20782-1-git-send-email-ft@xxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <1239039938-20782-1-git-send-email-ft@xxxxxxxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author