From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7935 invoked by alias); 2 Jun 2014 13:00:43 -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: 32662 Received: (qmail 19987 invoked from network); 2 Jun 2014 13:00:40 -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:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=mesmtp; bh= U3FECy/e6KydIQrW/xBUEeeissI=; b=gv8STUMVfpSeg8M3BRMqB+u5GN8GwOEU XiCnnPqcSIC67RxWZHmSpXhGGo0IUPzw5CXLnXAj1J2uMDG1WDHLtxXnG7s6uelg 6s43w/jpXZXkzceFx8ACmgC+/L4J9EsKIz1Jbir9bx/lcEgjmmoqCZOBlXDicbcG ZJySkMmtKHI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=smtpout; bh=U3FECy/e6KydIQrW/xBUEeeissI=; b=kndAcaojVEZMe2Jb9dx/p0pv9ZVn r+UOuPmE1Y80Qdq3eXlsgLuMHbI/wWSn61U7R+/GGFCTTucm4G7ES5HPXapuD366 VCj1KDxrulAcweoq1cojOvZ09VDnLbGRmSpbQkGeYa/EiV0MwB7hcef9qfY3Vz+u mDWjThk8vwx8wrU= X-Sasl-enc: Gc+QMULiU6NlsXcCTnIDFJ1PQBHfKh99iuh/ezU4UZ7p 1401714031 Date: Mon, 2 Jun 2014 13:00:28 +0000 From: Daniel Shahaf To: Frank Terbeck Cc: zsh-workers@zsh.org Subject: Re: [PATCH] vcs_info git: Fix stagedstr for empty repos Message-ID: <20140602130028.GD1871@tarsus.local2> References: <20140601022653.GE1820@tarsus.local2> <87vbsj4tk1.fsf@ft.bewatermyfriend.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8GpibOaaTibBMecb" Content-Disposition: inline In-Reply-To: <87vbsj4tk1.fsf@ft.bewatermyfriend.org> User-Agent: Mutt/1.5.21 (2010-09-15) --8GpibOaaTibBMecb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Frank Terbeck wrote on Mon, Jun 02, 2014 at 10:14:22 +0200: > Hello Daniel, > > Daniel Shahaf wrote: > > vcs_info git false-negatives to detect staged changes in a repository that has > > no commits. Attached a patch for that. > > Great! > > > The patch includes two variants for computing the "has staged changes?" bit in > > empty repositories: one via 'git ls-files' and one via git's empty tree. > > > > - The output of ls-files isn't O(1), but I tested with a 3000-file tree and > > didn't notice a slowdown, so I suppose it's acceptable. > > > > - 'diff-index --cached --quiet $empty_tree' is an O(1) operation, but I am not > > sure whether it is forwards compatible with future versions of Git, i.e., > > whether it's a hack that happens to work or a legitimate use of git's API. > > > > WDYT? > > I'm with Aaron on this one. IIRC, git uses the diff-index command in > various places, so I don't think it'll be removed anytime soon. My concern was not with using diff-index but with using the empty tree. Since Aaron says using it would be robust, let's just use it. Attached. > If you don't want the second variant to be forgotten, you can always put > it into the change's commit message. But in the code I'd just use the > variant that you think is faster (if only theoretically). It's mentioned in this thread, good enough for me. Daniel --8GpibOaaTibBMecb Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0002-vcs_info-git-Fix-stagedstr-for-empty-repos.patch" >>From 9797a5a46403ab7c60b4ee06aab27c65e7d4c75a Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Fri, 30 May 2014 23:50:55 +0000 Subject: [PATCH 2/2] vcs_info git: Fix stagedstr for empty repos In empty repositories, HEAD is an unresolvable symbolic ref. Start computing stagedstr/unstagedstr in that case; for the former, use a different method than the non-empty-repository case. --- Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 14 ++++++++++---- 1 file changed, 10 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 a48dc39..76ab92f 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -128,16 +128,22 @@ elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-change querystaged=1 fi if (( querystaged || 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 + [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then # Default: off - these are potentially expensive on big repositories if (( queryunstaged )) ; then ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code || gitunstaged=1 fi if (( querystaged )) ; then - ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null - (( $? && $? != 128 )) && gitstaged=1 + if ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then + ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null + (( $? && $? != 128 )) && gitstaged=1 + else + # empty repository (no commits yet) + # 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is the git empty tree. + ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules 4b825dc642cb6eb9a060e54bf8d69288fbee4904 2>/dev/null + (( $? && $? != 128 )) && gitstaged=1 + fi fi fi -- 1.7.10.4 --8GpibOaaTibBMecb--