Subject: Re: [PATCH] archive: add --mtime

From: Junio C Hamano <[email-masked]>
Date: Mon, 20 Feb 2023 21:37:18 -0800

René Scharfe <[email-masked]> writes:

>> This is the solution with least damage, letting the existing code to
>> set archive_time and then discard the result and overwrite with the
>> command line option.
>
> I actually like Peff's solution more, because it's short and solves the
> specific problem of non-deterministic timestamps for tree archives.

Yes.  That would be my preference as well.  Without any UI to
educate users about.

> The --mtime option on the other hand mimics GNU tar, so it is more
> familiar and proven, though.

And that gives us the second best option ;-)

> It isn't all that careful, but you're right that we should do what we
> can.  Like this on top?  The message string is borrowed from commit's
> handling of --date.

Yeah, something like that, I would think.

Thanks.

> ---
>  archive.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/archive.c b/archive.c
> index 122860b39d..871d80ee79 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -438,6 +438,15 @@ static void parse_pathspec_arg(const char **pathspec,
>  	}
>  }
>
> +static timestamp_t approxidate_or_die(const char *date_str)
> +{
> +	int errors = 0;
> +	timestamp_t date = approxidate_careful(date_str, &errors);
> +	if (errors)
> +		die(_("invalid date format: %s"), date_str);
> +	return date;
> +}
> +
>  static void parse_treeish_arg(const char **argv,
>  		struct archiver_args *ar_args, const char *prefix,
>  		int remote)
> @@ -473,7 +482,7 @@ static void parse_treeish_arg(const char **argv,
>  		archive_time = time(NULL);
>  	}
>  	if (ar_args->mtime_option)
> -		archive_time = approxidate(ar_args->mtime_option);
> +		archive_time = approxidate_or_die(ar_args->mtime_option);
>
>  	tree = parse_tree_indirect(&oid);
>  	if (!tree)
> --
> 2.39.2