git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 0/2] builtin/show-ref.c: support `--count` for limiting output

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 6, 2022, 22:57 UTC
Message-ID
<Yp6GRccc5UElNrZb@nand.local>
In-Reply-To
<xmqqo7z54d7g.fsf@gitster.g>
On Mon, Jun 06, 2022 at 03:52:19PM -0700, Junio C Hamano wrote:
Show 10 quoted lines
> Taylor Blau <me@ttaylorr.com> writes:
>
> > This short patch series adds support for a new `--count` argument for limiting
> > the output of `show-ref` (à-la the `for-each-ref` option by the same name).
>
> It makes me wonder why we limit this to show-ref.
>
>     $ git --pipe-to-head-N=3 any-command args...
>
> IOW, having to add an option like this feels absurd.

I don't disagree. But `--pipe-to-head-N=3` feels like too broad a stroke. This series at least imitates `for-each-ref`'s `--count` option, which makes it feel acceptable to me (if not a little silly).

Show 11 quoted lines
> > This is useful in contexts where a caller wants to avoid enumerating more
> > references than necessary (e.g., they only care whether a tag exists, but not
> > how many or what they are called) but doesn't have control of the output stream
> > (e.g., they are in Ruby and can't pipe the output to `head -n 1`).
>
> Are you saying that Ruby is incapable of run a command line like
>
>    av[0] = "sh"
>    av[1] = "-c"
>    av[2] = "git show-ref blah | head -n 1"
>    av[3] = NULL

No, Ruby is perfectly capable of doing that. But it involves an extra process (two, if `head` isn't a shell builtin) and the additional overhead of creating a pipe and passing data through it instead of writing directly to stdout.

That isn't a complete show-stopper in most cases, but in ultra-latency-sensitive applications like GitHub is using show-ref for, being able to shave an extra process or so off matters.

If you're strongly opposed to having `show-ref` match `for-each-ref`'s `--count` option, I won't be too sad. But I'm not in a huge rush to replace this series with `git --pipe-to-head-N=<n>` either, FWIW.

Thanks, Taylor

Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 14 in “builtin/show-ref.c: support `--count` for limiting output”
  1. 0/2 builtin/show-ref.c: support `--count` for limiting outputTaylor Blau, Jun 6, 2022
  2. 1/2 builtin/show-ref.c: rename `found_match` to `matches_nr`Taylor Blau, Jun 6, 2022
  3. 2/2 builtin/show-ref.c: limit output with `--count`Taylor Blau, Jun 6, 2022
  4. Junio C HamanoJun 6, 2022
  5. Ævar Arnfjörð BjarmasonJun 7, 2022
  6. Taylor BlauJun 7, 2022
  7. Ævar Arnfjörð BjarmasonJun 7, 2022
  8. Junio C HamanoJun 8, 2022
  9. Junio C HamanoJun 6, 2022
  10. Taylor BlauJun 6, 2022
  11. Junio C HamanoJun 6, 2022
  12. Derrick StoleeJun 7, 2022
  13. Ævar Arnfjörð BjarmasonJun 7, 2022
  14. Taylor BlauJun 7, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.