>From 6231494948ccc053b4b71be412e193ff33cfb16c Mon Sep 17 00:00:00 2001 From: Bruno Haible 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 in . * 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 + + gnulib-tool: Make --version output independent of git's configuration. + Reported by Collin Funk in + . + * 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 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