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

Re: Passing tar(1) options via git-archive(1)

From
Jeff King <peff@peff.net>
Date
Sep 24, 2014, 05:46 UTC
Message-ID
<20140924054624.GB24141@peff.net>
In-Reply-To
<87k34tizb5.fsf@brockman.se>
On Wed, Sep 24, 2014 at 03:26:22AM +0200, Daniel Brockman wrote:
Show 14 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > Git does not invoke tar(1).  It has its own tar (actually, pax)
> > implementation, so any options would have to be implemented in Git.
> > We'd probably want to make such a change effective in the zip format
> > as well.
> 
> Ah, I see...
> 
> Well, I guess in the meantime I'll just do this:
> 
>    git commit -m dummy --allow-empty --date=1970-01-01T00:00:00Z
>    git archive HEAD | docker build -
>    git reset HEAD~

I don't think that will work. The `--date` parameter sets the author date, but archive uses the committer date. You'd have to set GIT_COMMITTER_DATE in the environment to override that.

Also, you can avoid writing to the HEAD ref entirely by using the commit-tree plumbing. Like:

  commit=$(
    GIT_COMMITTER_DATE=1970-01-01T00:00:00Z \
    git commit-tree HEAD^{tree} </dev/null
  )
  git archive $commit | ...
However, the --mtime patch you are asking for is really not that big:
diff --git a/archive.c b/archive.c
index 952a659..9396fca 100644
--- a/archive.c
+++ b/archive.c
@@ -299,7 +299,8 @@ static void parse_treeish_arg(const char **argv,
 	ar_args->tree = tree;
 	ar_args->commit_sha1 = commit_sha1;
 	ar_args->commit = commit;
-	ar_args->time = archive_time;
+	if (!ar_args->time)
+		ar_args->time = archive_time;
 }
 
 #define OPT__COMPR(s, v, h, p) \
@@ -323,6 +324,7 @@ static int parse_archive_args(int argc, const char **argv,
 	int i;
 	int list = 0;
 	int worktree_attributes = 0;
+	unsigned long mtime = 0;
 	struct option opts[] = {
 		OPT_GROUP(""),
 		OPT_STRING(0, "format", &format, N_("fmt"), N_("archive format")),
@@ -332,6 +334,7 @@ static int parse_archive_args(int argc, const char **argv,
 			N_("write the archive to this file")),
 		OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
 			N_("read .gitattributes in working directory")),
+		OPT_DATE(0, "mtime", &mtime, N_("mtime of files in archive")),
 		OPT__VERBOSE(&verbose, N_("report archived files on stderr")),
 		OPT__COMPR('0', &compression_level, N_("store only"), 0),
 		OPT__COMPR('1', &compression_level, N_("compress faster"), 1),
@@ -398,6 +401,7 @@ static int parse_archive_args(int argc, const char **argv,
 	args->base = base;
 	args->baselen = strlen(base);
 	args->worktree_attributes = worktree_attributes;
+	args->time = mtime;
 
 	return argc;
 }

which allows:

  git archive --mtime='yesterday at 3pm' HEAD

For inclusion in git, it would need someone to wrap it up with a commit
message, and add a basic test (see the existing mtime test in
t/t5000-tar-tree) and documentation in Documentation/git-archive.txt.
That someone could be you. :)

-Peff
Previous: Daniel Brockman
Message 5 of 5 in “Passing tar(1) options via git-archive(1)”
  1. Daniel BrockmanSep 23, 2014
  2. Thomas BraunSep 23, 2014
  3. brian m. carlsonSep 24, 2014
  4. Daniel BrockmanSep 24, 2014
  5. Jeff KingSep 24, 2014

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.