Browse Source

Update auxiliary maintainer mode build tools

* git-set-file-times: Update from rsync.
* git-version-gen: Update from gnulib.
* gitlog-to-changelog: Likewise.
Dmitry V. Levin 1 month ago
parent
commit
3345cde36b
3 changed files with 179 additions and 93 deletions
  1. 9
    3
      git-set-file-times
  2. 19
    17
      git-version-gen
  3. 151
    73
      gitlog-to-changelog

+ 9
- 3
git-set-file-times View File

@@ -11,8 +11,14 @@ my %ls;
11 11
 my $commit_time;
12 12
 my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : '';
13 13
 
14
+my $top_dir = `git rev-parse --show-toplevel`;
15
+exit 1 unless $top_dir;
16
+chomp($top_dir);
17
+
18
+chdir $top_dir or die "Failed to chdir to $top_dir\: $!\n";
19
+
14 20
 $/ = "\0";
15
-open FH, 'git ls-files -z|' or die $!;
21
+open FH, '-|', qw( git ls-files -z ) or die "Failed to fork: $!";
16 22
 while (<FH>) {
17 23
     chomp;
18 24
     $ls{$_} = $_;
@@ -20,12 +26,12 @@ while (<FH>) {
20 26
 close FH;
21 27
 
22 28
 $/ = "\n";
23
-open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
29
+open FH, '-|', qw( git log -r --name-only --no-color --pretty=raw -z ), @ARGV or die "Failed to fork: $!";
24 30
 while (<FH>) {
25 31
     chomp;
26 32
     if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
27 33
 	$commit_time = $1;
28
-    } elsif (s/\0\0commit [a-f0-9]{40}$// or s/\0$//) {
34
+    } elsif (s/\0\0commit [a-f0-9]{40}$// || s/\0$//) {
29 35
 	my @files = delete @ls{split(/\0/, $_)};
30 36
 	@files = grep { defined $_ } @files;
31 37
 	next unless @files;

+ 19
- 17
git-version-gen View File

@@ -1,9 +1,8 @@
1 1
 #!/bin/sh
2 2
 # Print a version string.
3
-scriptversion=2014-12-02.19; # UTC
3
+scriptversion=2018-03-07.03; # UTC
4 4
 
5
-# Copyright (C) 2007-2014 Free Software Foundation, Inc.
6
-# Copyright (c) 2013-2017 The strace developers.
5
+# Copyright (C) 2007-2019 Free Software Foundation, Inc.
7 6
 #
8 7
 # This program is free software: you can redistribute it and/or modify
9 8
 # it under the terms of the GNU General Public License as published by
@@ -16,9 +15,9 @@ scriptversion=2014-12-02.19; # UTC
16 15
 # GNU General Public License for more details.
17 16
 #
18 17
 # You should have received a copy of the GNU General Public License
19
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 19
 
21
-# This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
20
+# This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/.
22 21
 # It may be run two ways:
23 22
 # - from a git repository in which the "git describe" command below
24 23
 #   produces useful output (thus requiring at least one signed tag)
@@ -73,9 +72,10 @@ scriptversion=2014-12-02.19; # UTC
73 72
 
74 73
 me=$0
75 74
 
75
+year=`expr "$scriptversion" : '\([^-]*\)'`
76 76
 version="git-version-gen $scriptversion
77 77
 
78
-Copyright 2011 Free Software Foundation, Inc.
78
+Copyright $year Free Software Foundation, Inc.
79 79
 There is NO warranty.  You may redistribute this software
80 80
 under the terms of the GNU General Public License.
81 81
 For more information about these matters, see the files named COPYING."
@@ -102,8 +102,8 @@ while test $# -gt 0; do
102 102
   case $1 in
103 103
     --help) echo "$usage"; exit 0;;
104 104
     --version) echo "$version"; exit 0;;
105
-    --prefix) shift; prefix="$1";;
106
-    --fallback) shift; fallback="$1";;
105
+    --prefix) shift; prefix=${1?};;
106
+    --fallback) shift; fallback=${1?};;
107 107
     -*)
108 108
       echo "$0: Unknown option '$1'." >&2
109 109
       echo "$0: Try '--help' for more information." >&2
@@ -168,9 +168,10 @@ then
168 168
     # tag or the previous older version that did not?
169 169
     #   Newer: v6.10-77-g0f8faeb
170 170
     #   Older: v6.10-g0f8faeb
