| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
use open ':encoding(UTF-8)'; |
| 6 |
use Encode; |
| 7 |
use Text::Wrap; |
| 8 |
|
| 9 |
# |
| 10 |
# We'd like to minimize the number of dependencies, otherwise we'd probably use |
| 11 |
# the Text::Unidecode module instead. |
| 12 |
# |
| 13 |
sub asciify { |
| 14 |
my $text = shift; |
| 15 |
my %charmap = ( |
| 16 |
ord "\N{LATIN CAPITAL LETTER A WITH DIAERESIS}" => 'Ae', |
| 17 |
ord "\N{LATIN CAPITAL LETTER O WITH DIAERESIS}" => 'Oe', |
| 18 |
ord "\N{LATIN CAPITAL LETTER U WITH DIAERESIS}" => 'Ue', |
| 19 |
ord "\N{LATIN SMALL LETTER A WITH DIAERESIS}" => 'ae', |
| 20 |
ord "\N{LATIN SMALL LETTER O WITH DIAERESIS}" => 'oe', |
| 21 |
ord "\N{LATIN SMALL LETTER U WITH DIAERESIS}" => 'ue', |
| 22 |
ord "\N{LATIN SMALL LETTER SHARP S}" => 'ss' |
| 23 |
); |
| 24 |
|
| 25 |
return encode('ascii', $text, sub { |
| 26 |
my $char = shift; |
| 27 |
|
| 28 |
foreach my $key (keys %charmap) { |
| 29 |
return $charmap{$key} if $key == $char; |
| 30 |
} |
| 31 |
return sprintf('<U+%04X>', $char); |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
# The lines will have a length of no more than $columns - 1. |
| 36 |
$Text::Wrap::columns = 81; |
| 37 |
|
| 38 |
if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) { |
| 39 |
print "Not a Git repository, so I won't update the ChangeLog.\n"; |
| 40 |
exit 0; |
| 41 |
} |
| 42 |
|
| 43 |
my $regex = |
| 44 |
'^commit [0-9a-f]+\n' . |
| 45 |
'^Author: (?<name>.+) <(?<email>.*)>\n' . |
| 46 |
'^Date: (?<date>\d{4}-\d{2}-\d{2})\n' . |
| 47 |
'^\n' . |
| 48 |
'(?<message>(^ .*\n)+)' . |
| 49 |
'^\n' . |
| 50 |
'(?<files>(^.+\n)+)'; |
| 51 |
|
| 52 |
my $git_log = qx'git log -M -C --stat --name-only --date=short'; |
| 53 |
die "Cannot get `git log' output\n" if $? != 0; |
| 54 |
|
| 55 |
my ($prev_date, $prev_name, $prev_email); |
| 56 |
|
| 57 |
while ($git_log =~ /$regex/gm) { |
| 58 |
my %commit = %+; |
| 59 |
|
| 60 |
if (not defined $prev_date |
| 61 |
or $commit{date} ne $prev_date |
| 62 |
or $commit{name} ne $prev_name |
| 63 |
or $commit{email} ne $prev_email) { |
| 64 |
print $commit{date}, ' '; |
| 65 |
print asciify($commit{name}), ' '; |
| 66 |
print '<', $commit{email}, '>', "\n\n"; |
| 67 |
} |
| 68 |
$prev_date = $commit{date}; |
| 69 |
$prev_name = $commit{name}; |
| 70 |
$prev_email = $commit{email}; |
| 71 |
|
| 72 |
my @files = split(/\n/, $commit{files}); |
| 73 |
my @message = map { s/^ {4}//r } split(/\n/, asciify($commit{message})); |
| 74 |
my $first_line = shift(@message) =~ s/^$files[-1]: //r; |
| 75 |
my $intro = sprintf('* %s: %s', join(', ', @files), $first_line); |
| 76 |
|
| 77 |
print fill("\t", "\t", $intro), "\n"; |
| 78 |
foreach my $line (@message) { |
| 79 |
print "\t$line" if length($line) > 0; |
| 80 |
print "\n"; |
| 81 |
} |
| 82 |
print "\n"; |
| 83 |
} |