Hi Simon, Bruno, and Paul, Following this thread from a few months ago [1]. Simon wanted to change 'git-log-to-changelog' so it used dates based on UTC time.
But Bruno said: > I don't agree with this patch. It misrepresents the dates on which people > have checked in their commits. [...] > There was a problem already before, in gitlog-to-changelog. Namely, what > if a committer sits in California and the release manager, who creates the > tarball, sits in England or Germany? The same effect as above would occur. > But your change now made it even worse: Even the release manager cannot > override the time zone. > The real fix, IMO, is to use 'git log --format=fuller', and convert > the CommitDate (*) by removing the time zone. In the example above: > CommitDate: Sat Mar 16 22:29:02 2024 -0700 > -> 2024-03-16 and then Paul added: > Emacs has had the tradition of using UTC for ChangeLog dates, so > please support that as well, as an option. I've attached a patch that I think deals with these issues. Can you all look over it for me? The patch adds a new '--utc' option and changes the default behavior so that localtime is no longer used. The default behavior invokes git with options to output ISO 8601 time. For example: [commit-hash]:2024-07-02T20:08:08+02:00 Bruno Haible <br...@clisp.org> git-merge-changelog: Simplify installation instructions. That way we can just trim off the time and offset and use the date. When using '--utc' we can use gmtime like Simon did with his patch. Let me know if this is okay and I can commit it with documentation adjustments. BTW, I don't know the time functions very well so there is probably a better way to do this... Collin [1] https://lists.gnu.org/archive/html/bug-gnulib/2024-04/msg00188.html
>From f4ad3c9376a23e10890e1db23e2f28270848f4d2 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Wed, 3 Jul 2024 05:25:54 -0700 Subject: [PATCH] gitlog-to-changelog: Improve handling of time zones. * build-aux/gitlog-to-changelog: Use the commit date in the committers timezone by default. Add the --utc option to convert commit times to UTC before using the date. (usage): Mention the --utc option. --- ChangeLog | 8 ++++++++ build-aux/gitlog-to-changelog | 27 +++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcef360b22..aca200cc13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-07-03 Collin Funk <collin.fu...@gmail.com> + + gitlog-to-changelog: Improve handling of time zones. + * build-aux/gitlog-to-changelog: Use the commit date in the committers + timezone by default. Add the --utc option to convert commit times to UTC + before using the date. + (usage): Mention the --utc option. + 2024-07-02 Bruno Haible <br...@clisp.org> git-merge-changelog: Simplify installation instructions. diff --git a/build-aux/gitlog-to-changelog b/build-aux/gitlog-to-changelog index 49e7ef95ce..d92eb621da 100755 --- a/build-aux/gitlog-to-changelog +++ b/build-aux/gitlog-to-changelog @@ -97,6 +97,7 @@ OPTIONS: --strip-cherry-pick remove data inserted by "git cherry-pick"; this includes the "cherry picked from commit ..." line, and the possible final "Conflicts:" paragraph. + --utc convert commit times to UTC before extracting the date --help display this help and exit --version output version information and exit @@ -247,6 +248,7 @@ sub git_dir_option($) my $ignore_line; my $strip_tab = 0; my $strip_cherry_pick = 0; + my $utc_commit_time = 0; my $srcdir; GetOptions ( @@ -262,6 +264,7 @@ sub git_dir_option($) 'ignore-line=s' => \$ignore_line, 'strip-tab' => \$strip_tab, 'strip-cherry-pick' => \$strip_cherry_pick, + 'utc' => \$utc_commit_time, 'srcdir=s' => \$srcdir, ) or usage 1; @@ -274,10 +277,12 @@ sub git_dir_option($) # that makes a correction in the log or attribution of that commit. my $amend_code = defined $amend_file ? parse_amend_file $amend_file : {}; + my $commit_time_format = $utc_commit_time ? '%ct' : '%cI'; my @cmd = ('git', git_dir_option $srcdir, qw(log --log-size), - '--pretty=format:%H:%ct %an <%ae>%n%n'.$format_string, @ARGV); + ("--pretty=format:%H:$commit_time_format" + . ' %an <%ae>%n%n'.$format_string, @ARGV)); open PIPE, '-|', @cmd or die ("$ME: failed to run '". quoted_cmd (@cmd) ."': $!\n" . "(Is your Git too old? Version 1.5.1 or later is required.)\n"); @@ -350,17 +355,31 @@ sub git_dir_option($) my $author_line = shift @line; defined $author_line or die "$ME:$.: unexpected EOF\n"; - $author_line =~ /^(\d+) (.*>)$/ + $author_line =~ /^(\S+) (.*>)$/ or die "$ME:$.: Invalid line " . "(expected date/author/email):\n$author_line\n"; + # Author <email> + my $author = $2; + + my $commit_date = $1; + if ($utc_commit_time) + { + # Seconds since the Epoch. + $commit_date = strftime "%Y-%m-%d", gmtime ($commit_date); + } + else + { + # ISO 8601 date. + $commit_date =~ s/T.*$//; + } + # Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog # '(tiny change)' annotation. my $tiny = (grep (/^(?:Copyright-paperwork-exempt|Tiny-change):\s+[Yy]es$/, @line) ? ' (tiny change)' : ''); - my $date_line = sprintf "%s %s$tiny\n", - strftime ("%Y-%m-%d", localtime ($1)), $2; + my $date_line = "$commit_date $author$tiny\n"; my @coauthors = grep /^Co-authored-by:.*$/, @line; # Omit meta-data lines we've already interpreted. -- 2.45.2