171
-    case $v in
172
-        *-*-*) : git describe is okay three part flavor ;;
173
-        *-*)
171
+    vprefix=`expr "X$v" : 'X\(.*\)-g[^-]*$'` || vprefix=$v
172
+    case $vprefix in
173
+        *-*) : git describe is probably okay three part flavor ;;
174
+        *)
174 175
             : git describe is older two part flavor
175 176
             # Recreate the number of commits and rewrite such that the
176 177
             # result is the same as if we were using the newer version
@@ -185,10 +186,11 @@ then
185 186
             ;;
186 187
     esac
187 188
 
188
-    # Change the first '-' to a '.', so version-comparing tools work properly.
189
-    # Remove the "g" in git describe's output string, to save a byte.
189
+    # Change the penultimate "-" to ".", for version-comparing tools.
190
+    # Remove the "g" to save a byte.
190 191
     # Change remaining '-' to '.', so version conforms to policies.
191
-    v=`echo "$v" | sed 's/-/.0./;s/\(.*\)-g/\1-/;s/-/./g'`;
192
+    v=`echo "$v" | sed 's/-\([^-]*\)-g\([^-]*\)$/.0.\1.\2/'`;
193
+
192 194
     v_from_git=1
193 195
 elif test "x$fallback" = x || git --version >/dev/null 2>&1; then
194 196
     v=UNKNOWN
@@ -202,7 +204,7 @@ v=`echo "$v" |sed "s/^$prefix//"`
202 204
 # string we're using came from git.  I.e., skip the test if it's "UNKNOWN"
203 205
 # or if it came from .tarball-version.
204 206
 if test "x$v_from_git" != x; then
205
-  # Don't declare a version "dirty" merely because a time stamp has changed.
207
+  # Don't declare a version "dirty" merely because a timestamp has changed.
206 208
   git update-index --refresh > /dev/null 2>&1
207 209
 
208 210
   dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty=
@@ -220,9 +222,9 @@ fi
220 222
 printf %s "$v"
221 223
 
222 224
 # Local variables:
223
-# eval: (add-hook 'write-file-hooks 'time-stamp)
225
+# eval: (add-hook 'before-save-hook 'time-stamp)
224 226
 # time-stamp-start: "scriptversion="
225 227
 # time-stamp-format: "%:y-%02m-%02d.%02H"
226
-# time-stamp-time-zone: "UTC"
228
+# time-stamp-time-zone: "UTC0"
227 229
 # time-stamp-end: "; # UTC"
228 230
 # End:

+ 151
- 73
gitlog-to-changelog View File

@@ -1,31 +1,46 @@
1
-eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
2
-  & eval 'exec perl -wS "$0" $argv:q'
3
-    if 0;
4
-# Convert git log output to ChangeLog format.
5
-
6
-my $VERSION = '2014-11-20 17:25'; # UTC
7
-# The definition above must lie within the first 8 lines in order
8
-# for the Emacs time-stamp write hook (at end) to update it.
9
-# If you change this file with Emacs, please let the write hook
10
-# do its job.  Otherwise, update this string manually.
1
+#!/bin/sh
2
+#! -*-perl-*-
11 3
 
12
-# Copyright (C) 2008-2014 Free Software Foundation, Inc.
4
+# Convert git log output to ChangeLog format.
13 5
 
6
+# Copyright (C) 2008-2019 Free Software Foundation, Inc.
7
+#
14 8
 # This program is free software: you can redistribute it and/or modify
15 9
 # it under the terms of the GNU General Public License as published by
16 10
 # the Free Software Foundation, either version 3 of the License, or
17 11
 # (at your option) any later version.
18
-
12
+#
19 13
 # This program is distributed in the hope that it will be useful,
20 14
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 15
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 16
 # GNU General Public License for more details.
23
-
17
+#
24 18
 # You should have received a copy of the GNU General Public License
25
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
-
19
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+#
27 21
 # Written by Jim Meyering
28 22
 
