bin/git-copyright-dates: New script to work out copyright date lists.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 15 Aug 2017 13:25:14 +0000 (14:25 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 15 Aug 2017 13:29:35 +0000 (14:29 +0100)
Makefile
bin/git-copyright-dates [new file with mode: 0755]

index 342f3ef..033006a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -158,6 +158,7 @@ DOTLINKS            += .bash_profile .bash_completion .bashrc .inputrc
 
 ## Git.
 DOTSUBST               += .gitconfig
+SCRIPTLINKS            += git-copyright-dates
 DOTLINKS               += .cgrc .tigrc
 .gitconfig_SUBSTS       = \
        $(call substvar,releasekey,$(call mdw-conf,release-key,481334C2))
diff --git a/bin/git-copyright-dates b/bin/git-copyright-dates
new file mode 100755 (executable)
index 0000000..5eec713
--- /dev/null
@@ -0,0 +1,34 @@
+#! /usr/bin/perl
+
+my (%Y, %M);
+open my $fh, "-|", "git", "log",
+  "--date=format:%Y", "--pretty=format:%ad %aN"
+  or die "git log: $!";
+while (<$fh>) {
+  /(\d+)\s+(.*)$/ or die "wtf?  $_";
+  my ($y, $who) = ($1, $2);
+  push @{$Y{$who}}, $y;
+  if (!exists $M{$who} || $y < $M{$who}) { $M{$who} = $y; }
+}
+close $fh or die "git log (rc = $?)";
+
+my ($S, $O, $L);
+sub out () {
+  defined $L or return;
+  defined $S and $S .= ", ";
+  if ($O < $L - 1) { $S .= "$O--$L" }
+  elsif ($O != $L) { $S .= "$O, $L" }
+  else { $S .= "$L" }
+}
+
+for my $who (sort { $M{$a} <=> $M{$b} } keys %Y) {
+  my @y = sort { $a <=> $b } @{$Y{$who}};
+  undef $S; undef $L;
+  for my $y (@y) {
+    if (!defined $L) { $O = $L = $y; }
+    elsif ($y == $L + 1) { $L = $y; }
+    elsif ($y != $L) { out(); $O = $L = $y; }
+  }
+  out();
+  print "$who: $S\n"
+}