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

git ls-remote and protocolv2

From
Keegan Carruthers-Smith <keegan.csmith@gmail.com>
Date
Apr 15, 2020, 13:09 UTC
Message-ID
<m2k12g7v5u.fsf@gmail.com>
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

Next: Jeff King
Message 1 of 2 in “git ls-remote and protocolv2”
  1. Keegan Carruthers-SmithApr 15, 2020
  2. Jeff KingApr 15, 2020

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.