Collin Funk wrote: > > git log -n 1 ChangeLog | grep ^Date: > > Ah, I see what is happening. > > [collin@debian gnulib]$ git log -n 1 > commit 431d6a7615245e6b32d95b4b27aab5d3af65ad2b (HEAD -> master, > origin/master, origin/HEAD) > Author: Bruno Haible <br...@clisp.org> > AuthorDate: Wed Feb 28 00:33:49 2024 +0100 > Commit: Bruno Haible <br...@clisp.org> > CommitDate: Wed Feb 28 00:33:49 2024 +0100 > > isnan: Fix compilation error in C++ mode on OpenBSD 7.5-beta. > > Reported by Christian Weisgerber <na...@mips.inka.de> in > <https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00261.html>. > > * lib/math.in.h (GNULIB_NAMESPACE_LACKS_ISNAN): Define on all platforms > with clang ≥ 14. > > So the grep ^Date fails. I don't remember changing this but in my git > config it is caused by this [1]: > > [format] > pretty = fuller
OK, so we need to make this piece of code more robust against various git configurations. > The regular gnulib-tool gives me this: > > [collin@debian gnulib]$ gnulib-tool --version > gnulib-tool (GNU gnulib 2024-02-28 00:00:00) 0.1.7153-431d6 Here, the git configuration fooled gnulib-tool too. $date ended up being empty, and GNU date interprets the empty strings as "today at 00:00:00". Which was unintended, but it's a decent fallback behaviour worth porting to the Python code. > It seems that the 'git command-name --pretty=medium' existed before > git version 1. Good. Thanks for the investigation. I'm committing these three patches, that fix the version output also in the presence of [log] date = relative [format] pretty = fuller 2024-02-28 Bruno Haible <br...@clisp.org> gnulib-tool: Make --version output independent of git's configuration. Reported by Collin Funk <collin.fu...@gmail.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00268.html>. * pygnulib/GLInfo.py (GLInfo.date): Pass --format and --date options, to override the user's git configuration. * gnulib-tool (func_version): Likewise. Also pass options '-n 1', to speed up the operation. 2024-02-28 Bruno Haible <br...@clisp.org> gnulib-tool.py: Avoid exception when 'git log' output is unexpected. * pygnulib/GLInfo.py (GLInfo.date): When the 'git log' output does not contain a line with the expected 'Date:' pattern, pass the empty string to GNU date. 2024-02-28 Bruno Haible <br...@clisp.org> gnulib-tool: Avoid references to functions that get defined later. * gnulib-tool (func_fatal_error, func_warning, func_readlink): Move before func_gnulib_dir.
>From 584ef464a310638f94a79e9b4710fde41c884e7d Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Feb 2024 11:23:17 +0100 Subject: [PATCH 1/3] gnulib-tool: Avoid references to functions that get defined later. * gnulib-tool (func_fatal_error, func_warning, func_readlink): Move before func_gnulib_dir. --- ChangeLog | 6 +++++ gnulib-tool | 70 ++++++++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index af3af3707e..af0835269f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-02-28 Bruno Haible <br...@clisp.org> + + gnulib-tool: Avoid references to functions that get defined later. + * gnulib-tool (func_fatal_error, func_warning, func_readlink): Move + before func_gnulib_dir. + 2024-02-27 Bruno Haible <br...@clisp.org> isnan: Fix compilation error in C++ mode on OpenBSD 7.5-beta. diff --git a/gnulib-tool b/gnulib-tool index 029a8cf377..2e10abcfcc 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -421,6 +421,41 @@ func_exit () (exit $1); exit $1 } +# func_fatal_error message +# outputs to stderr a fatal error message, and terminates the program. +# Input: +# - progname name of this program +func_fatal_error () +{ + echo "$progname: *** $1" 1>&2 + echo "$progname: *** Stop." 1>&2 + func_exit 1 +} + +# func_warning message +# Outputs to stderr a warning message, +func_warning () +{ + echo "gnulib-tool: warning: $1" 1>&2 +} + +# func_readlink SYMLINK +# outputs the target of the given symlink. +if (type readlink) > /dev/null 2>&1; then + func_readlink () + { + # Use the readlink program from GNU coreutils. + readlink "$1" + } +else + func_readlink () + { + # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p' + # would do the wrong thing if the link target contains " -> ". + LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' + } +fi + # func_gnulib_dir # locates the directory where the gnulib repository lives # Input: @@ -672,41 +707,6 @@ else fast_func_remove_suffix=false fi -# func_fatal_error message -# outputs to stderr a fatal error message, and terminates the program. -# Input: -# - progname name of this program -func_fatal_error () -{ - echo "$progname: *** $1" 1>&2 - echo "$progname: *** Stop." 1>&2 - func_exit 1 -} - -# func_warning message -# Outputs to stderr a warning message, -func_warning () -{ - echo "gnulib-tool: warning: $1" 1>&2 -} - -# func_readlink SYMLINK -# outputs the target of the given symlink. -if (type readlink) > /dev/null 2>&1; then - func_readlink () - { - # Use the readlink program from GNU coreutils. - readlink "$1" - } -else - func_readlink () - { - # Use two sed invocations. A single sed -n -e 's,^.* -> \(.*\)$,\1,p' - # would do the wrong thing if the link target contains " -> ". - LC_ALL=C ls -l "$1" | sed -e 's, -> ,#%%#,' | sed -n -e 's,^.*#%%#\(.*\)$,\1,p' - } -fi - # func_relativize DIR1 DIR2 # computes a relative pathname RELDIR such that DIR1/RELDIR = DIR2. # Input: -- 2.34.1
>From 0127a5e68be69a8c57bb43171bae3b1bb7ae4a6e Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Feb 2024 11:38:00 +0100 Subject: [PATCH 2/3] gnulib-tool.py: Avoid exception when 'git log' output is unexpected. * pygnulib/GLInfo.py (GLInfo.date): When the 'git log' output does not contain a line with the expected 'Date:' pattern, pass the empty string to GNU date. --- ChangeLog | 7 +++++++ pygnulib/GLInfo.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index af0835269f..e667861d9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-02-28 Bruno Haible <br...@clisp.org> + + gnulib-tool.py: Avoid exception when 'git log' output is unexpected. + * pygnulib/GLInfo.py (GLInfo.date): When the 'git log' output does not + contain a line with the expected 'Date:' pattern, pass the empty string + to GNU date. + 2024-02-28 Bruno Haible <br...@clisp.org> gnulib-tool: Avoid references to functions that get defined later. diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 808f11b06f..8ffe1d309b 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -106,10 +106,14 @@ class GLInfo(object): result = sp.check_output(args, cwd=DIRS['root']).decode("UTF-8") # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string pattern = re.compile('^Date:[\t ]*(.*?)$', re.M) - result = pattern.findall(result)[0] - # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600" - pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ') - result = pattern.sub('\\1 \\2 \\4 \\3 ', result) + result = pattern.findall(result) + if (len(result) > 0): + result = result[0] + # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600" + pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ') + result = pattern.sub('\\1 \\2 \\4 \\3 ', result) + else: + result = '' # Use GNU date to compute the time in GMT args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S'] proc = sp.check_output(args) -- 2.34.1
>From 6231494948ccc053b4b71be412e193ff33cfb16c Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 28 Feb 2024 11:52:33 +0100 Subject: [PATCH 3/3] gnulib-tool: Make --version output independent of git's configuration. Reported by Collin Funk <collin.fu...@gmail.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00268.html>. * pygnulib/GLInfo.py (GLInfo.date): Pass --format and --date options, to override the user's git configuration. * gnulib-tool (func_version): Likewise. Also pass options '-n 1', to speed up the operation. --- ChangeLog | 10 ++++++++++ gnulib-tool | 5 +---- pygnulib/GLInfo.py | 7 ++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index e667861d9c..330727e02e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-02-28 Bruno Haible <br...@clisp.org> + + gnulib-tool: Make --version output independent of git's configuration. + Reported by Collin Funk <collin.fu...@gmail.com> in + <https://lists.gnu.org/archive/html/bug-gnulib/2024-02/msg00268.html>. + * pygnulib/GLInfo.py (GLInfo.date): Pass --format and --date options, to + override the user's git configuration. + * gnulib-tool (func_version): Likewise. Also pass options '-n 1', to + speed up the operation. + 2024-02-28 Bruno Haible <br...@clisp.org> gnulib-tool.py: Avoid exception when 'git log' output is unexpected. diff --git a/gnulib-tool b/gnulib-tool index 2e10abcfcc..a7ba7a98f1 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -359,10 +359,7 @@ func_version () s/^Date:[ ]*//p q }' - date=`cd "$gnulib_dir" && git log ChangeLog | sed -n -e "$sed_extract_first_date"` - # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600". - sed_year_before_time='s/^[^ ]* \([^ ]*\) \([0-9]*\) \([0-9:]*\) \([0-9]*\) /\1 \2 \4 \3 /' - date=`echo "$date" | sed -e "$sed_year_before_time"` + date=`cd "$gnulib_dir" && git log -n 1 --format=medium --date=iso ChangeLog | sed -n -e "$sed_extract_first_date"` # Use GNU date to compute the time in GMT. date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"` version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'` diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 8ffe1d309b..a0a70270a9 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -102,16 +102,13 @@ class GLInfo(object): except: have_GNU_date = False if have_GNU_date: - args = ['git', 'log', '-n', '1', 'ChangeLog'] + args = ['git', 'log', '-n', '1', '--format=medium', '--date=iso', 'ChangeLog'] result = sp.check_output(args, cwd=DIRS['root']).decode("UTF-8") - # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string + # Get date as "2008-03-21 07:16:51 -0600" from string pattern = re.compile('^Date:[\t ]*(.*?)$', re.M) result = pattern.findall(result) if (len(result) > 0): result = result[0] - # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600" - pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ') - result = pattern.sub('\\1 \\2 \\4 \\3 ', result) else: result = '' # Use GNU date to compute the time in GMT -- 2.34.1