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

Re: Exec upload-pack on remote with what parameters to get direntries.

From
Jeff King <peff@peff.net>
Date
Aug 30, 2021, 19:10 UTC
Message-ID
<YS0tNoAa/0VQe1OW@coredump.intra.peff.net>
In-Reply-To
<CANXojcyWnFY60bXG6MDS9WAYkcFQHf+Oef0VREBkvgsuX9e=Kg@mail.gmail.com>
On Sat, Aug 28, 2021 at 02:56:17PM +0200, Stef Bon wrote:
Show 8 quoted lines
> I've got a custom ssh library which I use to make a connection to a
> git server like www.github.com, user stefbon.
> 
> Now I want to get the direntries of a remote repo, and I know I have
> to use upload-pack for that, but with what parameters?
> 
> I want to use the outcome to make a fuse fs, user can browse the
> files. Possibly the user can also view the contents.

The protocol used by upload-pack is described in Documentation/technical/pack-protocol.txt, but in short: I don't think it will do what you want.

There is no operation to list the tree contents, for example, nor really even a good way to fetch a single object. The protocol is geared around efficiently transferring slices of history, so it is looking at sets of reachable objects (what the client is asking for, and what it claims to have).

You might be able to cobble something together with shallow and partial fetches. E.g., something like:

  git clone --depth 1 --filter=blob:none --single-branch -b $branch

is basically asking to send only a single commit, plus all of its trees, but no blobs. From there you could parse the tree objects to assemble a directory listing. Possibly with a tree:depth filter you could even do it iteratively.

Some hosts offer a separate API that would give you a much nicer interface. E.g., GitHub has:

  https://docs.github.com/en/rest/reference/git#trees

But of course that won't work with GitLab, etc, and you'd have to implement against the API for each hosting provider.

-Peff
Previous: Stef BonNext: Junio C Hamano
Message 2 of 12 in “Exec upload-pack on remote with what parameters to get direntries.”
  1. Stef BonAug 28, 2021
  2. Jeff KingAug 30, 2021
  3. Junio C HamanoAug 30, 2021
  4. Jeff KingAug 30, 2021
  5. Junio C HamanoAug 30, 2021
  6. Ævar Arnfjörð BjarmasonAug 31, 2021
  7. Bruno AlbuquerqueAug 31, 2021
  8. Junio C HamanoAug 31, 2021
  9. Stef BonAug 31, 2021
  10. Jeff KingAug 31, 2021
  11. Stef BonAug 31, 2021
  12. Ævar Arnfjörð BjarmasonAug 31, 2021

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.