From 2e15741e0ecb3c08ada8abdc9887fc4c42fe05fe Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 15 Aug 2017 14:25:14 +0100 Subject: [PATCH] bin/git-copyright-dates: New script to work out copyright date lists. --- Makefile | 1 + bin/git-copyright-dates | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 bin/git-copyright-dates diff --git a/Makefile b/Makefile index 342f3ef..033006a 100644 --- 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 index 0000000..5eec713 --- /dev/null +++ b/bin/git-copyright-dates @@ -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" +} -- 2.11.0