All of lore.kernel.org
 help / color / mirror / Atom feed
* git ls-remote and protocolv2
@ 2020-04-15 13:09 Keegan Carruthers-Smith
  2020-04-15 16:04 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Keegan Carruthers-Smith @ 2020-04-15 13:09 UTC (permalink / raw)
  To: git

Hi,

I would like to take advantage of protocol v2 in "git
ls-remote". However, it can't reasonably use it because the patterns for
ls-remote aren't prefix based patterns. See
https://public-inbox.org/git/20181031042405.GA5503@sigill.intra.peff.net/

This is behaviour I would like to implement. At Sourcegraph (were I
work) we use "git ls-remote HEAD" to test if a remote is reachable and a
valid git remote. Additionally we use it to get the symref for the
default branch.

There may be a better way to do this, but so far it seems ls-remote is
the most reliable. However, we don't get to take advantage of protocol
v2. A simple hack I did gives much better perf for our use case:

  diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
  index 6ef519514b..12d3af177a 100644
  --- a/builtin/ls-remote.c
  +++ b/builtin/ls-remote.c
  @@ -91,6 +91,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
   		}
   	}
   
  +	argv_array_push(&ref_prefixes, "HEAD");
  +
   	if (flags & REF_TAGS)
   		argv_array_push(&ref_prefixes, "refs/tags/");
   	if (flags & REF_HEADS)


What are the options to allow the use of protocol v2? The ideas I have
in mind are the following.

"--ref-prefixes" flag. This changes the behaviour of the patterns to
instead be ref prefixes so we can pass them as ref prefixes.

"--ref-prefix=PREFIX" flag. Can be passed in multiple times. Each PREFIX
is set as a ref prefix.

"refs/" prefix in pattern. If all patterns have a prefix of "refs/" pass
in the relevant prefixes to remote refs. This would be a breaking change
for the rare case of refs named like "refs/heads/refs/foo". You also
wouldn't be able to pass in the symref "HEAD" which is what I want for
my usecase.

I'm happy to implement any of these.

Cheers,
Keegan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-15 16:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-15 13:09 git ls-remote and protocolv2 Keegan Carruthers-Smith
2020-04-15 16:04 ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.