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

Re: git-archive and tar options

From
Jeff King <peff@peff.net>
Date
Jul 14, 2011, 18:18 UTC
Message-ID
<20110714181858.GA25172@sigill.intra.peff.net>
In-Reply-To
<4E1F2B23.1020908@lsrfire.ath.cx>
On Thu, Jul 14, 2011 at 07:45:07PM +0200, René Scharfe wrote:
Show 8 quoted lines
> > We didn't when git-archive was written, but these days we have
> > get_sha1_with_context to remember incidental things about an object we
> > look up. It should perhaps remember the commit (if any) we used to reach
> > a treeish, and then the above command line could still insert the pax
> > header.
> 
> That's a good idea to increase consistency, as there shouldn't really be
> a difference in output between the two subdirectory syntaxes.
The patch to do this is pretty tiny. See below.
There are a few issues, though:
  1. I think this is probably the right thing to do, and most people
     will be happy about it. But I guess I can see an argument that the
     commit-id should not be there, as the subtree does not represent
     that commit.
     IOW, if you assume the commit-id in the output means
     "by the way, this came from commit X", this change is a good thing.
     If you assume it means "this is the tree from commit X", then it's
     not.  I have no idea how people use it. I never have, but I always
     assumed the use case was "I have this random tarball. Where did it
     come from?".
  2. The object_context already has the sha1 we want, but it is under
     the name "tree", which is not an accurate name. It's actually
     "whatever is on the left side of the :". Which should be a
     tree-ish, but could be a commit or a tree.
  3. It looks like we fill in object_context whenever we see something
     like "tree-ish:path". But we should perhaps also do so when peeling
     something like "tree-ish^{tree}".
> I always wondered, however, if the embedded commit ID has really been
> used to identify the corresponding version of an archive that somehow
> lost its filename (due to being piped?).
I dunno. I've never used it.
-- >8 --
Subject: [PATCH] archive: look harder for commit id

When "git archive" is given a commit, the output will contain the commit sha1 (either as a pax header for tar format, or in a file comment for zip).

When it's given a name that resolves to a tree, like:
  git archive git-1.7.0:Documentation

then the archive code never sees the commit, and no commit-id is output. We can use get_sha1_with_context to remember the commit that led us to that tree (if any).

Signed-off-by: Jeff King <peff@peff.net>
---
 archive.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/archive.c b/archive.c
index 42f2d2f..d0ba7fb 100644
--- a/archive.c
+++ b/archive.c
@@ -256,11 +256,14 @@ static void parse_treeish_arg(const char **argv,
 	struct tree *tree;
 	const struct commit *commit;
 	unsigned char sha1[20];
+	struct object_context oc;
 
-	if (get_sha1(name, sha1))
+	if (get_sha1_with_context(name, sha1, &oc))
 		die("Not a valid object name");
 
 	commit = lookup_commit_reference_gently(sha1, 1);
+	if (!commit)
+		commit = lookup_commit_reference_gently(oc.tree, 1);
 	if (commit) {
 		commit_sha1 = commit->object.sha1;
 		archive_time = commit->date;
-- 
1.7.6.38.ge5b33
Previous: René ScharfeNext: Jakub Narebski
Message 6 of 22 in “git-archive and tar options”
  1. Neal KreitzingerJul 13, 2011
  2. Jeff KingJul 14, 2011
  3. René ScharfeJul 14, 2011
  4. Jeff KingJul 14, 2011
  5. René ScharfeJul 14, 2011
  6. Jeff KingJul 14, 2011
  7. Jakub NarebskiJul 14, 2011
  8. Junio C HamanoJul 14, 2011
  9. Jeff KingJul 14, 2011
  10. Junio C HamanoJul 14, 2011
  11. René ScharfeJul 15, 2011
  12. Neal KreitzingerJul 18, 2011
  13. René ScharfeJul 18, 2011
  14. Jakub NarebskiJul 14, 2011
  15. Neal KreitzingerJul 18, 2011
  16. René ScharfeJul 18, 2011
  17. Neal KreitzingerJul 19, 2011
  18. René ScharfeJul 19, 2011
  19. Neal KreitzingerJul 21, 2011
  20. Neal KreitzingerJul 21, 2011
  21. Andreas SchwabJul 14, 2011
  22. Sylvain RabotJul 19, 2011

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.