From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17895 invoked by alias); 22 Mar 2010 02:30:42 -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: 27817 Received: (qmail 9732 invoked from network); 22 Mar 2010 02:30:40 -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=AWL,BAYES_00 autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Sun, 21 Mar 2010 22:30:34 -0400 (EDT) From: "Benjamin R. Haskell" To: zsh-workers@zsh.org Subject: Re: [PATCH] _git: Also complete FETCH_HEAD, ORIG_HEAD and MERGE_HEAD. In-Reply-To: <20100322012544.GA6014@ruderich.org> Message-ID: References: <20100321172336.GA4151@ruderich.org> <20100322012544.GA6014@ruderich.org> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="-1463810530-1498881046-1269225034=:19615" ---1463810530-1498881046-1269225034=:19615 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Mon, 22 Mar 2010, Simon Ruderich wrote: > On Sun, Mar 21, 2010 at 09:17:25PM +0100, Nikolai Weibull wrote: > > On Sun, Mar 21, 2010 at 20:48, Benjamin R. Haskell wrote: > > > >> + symbolic_heads=() > >> + for head in HEAD ORIG_HEAD FETCH_HEAD MERGE_HEAD ; do > >> + git rev-parse $head &>/dev/null && symbolic_heads+=( $head ) > >> + done > > > > That’s a lot of forking to make a simple check. Is there no better > > way? Do we actually have to filter the heads? > > I don't know the _git completion code, but couldn't we just check if > .git/{ORIG_HEAD,FETCH_HEAD,MERGE_HEAD} exists? This should work for > most things. > > Another possibility would be to just complete them all the time. Testing the existence of $gitdir/{refname} seems a fine compromise. (Really, I don't see the issue; this seems like a drop in the bucket of _git's performance issues... I s'pose the forks are prohibitively expensive on Win32? Revised patch below anyway.) Also, this breaks the fact that my previous patch fixed 'HEAD' *not* completing in a newly init'ed repo. (The file .git/HEAD contains the text "ref: refs/heads/master", even if HEAD doesn't exist.) But, whatever; speed trumps correctness. (In case it's unclear, I prefer my previous patch -- doesn't _git fork all over the place? -- but either one's preferable to no-change or always-adding-them.) Best, Ben --- Completion/Unix/Command/_git | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index d7570cc..ae6565f 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -3119,13 +3119,17 @@ __git_tag_ids () { (( $+functions[__git_heads] )) || __git_heads () { - local expl + local expl gitdir head symbolic_heads declare -a branch_names branch_names=(${${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname)"' refs/heads refs/remotes 2>/dev/null)"}#refs/(heads|remotes)/}) __git_command_successful || return - _wanted heads expl branch-name compadd $* - $branch_names HEAD + symbolic_heads=() + gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null) + __git_command_successful && symbolic_heads=( $gitdir/{,{ORIG,FETCH,MERGE}_}HEAD(N:t) ) + + _wanted heads expl branch-name compadd $* - $branch_names $symbolic_heads } (( $+functions[__git_tags] )) || -- 1.7.0 ---1463810530-1498881046-1269225034=:19615--