Skip to content

Commit

Permalink
Set Copyright years and make them easier to update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Wayne Davison committed Apr 9, 2020
1 parent e2aee6c commit c5fabfb
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 66 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ rsync$(EXEEXT): $(OBJS)

$(OBJS): $(HEADERS)
$(CHECK_OBJS): $(HEADERS)
options.o: latest-year.h

flist.o: rounding.h

Expand Down
2 changes: 1 addition & 1 deletion authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clientserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 1998-2001 Andrew Tridgell <[email protected]>
* Copyright (C) 2001-2002 Martin Pool <[email protected]>
* 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
Expand Down
1 change: 1 addition & 0 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flist.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 1996 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <[email protected]>
* 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
Expand Down
2 changes: 1 addition & 1 deletion generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 1996-2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2002 Martin Pool <[email protected]>
* 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
Expand Down
1 change: 1 addition & 0 deletions latest-year.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define LATEST_YEAR "2020"
1 change: 1 addition & 0 deletions lib/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions loadparm.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
*
* 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 <[email protected]>
* Copyright (C) 2003-2019 Wayne Davison <[email protected]>
* Copyright (C) 2003-2020 Wayne Davison
*/

/* Load parameters.
Expand Down
2 changes: 1 addition & 1 deletion log.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 1998-2001 Andrew Tridgell <[email protected]>
* Copyright (C) 2000-2001 Martin Pool <[email protected]>
* 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
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 1996-2001 Andrew Tridgell <[email protected]>
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <[email protected]>
* 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
Expand Down
5 changes: 3 additions & 2 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 1998-2001 Andrew Tridgell <[email protected]>
* Copyright (C) 2000, 2001, 2002 Martin Pool <[email protected]>
* 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
Expand All @@ -21,6 +21,7 @@

#include "rsync.h"
#include "itypes.h"
#include "latest-year.h"
#include <popt.h>
#include <zlib.h>

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion progress.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 1996-2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <[email protected]>
* 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
Expand Down
2 changes: 1 addition & 1 deletion receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rounding.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (C) 1996, 2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool <[email protected]>
* 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
Expand Down
2 changes: 1 addition & 1 deletion sender.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
119 changes: 76 additions & 43 deletions support/git-set-file-times
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit c5fabfb

Please sign in to comment.