Set Copyright years and make them easier to update
authorWayne Davison <wayned@samba.org>
Thu, 9 Apr 2020 22:11:37 +0000 (15:11 -0700)
committerWayne Davison <wayned@samba.org>
Thu, 9 Apr 2020 22:11:37 +0000 (15:11 -0700)
I replaced git-set-file-times with an improved version that I wrote
recently (in python3). A new script uses it to figure out the
last-modified year for each *.[ch] file and updates its copyright.
It also puts the latest year into the latest-year.h file for the
output of --version.

25 files changed:
Makefile.in
authenticate.c
checksum.c
cleanup.c
clientserver.c
connection.c
flist.c
generator.c
latest-year.h [new file with mode: 0644]
lib/md5.c
loadparm.c
log.c
main.c
options.c
progress.c
receiver.c
rounding.c
rsync.c
rsync.h
sender.c
support/git-set-file-times
support/year-tweak [new file with mode: 0755]
uidlist.c
util.c
util2.c

index d7ddbc41e46696c586a70fdd65cdd0a37656eec0..4d6eadc60c6d42a31ec21b97310352fe99874da3 100644 (file)
@@ -95,6 +95,7 @@ rsync$(EXEEXT): $(OBJS)
 
 $(OBJS): $(HEADERS)
 $(CHECK_OBJS): $(HEADERS)
+options.o: latest-year.h
 
 flist.o: rounding.h
 
index 67c417cc5afd07ee94ac7fcd622e8196c6d858e5..169331e5491be88d78528d55c1d21b7020fb47a8 100644 (file)
@@ -2,7 +2,7 @@
  * Support rsync daemon authentication.
  *
  * Copyright (C) 1998-2000 Andrew Tridgell
- * Copyright (C) 2002-2019 Wayne Davison
+ * Copyright (C) 2002-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index b7ea748fff2720c06a0005ad9c4daa61617b2f2e..a6f1cd9c7caca9c8e28b99c25999743bf0212bae 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2004-2019 Wayne Davison
+ * Copyright (C) 2004-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 51130cafa570b931dcd6a393e079e46e55beef82..fbf7c60b12d302a2ee4d35e89943cc2e2c8b72b4 100644 (file)
--- a/cleanup.c
+++ b/cleanup.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2002 Martin Pool
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 692a4047ab998cf530795e0eefda5974a6da3ca1..3970f507f610b8178a3787454bef8a8212c1d542 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 2001-2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2002-2019 Wayne Davison
+ * Copyright (C) 2002-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 628186103e020788cd050011d240c7c385c21af2..1039115cf054e3509109c840091e7d9fc1e17036 100644 (file)
@@ -2,6 +2,7 @@
  * Support the max connections option.
  *
  * Copyright (C) 1998 Andrew Tridgell
+ * Copyright (C) 2006-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/flist.c b/flist.c
index 7d7d2c0ff1356886e71cc8db6a70e28f6b255ca8..5a29d6e913818b9308cb895ad7ba6e3f88861226 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2002-2019 Wayne Davison
+ * Copyright (C) 2002-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 12ad037d70d830b8d6099c741f9be953b423397f..1955bc81c096fe2be0d6e1b90e162c9d0b4b1c27 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/latest-year.h b/latest-year.h
new file mode 100644 (file)
index 0000000..ddbf2b5
--- /dev/null
@@ -0,0 +1 @@
+#define LATEST_YEAR "2020"
index 4baa9638e9ce4f60a8177893e32860223b2e8bef..c979d10cc2dd93a67aed21ec5a4f0730c59a2f00 100644 (file)
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -2,6 +2,7 @@
  * RFC 1321 compliant MD5 implementation
  *
  * Copyright (C) 2001-2003 Christophe Devine
+ * Copyright (C) 2007-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 534e7b63f892469e2dfe282518086230a255d110..eaa15d7de2cc921f3326cddc8593566544f7f16a 100644 (file)
  *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, visit the http://fsf.org website.