23
+# This is a prologue that allows to run a perl script as an executable
24
+# on systems that are compliant to a POSIX version before POSIX:2017.
25
+# On such systems, the usual invocation of an executable through execlp()
26
+# or execvp() fails with ENOEXEC if it is a script that does not start
27
+# with a #! line.  The script interpreter mentioned in the #! line has
28
+# to be /bin/sh, because on GuixSD systems that is the only program that
29
+# has a fixed file name.  The second line is essential for perl and is
30
+# also useful for editing this file in Emacs.  The next two lines below
31
+# are valid code in both sh and perl.  When executed by sh, they re-execute
32
+# the script through the perl program found in $PATH.  The '-x' option
33
+# is essential as well; without it, perl would re-execute the script
34
+# through /bin/sh.  When executed by  perl, the next two lines are a no-op.
35
+eval 'exec perl -wSx "$0" "$@"'
36
+     if 0;
37
+
38
+my $VERSION = '2018-03-07 03:47'; # UTC
39
+# The definition above must lie within the first 8 lines in order
40
+# for the Emacs time-stamp write hook (at end) to update it.
41
+# If you change this file with Emacs, please let the write hook
42
+# do its job.  Otherwise, update this string manually.
43
+
29 44
 use strict;
30 45
 use warnings;
31 46
 use Getopt::Long;
@@ -33,7 +48,7 @@ use POSIX qw(strftime);
33 48
 
34 49
 (my $ME = $0) =~ s|.*/||;
35 50
 
