Re: [PATCH] git-completion.bash: always swallow error output of for-each-ref
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Feb 4, 2016, 11:26 UTC
- Message-ID
- <alpine.DEB.2.20.1602041216240.2964@virtualbox>
- In-Reply-To
- <20160204111307.GA30495@sigill.intra.peff.net>
Hi Peff,
On Thu, 4 Feb 2016, Jeff King wrote:
Show 11 quoted lines
> On Thu, Feb 04, 2016 at 11:34:59AM +0100, Sebastian Schuberth wrote: > > > This avoids output like > > > > warning: ignoring broken ref refs/remotes/origin/HEAD > > > > while completing branch names. > > Hmm. I feel like this case (HEAD points to a branch, then `fetch > --prune` deletes it) came up recently and we discussed quieting that > warning. But now I cannot seem to find it.
I am pretty certain that it came up in my patch series:
http://thread.gmane.org/gmane.comp.version-control.git/278538
> Anyway, I this is a reasonable workaround. Errors from bash completion > scripts are almost always going to be useless and get in the way of > reading your own prompt.
Maybe we should just shut up the completions in more cases? Dunno...
Show 18 quoted lines
> > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > > index 15ebba5..7c0549d 100644 > > --- a/contrib/completion/git-completion.bash > > +++ b/contrib/completion/git-completion.bash > > @@ -317,7 +317,7 @@ __git_heads () > > local dir="$(__gitdir)" > > if [ -d "$dir" ]; then > > git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ > > - refs/heads > > + refs/heads 2>/dev/null > > return > > Not really related to your topic, but digging into it caused me to read > b7dd2d2 (for-each-ref: Do not lookup objects when they will not be used, > 2009-05-27), which is about making sure for-each-ref is very fast in > completion. > > It looks like %(refname:short) is actually kind of expensive:
Yep, this was reported on the Git for Windows bug tracker, too:
https://github.com/git-for-windows/git/issues/524
Show 11 quoted lines
> $ time git for-each-ref --format='%(refname)' refs/tags >/dev/null > > real 0m0.004s > user 0m0.000s > sys 0m0.004s > > $ time git for-each-ref --format='%(refname:short)' refs/tags >/dev/null > > real 0m0.009s > user 0m0.004s > sys 0m0.004s
And the timings in the ticket I mentioned above are not pretty small: 0.055s vs 1.341s
Show 7 quoted lines
> The upcoming refname:strip does much better: > > $ time git for-each-ref --format='%(refname:strip=2)' refs/tags >/dev/null > > real 0m0.004s > user 0m0.000s > sys 0m0.004s
This is funny: after reading the commit message at https://github.com/git/git/commit/0571979b it eludes me why strip=2 should be so much faster than short...
Ciao, Dscho