- */
-
-/* This is based on loadparm.c from Samba, written by Andrew Tridgell
+ *
+ * This is based on loadparm.c from Samba, written by Andrew Tridgell
  * and Karl Auer.  Some of the changes are:
  *
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison <wayned@samba.org>
+ * Copyright (C) 2003-2020 Wayne Davison
  */
 
 /* Load parameters.
diff --git a/log.c b/log.c
index b9bab81105eecff7c015586d232db8bc317650c6..3c6b1b9b3832b03c283fbfe56c4aed2aa78427fd 100644 (file)
--- a/log.c
+++ b/log.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 2000-2001 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/main.c b/main.c
index 9af9e5d3efd4d5f6cfb65bd4f2430dd83c5c23cf..3b37796db91f0fd4895e472a263097b30de04c1a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 99d3627ad429768e9d2b20027518f1bcdfa2cfa0..4ec8d4c8af1f25cba8482dcc13e1076ac31e1d4c 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1998-2001 Andrew Tridgell <tridge@samba.org>
  * Copyright (C) 2000, 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2002-2019 Wayne Davison
+ * Copyright (C) 2002-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
 
 #include "rsync.h"
 #include "itypes.h"
+#include "latest-year.h"
 #include <popt.h>
 #include <zlib.h>
 
@@ -614,7 +615,7 @@ static void print_rsync_version(enum logcode f)
 
        rprintf(f, "%s  version %s  protocol version %d%s\n",
                RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol);
-       rprintf(f, "Copyright (C) 1996-2019 by Andrew Tridgell, Wayne Davison, and others.\n");
+       rprintf(f, "Copyright (C) 1996-" LATEST_YEAR " by Andrew Tridgell, Wayne Davison, and others.\n");
        rprintf(f, "Web site: http://rsync.samba.org/\n");
        rprintf(f, "Capabilities:\n");
        rprintf(f, "    %d-bit files, %d-bit inums, %d-bit timestamps, %d-bit long ints,\n",
index d1cf8caa4de842f9bae79b658ca6a7fbe914409d..21763611ab338af5b9093dee14a5cb162ca5d45d 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index adfa8047189612fd68e4a15e38270625084949a7..afc8932cbcbaf5d8db30e53ea1963459750ba49d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index c4c29b3129bedab145fc954fcff8c68800fa9d98..bf2ecd3152a21d6c23139c7988879dc3606d4d30 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * A pre-compilation helper program to aid in the creation of rounding.h.
  *
- * Copyright (C) 2007-2019 Wayne Davison
+ * Copyright (C) 2007-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/rsync.c b/rsync.c
index b8d9acb90fd0370a4e24cbecc2ccf4cb71a0e5c1..f4af494579ffa2c7024ce1c38e256dd6977fa103 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/rsync.h b/rsync.h
index b1d16b37826887ac2bac652a4167886c6da68d7c..3f239f06271e0685b5e4f4bb78e1c78d071576ff 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -2,7 +2,7 @@
  * Copyright (C) 1996, 2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 27c511ef63a3a69b2af0cad42f5a4ffd99aebf02..4f34cded30fd0ed84b3a5ab51abae2deae4d9bac 100644 (file)
--- a/sender.c
+++ b/sender.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
index 53550b74092abb9c96aaad7bb9f34481f558764b..6fe641a39e9a6d000bcf1abe9e2abff220278c37 100755 (executable)
@@ -1,43 +1,76 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-# Sets mtime and atime of files to the latest commit time in git.
-#
-# This is useful after the first clone of the rsync repository BEFORE you
-# do any building.  It is also safe if you have done a "make distclean".
-
-my %ls;
-my $commit_time;
-my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : '';
-
-my $top_dir = `git rev-parse --show-toplevel`;
-exit 1 unless $top_dir;
-chomp($top_dir);
-
-chdir $top_dir or die "Failed to chdir to $top_dir\: $!\n";
-
-$/ = "\0";
-open FH, '-|', qw( git ls-files -z ) or die "Failed to fork: $!";
-while (<FH>) {
-    chomp;
-    $ls{$_} = $_;
-}
-close FH;
-
-$/ = "\n";
-open FH, '-|', qw( git log -r --name-only --no-color --pretty=raw -z ), @ARGV or die "Failed to fork: $!";
-while (<FH>) {
-    chomp;
-    if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
-       $commit_time = $1;
-    } elsif (s/\0\0commit [a-f0-9]{40}$// || s/\0$//) {
-       my @files = delete @ls{split(/\0/, $_)};
-       @files = grep { defined $_ } @files;
-       next unless @files;
-       map { s/^/$prefix/ } @files;
-       utime $commit_time, $commit_time, @files;
-    }
-    last unless %ls;
-}
-close FH;
+#!/usr/bin/python3
+
+import os, re, argparse, subprocess
+from datetime import datetime
+
+NULL_COMMIT_RE = re.compile(r'\0\0commit [a-f0-9]{40}$|\0$')
+
+def main():
+    if not args.git_dir:
+        cmd = 'git rev-parse --show-toplevel 2>/dev/null || echo .'
+        top_dir = subprocess.check_output(cmd, shell=True).decode('utf-8').strip()
+        args.git_dir = os.path.join(top_dir, '.git')
+        if not args.prefix:
+            os.chdir(top_dir)
+
+    git = [ 'git', '--git-dir=' + args.git_dir ]
+
+    if args.tree:
+        cmd = git + 'ls-tree -z -r --name-only'.split() + [ args.tree ]
+    else:
+        cmd = git + 'ls-files -z'.split()
+
+    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    out = proc.communicate()[0].decode('utf-8')
+    ls = set(out.split('\0'))
+    ls.discard('')
+
+    cmd = git + 'log -r --name-only --no-color --pretty=raw --no-renames -z'.split()
+    if args.tree:
+        cmd.append(args.tree)
+    cmd += ['--'] + args.files
+
+    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+    for line in proc.stdout:
+        line = line.decode('utf-8').strip()
+        m = re.match(r'^committer .*? (\d+) [-+]\d+$', line)
+        if m:
+            commit_time = int(m[1])
+        elif NULL_COMMIT_RE.search(line):
+            line = NULL_COMMIT_RE.sub('', line)
+            files = set(fn for fn in line.split('\0') if fn in ls)
+            if not files:
+                continue
+            for fn in files:
+                if args.prefix:
+                    fn = args.prefix + fn
+                mtime = os.lstat(fn).st_mtime
+                if args.list:
+                    if args.list > 1:
+                        ts = str(commit_time).rjust(10)
+                    else:
+                        ts = datetime.utcfromtimestamp(commit_time).strftime("%Y-%m-%d %H:%M:%S")
+                    chg = '.' if mtime == commit_time else '*'
+                    print(chg, ts, fn)
+                elif mtime != commit_time:
+                    if not args.quiet:
+                        print(f"Setting {fn}")
+                    os.utime(fn, (commit_time, commit_time), follow_symlinks = False)
+            ls -= files
+            if not ls:
+                break
+    proc.communicate()
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description="Set the times of the current git checkout to their last-changed time.")
+    parser.add_argument('--git-dir', metavar='GIT_DIR', help="The git dir to query (defaults to affecting the current git checkout).")
+    parser.add_argument('--tree', metavar='TREE-ISH', help="The tree-ish to query (defaults to the current branch).")
+    parser.add_argument('--prefix', metavar='PREFIX_STR', help="Prepend the PREFIX_STR to each filename we tweak.")
+    parser.add_argument('--quiet', '-q', action='store_true', help="Don't output the changed-file information.")
+    parser.add_argument('--list', '-l', action='count', help="List the files and their dates instead of changing them. Repeat for Unix Time instead of human reable.")
+    parser.add_argument('files', metavar='FILE', nargs='*', help="Specify a subset of checked-out files to tweak.")
+    args = parser.parse_args()
+    main()
+
+# vim: sw=4 et
diff --git a/support/year-tweak b/support/year-tweak
new file mode 100755 (executable)
index 0000000..aff72aa
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/python3
+
+# This uses the output from "support/git-set-file-times --list" to discern
+# the last-modified year of each *.c & *.h file and updates the copyright
+# year if it isn't set right.
+
+import sys, os, re, argparse, subprocess
+from datetime import datetime
+
+MAINTAINER_NAME = 'Wayne Davison'
+MAINTAINER_SUF = ' ' + MAINTAINER_NAME + "\n"
+
+def main():
+    latest_year = '2000'
+
+    proc = subprocess.Popen('support/git-set-file-times --list'.split(), stdout=subprocess.PIPE, encoding='utf-8')
+    for line in proc.stdout:
+        m = re.match(r'^\S\s+(?P<year>\d\d\d\d)\S+\s+\S+\s+(?P<fn>.+)', line)
+        if not m:
+            print("Failed to parse line from git-set-file-times:", line)
+            sys.exit(1)
+        m = argparse.Namespace(**m.groupdict())
+        if m.year > latest_year:
+            latest_year = m.year
+        if not re.search(r'\.(c|h|[1-9])$', m.fn) or m.fn.startswith('zlib/'):
+            continue
+        maybe_edit_copyright_year(m.fn, m.year)
+    proc.communicate()
+
+    fn = 'latest-year.h'
+    with open(fn, 'r', encoding='utf-8') as fh:
+        old_txt = fh.read()
+
+    txt = f'#define LATEST_YEAR "{latest_year}"\n'
+    if txt != old_txt:
+        print(f"Updating {fn} with year {latest_year}")
+        with open(fn, 'w', encoding='utf-8') as fh:
+            fh.write(txt)
+
+
+def maybe_edit_copyright_year(fn, year):
+    opening_lines = [ ]
+    copyright_line = None
+
+    with open(fn, 'r', encoding='utf-8') as fh:
+        for line in fh:
+            opening_lines.append(line)
+            if not re.search(r'\S', line):
+                break
+            m = re.match(r'^(?P<pre>.*Copyright\s+\S+\s+)(?P<year>\d\d\d\d(?:-\d\d\d\d)?(,\s+\d\d\d\d)*)(?P<suf>.+)', line)
+            if not m:
+                continue
+            copyright_line = argparse.Namespace(**m.groupdict())
+            copyright_line.lineno = len(opening_lines)
+            copyright_line.is_maintainer_line = MAINTAINER_NAME in copyright_line.suf
+            copyright_line.txt = line
+            if copyright_line.is_maintainer_line:
+                break
+
+        if not copyright_line:
+            return
+
+        if copyright_line.is_maintainer_line:
+            cyears = copyright_line.year.split('-')
+            if year == cyears[0]:
+                cyears = [ year ]
+            else:
+                cyears = [ cyears[0], year ]
+            txt = copyright_line.pre + '-'.join(cyears) + MAINTAINER_SUF
+            if txt == copyright_line.txt:
+                return
+            opening_lines[copyright_line.lineno - 1] = txt
+        else:
+            if fn.startswith('lib/'):
+                return
+            txt = copyright_line.pre + year + MAINTAINER_SUF
+            opening_lines[copyright_line.lineno - 1] += txt
+
+        remaining_txt = fh.read()
+
+    print(f"Updating {fn} with year {year}")
+
+    with open(fn, 'w', encoding='utf-8') as fh:
+        fh.write(''.join(opening_lines))
+        fh.write(remaining_txt)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description="Grab the year of last mod for our c & h files and make sure the Copyright comment is up-to-date.")
+    args = parser.parse_args()
+    main()
+
+# vim: sw=4 et
index 98d229527704de491a90ff4ab98bc783579b1f01..e0c0d74b95331c45b69180bb613ff18f70f05ead 100644 (file)
--- a/uidlist.c
+++ b/uidlist.c
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 1996 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
- * Copyright (C) 2004-2019 Wayne Davison
+ * Copyright (C) 2004-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/util.c b/util.c
index aaf540376e132f956d98f29e449e366eca5280fc..ec80b43bd1785c6d4a031655e3b9f62b7f2b0df4 100644 (file)
--- a/util.c
+++ b/util.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/util2.c b/util2.c
index b46677c04af14c2c12faccc094c887d19312a2c0..488d673a0b0e018a096c7bafe7cab8f4f3154a0a 100644 (file)
--- a/util2.c
+++ b/util2.c
@@ -4,7 +4,7 @@
  * Copyright (C) 1996-2000 Andrew Tridgell
  * Copyright (C) 1996 Paul Mackerras
  * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
- * Copyright (C) 2003-2019 Wayne Davison
+ * Copyright (C) 2003-2020 Wayne Davison
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by