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

Re: Passing commit IDs to git-archive

From
Jeff King <peff@peff.net>
Date
Mar 12, 2012, 11:47 UTC
Message-ID
<20120312114742.GC12921@sigill.intra.peff.net>
In-Reply-To
<8fb14091-99dc-4383-9cab-5bf508e0a554@mail>
On Fri, Mar 09, 2012 at 05:14:05PM -0500, Stephen Bash wrote:
Show 6 quoted lines
> on Mac OS 10.6.8 (obviously this is local testing, the goal is to use
> ssh remotely).  After parsing the error "no such ref" I attempted the
> same operation using master as the tree-ish and archive worked as
> expected (either specifying the path separately or using the colon
> syntax to reference the tree directly).  Is there a reason git-archive
> requires a named ref rather than just a commit (or tree) ID?

Yes; generally git repositories do not allow clients to access arbitrary sha1s. Instead, they require that the requested objects be accessible by a ref.

git-archive was not properly enforcing this, and was changed recently to allow only refs by name, as well as sub-trees of refs (e.g., HEAD:subdir/). That means we do disallow an arbitrary commit or tree sha1, even if it is reachable from the advertised refs.

> would it be difficult to patch git-upload-archive to use the IDs?  I
> could use tags for the ref, but in my case would result in almost
> every commit being a tag which seems wasteful.

Doing it right is a bit expensive, because in the general case (somebody requested a tree sha1), we would need to traverse every tree of every commit to see if it is reachable.

We could potentially implement a more restricted set of rules, allowing "<commit>:<subdir>" and checking that <commit> is reachable. That would disallow an arbitrary tree sha1, but I suspect it would cover the common use case (i.e., you want to get the tree, or even a subtree, of a particular revision).

-Peff
Previous: René ScharfeNext: Stephen Bash
Message 4 of 5 in “Passing commit IDs to git-archive”
  1. Stephen BashMar 9, 2012
  2. Junio C HamanoMar 9, 2012
  3. René ScharfeMar 10, 2012
  4. Jeff KingMar 12, 2012
  5. Stephen BashMar 12, 2012

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.