From: Jeff King <peff@peff.net>
To: Sebastian Schuberth <sschuberth@gmail.com>
Cc: git@vger.kernel.org, szeder@ira.uka.de,
Junio C Hamano <gitster@pobox.com>,
tr@thomasrast.ch
Subject: Re: [PATCH] git-completion.bash: always swallow error output of for-each-ref
Date: Thu, 4 Feb 2016 06:13:07 -0500 [thread overview]
Message-ID: <20160204111307.GA30495@sigill.intra.peff.net> (raw)
In-Reply-To: <56B32953.2010908@gmail.com>
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.
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.
> 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:
$ 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
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
Obviously these are pretty small timings from my git.git with ~600 tags,
but you can see that refname:short really does cost more. On a more
ridiculous example repository I have with about 10 million refs, the
timings are more like 5s, 66s, 5.5s.
Just thought I'd throw that our there in case any completion people feel
like poking around with it.
-Peff
next prev parent reply other threads:[~2016-02-04 11:13 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-04 10:34 [PATCH] git-completion.bash: always swallow error output of for-each-ref Sebastian Schuberth
2016-02-04 11:13 ` Jeff King [this message]
2016-02-04 11:26 ` Johannes Schindelin
2016-02-04 11:45 ` Jeff King
2016-02-04 19:06 ` Junio C Hamano
2016-02-12 23:21 ` SZEDER Gábor
2016-02-12 23:40 ` Jeff King
2016-02-13 1:07 ` SZEDER Gábor
2016-02-13 9:21 ` Johannes Schindelin
2016-02-13 13:53 ` SZEDER Gábor
2016-02-13 17:14 ` Johannes Schindelin
2016-02-13 16:57 ` Jeff King
2016-02-12 23:43 ` SZEDER Gábor
2016-02-12 23:46 ` Jeff King
2016-02-13 0:53 ` Duy Nguyen
2016-02-12 20:00 ` Junio C Hamano
2016-02-12 20:10 ` Jeff King
2016-02-12 20:26 ` Junio C Hamano
2016-02-12 21:40 ` SZEDER Gábor
2016-02-12 22:16 ` Jeff King
2016-02-12 23:37 ` Junio C Hamano
2016-02-23 23:30 ` Junio C Hamano
2016-02-24 7:48 ` Sebastian Schuberth
2016-02-12 9:23 ` Sebastian Schuberth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160204111307.GA30495@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sschuberth@gmail.com \
--cc=szeder@ira.uka.de \
--cc=tr@thomasrast.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).