36
-# use File::Coda; # http://meyering.net/code/Coda/
51
+# use File::Coda; # https://meyering.net/code/Coda/
37 52
 END {
38 53
   defined fileno STDOUT or return;
39 54
   close STDOUT and return;
@@ -73,6 +88,8 @@ OPTIONS:
73 88
    --since=DATE convert only the logs since DATE;
74 89
                   the default is to convert all log entries.
75 90
    --until=DATE convert only the logs older than DATE.
91
+   --ignore-matching=PAT ignore commit messages whose first lines match PAT.
92
+   --ignore-line=PAT ignore lines of commit messages that match PAT.
76 93
    --format=FMT set format string for commit subject and body;
77 94
                   see 'man git-log' for the list of format metacharacters;
78 95
                   the default is '%s%n%b%n'
@@ -172,7 +189,7 @@ sub parse_amend_file($)
172 189
 
173 190
       if (!$in_code)
174 191
         {
175
-          $line =~ /^([0-9a-fA-F]{40})$/
192
+          $line =~ /^([[:xdigit:]]{40})$/
176 193
             or (warn "$ME: $f:$.: invalid line; expected an SHA1\n"),
177 194
               $fail = 1, next;
178 195
           $sha = lc $1;
@@ -226,6 +243,8 @@ sub git_dir_option($)
226 243
   my $amend_file;
227 244
   my $append_dot = 0;
228 245
   my $cluster = 1;
246
+  my $ignore_matching;
247
+  my $ignore_line;
229 248
   my $strip_tab = 0;
230 249
   my $strip_cherry_pick = 0;
231 250
   my $srcdir;
@@ -239,6 +258,8 @@ sub git_dir_option($)
239 258
      'amend=s' => \$amend_file,
240 259
      'append-dot' => \$append_dot,
241 260
      'cluster!' => \$cluster,
261
+     'ignore-matching=s' => \$ignore_matching,
262
+     'ignore-line=s' => \$ignore_line,
242 263
      'strip-tab' => \$strip_tab,
243 264
      'strip-cherry-pick' => \$strip_cherry_pick,
244 265
      'srcdir=s' => \$srcdir,
@@ -264,6 +285,7 @@ sub git_dir_option($)
264 285
   my $prev_multi_paragraph;
265 286
   my $prev_date_line = '';
266 287
   my @prev_coauthors = ();
288
+  my @skipshas = ();
267 289
   while (1)
268 290
     {
269 291
       defined (my $in = <PIPE>)
@@ -281,9 +303,22 @@ sub git_dir_option($)
281 303
       my ($sha, $rest) = split ':', $log, 2;
282 304
       defined $sha
283 305
         or die "$ME:$.: malformed log entry\n";
284
-      $sha =~ /^[0-9a-fA-F]{40}$/
306
+      $sha =~ /^[[:xdigit:]]{40}$/
285 307
         or die "$ME:$.: invalid SHA1: $sha\n";
286 308
 
309
+      my $skipflag = 0;
310
+      if (@skipshas)
311
+        {
312
+          foreach(@skipshas)
313
+            {
314
+              if ($sha =~ /^$_/)
315
+                {
316
+                  $skipflag = $_;
317
+                  last;
318
+                }
319
+            }
320
+        }
321
+
287 322
       # If this commit's log requires any transformation, do it now.
288 323
       my $code = $amend_code->{$sha};
289 324
       if (defined $code)
@@ -311,7 +346,7 @@ sub git_dir_option($)
311 346
           $rest =~ s/^\s*\(cherry picked from commit [\da-f]+\)\n//m;
312 347
         }
313 348
 
314
-      my @line = split "\n", $rest;
349
+      my @line = split /[ \t]*\n/, $rest;
315 350
       my $author_line = shift @line;
316 351
       defined $author_line
317 352
         or die "$ME:$.: unexpected EOF\n";
@@ -321,17 +356,18 @@ sub git_dir_option($)
321 356
 
322 357
       # Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog
323 358
       # `(tiny change)' annotation.
324
-      my $tiny = (grep (/^Copyright-paperwork-exempt:\s+[Yy]es$/, @line)
359
+      my $tiny = (grep (/^(?:Copyright-paperwork-exempt|Tiny-change):\s+[Yy]es$/, @line)
325 360
                   ? '  (tiny change)' : '');
326 361
 
327 362
       my $date_line = sprintf "%s  %s$tiny\n",
328
-        strftime ("%F", localtime ($1)), $2;
363
+        strftime ("%Y-%m-%d", localtime ($1)), $2;
329 364
 
330 365
       my @coauthors = grep /^Co-authored-by:.*$/, @line;
331 366
       # Omit meta-data lines we've already interpreted.
332 367
       @line = grep !/^(?:Signed-off-by:[ ].*>$
333 368
                        |Co-authored-by:[ ]
334 369
                        |Copyright-paperwork-exempt:[ ]
370
+                       |Tiny-change:[ ]
335 371
                        )/x, @line;
336 372
 
337 373
       # Remove leading and trailing blank lines.
@@ -341,68 +377,109 @@ sub git_dir_option($)
341 377
           while ($line[$#line] =~ /^\s*$/) { pop @line; }
342 378
         }
343 379
 
344
-      # Record whether there are two or more paragraphs.
345
-      my $multi_paragraph = grep /^\s*$/, @line;
346
-
347
-      # Format 'Co-authored-by: A U Thor <email@example.com>' lines in
348
-      # standard multi-author ChangeLog format.
349
-      for (@coauthors)
380
+      # Handle Emacs gitmerge.el "skipped" commits.
381
+      # Yes, this should be controlled by an option.  So sue me.
382
+      if ( grep /^(; )?Merge from /, @line )
383
+      {
384
+          my $found = 0;
385
+          foreach (@line)
386
+          {
387
+              if (grep /^The following commit.*skipped:$/, $_)
388
+              {
389
+                  $found = 1;
390
+                  ## Reset at each merge to reduce chance of false matches.
391
+                  @skipshas = ();
392
+                  next;
393
+              }
394
+              if ($found && $_ =~ /^([[:xdigit:]]{7,}) [^ ]/)
395
+              {
396
+                  push ( @skipshas, $1 );
397
+              }
398
+          }
399
+      }
400
+
401
+      # Ignore commits that match the --ignore-matching pattern, if specified.
402
+      if (defined $ignore_matching && @line && $line[0] =~ /$ignore_matching/)
350 403
         {
351
-          s/^Co-authored-by:\s*/\t    /;
352
-          s/\s*</  </;
353
-
354
-          /<.*?@.*\..*>/
355
-            or warn "$ME: warning: missing email address for "
356
-              . substr ($_, 5) . "\n";
404
+          $skipflag = 1;
357 405
         }
358
-
359
-      # If clustering of commit messages has been disabled, if this header
360
-      # would be different from the previous date/name/email/coauthors header,
361
-      # or if this or the previous entry consists of two or more paragraphs,
362
-      # then print the header.
363
-      if ( ! $cluster
364
-          || $date_line ne $prev_date_line
365
-          || "@coauthors" ne "@prev_coauthors"
366
-          || $multi_paragraph
367
-          || $prev_multi_paragraph)
406
+      elsif ($skipflag)
368 407
         {
369
-          $prev_date_line eq ''
370
-            or print "\n";
371
-          print $date_line;
372
-          @coauthors
373
-            and print join ("\n", @coauthors), "\n";
408
+          ## Perhaps only warn if a pattern matches more than once?
409
+          warn "$ME: warning: skipping $sha due to $skipflag\n";
374 410
         }
375
-      $prev_date_line = $date_line;
376
-      @prev_coauthors = @coauthors;
377
-      $prev_multi_paragraph = $multi_paragraph;
378 411
 
379
-      # If there were any lines
380
-      if (@line == 0)
381
-        {
382
-          warn "$ME: warning: empty commit message:\n  $date_line\n";
383
-        }
384
-      else
412
+      if (! $skipflag)
385 413
         {
386
-          if ($append_dot)
414
+          if (defined $ignore_line && @line)
415
+            {
416
+              @line = grep ! /$ignore_line/, @line;
417
+              while ($line[$#line] =~ /^\s*$/) { pop @line; }
418
+            }
419
+
420
+          # Record whether there are two or more paragraphs.
421
+          my $multi_paragraph = grep /^\s*$/, @line;
422
+
423
+          # Format 'Co-authored-by: A U Thor <email@example.com>' lines in
424
+          # standard multi-author ChangeLog format.
425
+          for (@coauthors)
387 426
             {
388
-              # If the first line of the message has enough room, then
389
-              if (length $line[0] < 72)
427
+              s/^Co-authored-by:\s*/\t    /;
428
+              s/\s*</  </;
429
+
430
+              /<.*?@.*\..*>/
431
+                or warn "$ME: warning: missing email address for "
432
+                  . substr ($_, 5) . "\n";
433
+            }
434
+
435
+          # If clustering of commit messages has been disabled, if this header
436
+          # would be different from the previous date/name/etc. header,
437
+          # or if this or the previous entry consists of two or more paragraphs,
438
+          # then print the header.
439
+          if ( ! $cluster
440
+              || $date_line ne $prev_date_line
441
+              || "@coauthors" ne "@prev_coauthors"
442
+              || $multi_paragraph
443
+              || $prev_multi_paragraph)
444
+            {
445
+              $prev_date_line eq ''
446
+                or print "\n";
447
+              print $date_line;
448
+              @coauthors
449
+                and print join ("\n", @coauthors), "\n";
450
+            }
451
+          $prev_date_line = $date_line;
452
+          @prev_coauthors = @coauthors;
453
+          $prev_multi_paragraph = $multi_paragraph;
454
+
455
+          # If there were any lines
456
+          if (@line == 0)
457
+            {
458
+              warn "$ME: warning: empty commit message:\n  $date_line\n";
459
+            }
460
+          else
461
+            {
462
+              if ($append_dot)
390 463
                 {
391
-                  # append a dot if there is no other punctuation or blank
392
-                  # at the end.
393
-                  $line[0] =~ /[[:punct:]\s]$/
394
-                    or $line[0] .= '.';
464
+                  # If the first line of the message has enough room, then
465
+                  if (length $line[0] < 72)
466
+                    {
467
+                      # append a dot if there is no other punctuation or blank
468
+                      # at the end.
469
+                      $line[0] =~ /[[:punct:]\s]$/
470
+                        or $line[0] .= '.';
471
+                    }
395 472
                 }
396
-            }
397 473
 
398
-          # Remove one additional leading TAB from each line.
399
-          $strip_tab
400
-            and map { s/^\t// } @line;
474
+              # Remove one additional leading TAB from each line.
475
+              $strip_tab
476
+                and map { s/^\t// } @line;
401 477
 
402
-          # Prefix each non-empty line with a TAB.
403
-          @line = map { length $_ ? "\t$_" : '' } @line;
478
+              # Prefix each non-empty line with a TAB.
479
+              @line = map { length $_ ? "\t$_" : '' } @line;
404 480
 
405
-          print "\n", join ("\n", @line), "\n";
481
+              print "\n", join ("\n", @line), "\n";
482
+            }
406 483
         }
407 484
 
408 485
       defined ($in = <PIPE>)
@@ -429,9 +506,10 @@ sub git_dir_option($)
429 506
 # Local Variables:
430 507
 # mode: perl
431 508
 # indent-tabs-mode: nil
432
-# eval: (add-hook 'write-file-hooks 'time-stamp)
509
+# eval: (add-hook 'before-save-hook 'time-stamp)
510
+# time-stamp-line-limit: 50
433 511
 # time-stamp-start: "my $VERSION = '"
434 512
 # time-stamp-format: "%:y-%02m-%02d %02H:%02M"
435
-# time-stamp-time-zone: "UTC"
513
+# time-stamp-time-zone: "UTC0"
436 514
 # time-stamp-end: "'; # UTC"
437 515
 # End:

Loading…
Cancel
Save