From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4260 invoked by alias); 29 Mar 2014 09:59:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32508 Received: (qmail 22340 invoked from network); 29 Mar 2014 09:58:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:subject:message-id :mime-version:content-type; s=mesmtp; bh=ZnMvmJT2FHDekztM0x3aP0r W1Tk=; b=NQDFkY2ENNjbRo4CchCHqi/WDiCteWIp0+LDeVfcYp3pqeviez9oA8L q7inGBexPpuMcM4IId4LZNeQ6ojuMKBbmAHUqwQihPIysPdEA2Sf9Mx/GgX2yY6r s1UvokSTTjNpxwf9uezr2wcE6RPr0VfwUI6Z1uZkgPpFRpSLaZ1g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:subject:message-id :mime-version:content-type; s=smtpout; bh=ZnMvmJT2FHDekztM0x3aP0 rW1Tk=; b=YQtHRmH0s/FmtxBSMeu1wI5IC8pUU4BxoQdPg26wyKAOHBpL3qnXaz M3whf/yUgPnSmZX2Hg8sRInL+YLo6iRK15md2Ig/60ifGV/OaY0ie2WCbVZY5Fv3 riTcb5pWbjGxxgaNrOtuxgFcgnA7mDMhjAOZoGca4dzGc+8SRSCAU= X-Sasl-enc: 7cZYQAPmElCnlziddP5Kczi2d22Uw2w9F/ZRQCDQqsHZ 1396086592 Date: Sat, 29 Mar 2014 09:49:49 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] vcs_info: git: Support stagedstr(%c) without unstagedstr(%u) Message-ID: <20140329094949.GB11569@tarsus.local2> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello. I'd like to have my prompt alert me when I have staged changes (because it's a pain to keep running 'git diff --staged' before every 'git commit -a'). However, I don't want to enable detection of unstaged changes too as that's more expensive (disk crawl v. metadata crawl). Put another way, I want to have %c/stagedstr without the cost of %u/unstagestr. The current code makes detection of %u,%c an all-or-nothing deal: # excerpt from Functions/VCS_Info/Backends/VCS_INFO_get_data_git if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && ... ; then # Default: off - these are potentially expensive on big repositories ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code || gitunstaged=1 ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null (( $? && $? != 128 )) && gitstaged=1 fi I went ahead and implemented a way to enable %c without %u, specifically by adding a 'check-for-staged-changes' style that sets %c but not %u and leaving 'check-for-changes' unchanged (sets both %c and %u). See attached patch. WDYT? Daniel --- Recipe for testing: zsh -f cd $MY_ZSH_SOURCE_DIR zstyle ':vcs_info:git:*' stagedstr '[+]' zstyle ':vcs_info:git:*' check-for-staged-changes true zstyle ':vcs_info:git:*' formats '%b%c' fpath=( $PWD/Functions/**/*(/) ) autoload -Uz vcs_info _precmd_vcs_info() { vcs_info; print -P ${vcs_info_msg_0_} } precmd_functions+=(_precmd_vcs_info) git rm --quiet -- README git checkout HEAD -- README # Observe the last two prompts. --DocE+STaALJfprDB Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0003-vcs_info-Add-check-for-staged-changes.patch" >>From 8274b8113f0b4c17f9fd2532dc58db7b82042c1d Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 28 Mar 2014 11:00:35 +0000 Subject: [PATCH 3/3] vcs_info: Add check-for-staged-changes --- Completion/Zsh/Command/_zstyle | 2 ++ Doc/Zsh/contrib.yo | 13 +++++++++++++ Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr | 2 ++ Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 21 ++++++++++++++++----- Misc/vcs_info-examples | 4 ++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle index 708c0fd..eb27117 100644 --- a/Completion/Zsh/Command/_zstyle +++ b/Completion/Zsh/Command/_zstyle @@ -182,6 +182,8 @@ styles=( disable v:vcs disable-patterns v: check-for-changes v:bool + check-for-staged-changes + v:bool stagedstr v: unstagedstr v: command v:_command_names diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 76f456a..01d5b6a 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -837,6 +837,18 @@ Note, the actions taken if this style is enabled are potentially expensive (read: they may be slow, depending on how big the current repository is). Therefore, it is disabled by default. ) +kindex(check-for-staged-changes) +item(tt(check-for-staged-changes))( +This style is like tt(check-for-changes), but it never checks the worktree +files, only the metadata in the tt(.${vcs}) dir. Therefore, +this style initializes only the tt(%c) escape (with tt(stagedstr)) but +not the tt(%u) escape. This style is faster than tt(check-for-changes). + +In the tt(git) backend, this style checks for changes in the index. +Other backends do not currently implement this style. + +This style is disabled by default. +) kindex(stagedstr) item(tt(stagedstr))( This string will be used in the tt(%c) escape if there are staged changes in @@ -941,6 +953,7 @@ sitem(tt(enable))(ALL) sitem(tt(disable))((empty list)) sitem(tt(disable-patterns))((empty list)) sitem(tt(check-for-changes))(false) +sitem(tt(check-for-staged-changes))(false) sitem(tt(stagedstr))((string: "S")) sitem(tt(unstagedstr))((string: "U")) sitem(tt(command))((empty string)) diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr index 6e96ece..3198915 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_bzr @@ -11,6 +11,8 @@ local -xA hook_com bzr_info VCS_INFO_bzr_get_info() { bzrinfo=( ${(s.:.)$( ${vcs_comm[cmd]} version-info --custom \ --template="{revno}:{branch_nick}:{clean}")} ) + # TODO: document in zshcontrib that bzr supports check-for-changes + # (also in VCS_INFO_bzr_get_info_restricted) if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" then VCS_INFO_bzr_get_changes diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index e6791cb..abe388b 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -5,6 +5,7 @@ setopt localoptions extendedglob NO_shwordsplit local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1 local stgitpatch stgitunapplied +local querystaged queryunstaged local -A hook_com VCS_INFO_git_getaction () { @@ -120,14 +121,24 @@ if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then return 1 fi -if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \ +if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then + querystaged=1 + queryunstaged=1 +elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-changes" ; then + querystaged=1 +fi +if [[ -n $querystaged || -n $queryunstaged ]] && \ [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-git-dir 2> /dev/null)" != 'true' ]] && \ ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then # Default: off - these are potentially expensive on big repositories - ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code || - gitunstaged=1 - ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null - (( $? && $? != 128 )) && gitstaged=1 + if [[ -n $queryunstaged ]] ; then + ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code || + gitunstaged=1 + fi + if [[ -n $querystaged ]] ; then + ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null + (( $? && $? != 128 )) && gitstaged=1 + fi fi VCS_INFO_adjust diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples index b07bfc6..5d8ff18 100644 --- a/Misc/vcs_info-examples +++ b/Misc/vcs_info-examples @@ -266,6 +266,10 @@ autoload -Uz vcs_info zstyle ':vcs_info:*' check-for-changes true zstyle ':vcs_info:*' get-revision true +# Alternatively, the following would set only %c, but is faster: +#zstyle ':vcs_info:*' check-for-changes false +#zstyle ':vcs_info:*' check-for-staged-changes true + # Default to running vcs_info. If possible we prevent running it later for # speed reasons. If set to a non empty value vcs_info is run. -- 1.7.10.4 --DocE+STaALJfprDB--