On 2023-08-01 06:36, Sergey Poznyakoff wrote:
Opinions?
Thanks for looking into this. My first reaction is that it's a bit
complicated and I would omit --set-mtime-format as being more trouble
than it's worth, and by default disable warnings about the command
issuing an empty log message. I have what I hope is a better idea below.
1. When COMMAND returns empty output (e.g. when given a file that is
not in the repository), tar issues a warning message.
In the tzdb example this warning is unnecessary. Some files in a tarball
are generated by 'Make' and these should use their own timestamps (with
mtime truncated to integer seconds). We don't need to see a warning
about this. I expect other projects using this approach to be similar.
The command ... implies additional complication, because it is executed in
subdirectory.
Possibly 'tar' should be using the -C option - though would this also
apply to the mtime-determining subcommand? Anyway, I'm hoping for
something simpler than this (see below).
A better solution would be possible
if instead of of simply passing the file name to the command,
--set-mtime-command used some kind of variable expansion, e.g.
--set-mtime-command="git log -1 --format='tformat:%cI' ../$file"
3. Command execution timeout should be implemented, perhaps.
This is all getting a bit complicated.
Some time ago Bruno Haible suggested a simpler approach, which may be
better for GNU tar's users. Here's the idea, which requires two passes
over the input files, the first to collect timestamp info:
1. For each version-controlled file, obtain the mtime from your
version-control system. Put this mtime into the tarball.
2. Let M be the maximum mtime determined in step (1), truncated to
1-second resolution. (If there are no such files, let M be zero.)
3. Sort each non-version-controlled file by time, putting them into a
sorted list F1, F2, ... Fn. Put into the tarball the timestamps M+1,
..., M+n, respectively, for these files.
If F1, ..., Fn are all built from version-controlled files by a
deterministic sequential process, the tarball's timestamps will be
reproducible from the version-control system.
If GNU Tar had a --reproducible-mtime flag that did the above, that
would be convenient to use. Ideally I wouldn't have to specify
--set-mtime-command for the special case of Git; GNU Tar would just do
the right thing by default for Git.