Bruno Haible <br...@clisp.org> writes: >> I can send a version of that patch if that is agreeable to everyone. > > Yes, please. With an added example in the documentation. Thanks!
I've pushed the attached patch. Mostly the same as the original but the default behavior is unchanged. The option is now named '--commit-timezone'. I'm not very creative so feel free to change it if you think of something better. :) I added documentation with an example where me and your time zones created unordered output in the generated ChangeLog: 2024-06-19 Bruno Haible <br...@clisp.org> 2024-06-18 Collin Funk <collin.fu...@gmail.com> 2024-06-19 Bruno Haible <br...@clisp.org> Hopefully that should make it clear for anyone who wants to avoid that behavior. Simon Josefsson <si...@josefsson.org> writes: > That is not how C-x 4 a works, I believe it uses local time zone. So I > think we will have to live with some inconsistency here. It can also be > argued that the local date should be used: after all, if I'm committing > something on 2023-12-31 or 2024-01-01 locally, it shouldn't show up as > being done 2024-01-01 or 2023-12-31 which could even have legal > consequences. I wonder if it is worth mentioning to bug-standards. I feel like using the local time of the committer better represents the "date you applied the change" as written in the GNU standards mentioned earlier [1]. However, I think I dislike the entries being out of order more... Collin [1] https://www.gnu.org/prep/standards/standards.html#Style-of-Change-Logs
>From 4c9664d6f3fcbef8ffd3a2ccb70b694284ee0598 Mon Sep 17 00:00:00 2001 From: Collin Funk <collin.fu...@gmail.com> Date: Wed, 3 Jul 2024 21:55:13 -0700 Subject: [PATCH] gitlog-to-changelog: Add a new --commit-timezone option. * build-aux/gitlog-to-changelog: Use the date given in the commit time zone if --commit-timezone is used. (usage): Mention the new option. * doc/gitlog-to-changelog.texi (gitlog-to-changelog): Mention the --commit-timezone and add an invocation example. Add example of date ordering that may be undesired. --- ChangeLog | 10 ++++++++ build-aux/gitlog-to-changelog | 29 ++++++++++++++++++---- doc/gitlog-to-changelog.texi | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a886e25cc2..b19c2a482a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-07-03 Collin Funk <collin.fu...@gmail.com> + + gitlog-to-changelog: Add a new --commit-timezone option. + * build-aux/gitlog-to-changelog: Use the date given in the commit time + zone if --commit-timezone is used. + (usage): Mention the new option. + * doc/gitlog-to-changelog.texi (gitlog-to-changelog): Mention the + --commit-timezone and add an invocation example. Add example of date + ordering that may be undesired. + 2024-07-03 Jim Meyering <meyer...@meta.com> maintainer-makefile: derive VERSION from RELEASE only from command line diff --git a/build-aux/gitlog-to-changelog b/build-aux/gitlog-to-changelog index 49e7ef95ce..32b3a6264c 100755 --- a/build-aux/gitlog-to-changelog +++ b/build-aux/gitlog-to-changelog @@ -35,7 +35,7 @@ eval 'exec perl -wSx "$0" "$@"' if 0; -my $VERSION = '2023-06-24 21:59'; # UTC +my $VERSION = '2024-07-04 04:42'; # UTC # The definition above must lie within the first 8 lines in order # for the Emacs time-stamp write hook (at end) to update it. # If you change this file with Emacs, please let the write hook @@ -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. + --commit-timezone use dates respecting the timezone commits were made in. --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 $commit_timezone = 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, + 'commit-timezone' => \$commit_timezone, '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 = $commit_timezone ? '%cI' : '%ct'; 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 (! $commit_timezone) + { + # Seconds since the Epoch. + $commit_date = strftime "%Y-%m-%d", localtime ($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. diff --git a/doc/gitlog-to-changelog.texi b/doc/gitlog-to-changelog.texi index 5dc1043e45..2b96721e5d 100644 --- a/doc/gitlog-to-changelog.texi +++ b/doc/gitlog-to-changelog.texi @@ -43,6 +43,51 @@ @node gitlog-to-changelog depend on the developer's locale and time zone. Omit this line if you prefer @file{ChangeLog} files that depend on these developer settings. +If you wish to output the @file{ChangeLog} with dates respecting the +time zone each individual commit was made in you can use the +@option{--commit-timezone} option. For example: + +@example +dist-hook: gen-ChangeLog +.PHONY: gen-ChangeLog +gen-ChangeLog: + $(AM_V_GEN)if test -e .git; then \ + $(top_srcdir)/build-aux/gitlog-to-changelog --commit-timezone \ + > $(distdir)/ChangeLog.tmp && \ + mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \ + fi +@end example + +The use of @option{--commit-timezone} means that @file{ChangeLog} dates +correctly represent when a committer pushed a change according to their +time zone. However, as a consequence @file{ChangeLog} dates will no +longer be monotonically increasing. This behavior may be undesired, +especially when developers are spread across many different time zones. +For example, the following three commits were made in a short period of +time across two different time zones: + +@example +2024-06-19 Bruno Haible <bruno@@clisp.org> + + filemode tests: Tweak. + * tests/test-filemode.c: Update comment. + * modules/filemode-tests (Depends-on): Add unistd. + +2024-06-18 Collin Funk <collin.funk1@@gmail.com> + + filemode: Add tests. + * modules/filemode-tests: New file. + * tests/test-filemode.c: New file. + +2024-06-19 Bruno Haible <bruno@@clisp.org> + + copysignl tests: Avoid failure on Solaris 11.4. + * tests/test-copysignl.c: Include <float.h>. + (LDBL_BYTES): New macro. + (main): Use it instead of sizeof (long double). + * modules/copysignl-tests (Depends-on): Add float. +@end example + If you wish to limit the @file{ChangeLog} entries (perhaps for size issues) to contain only entries since a particular git tag, you can use a @code{gen-ChangeLog} rule like the following: -- 2.45.2