gencl
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
eval '(exit $?0)' && eval 'exec perl -wS "$0" "$@"'
& eval 'exec perl -wS "$0" $argv:q'
if 0;
use strict;
use POSIX qw(strftime);
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
my @append_files;
my $force;
my $verbose;
my $changelog_file = 'ChangeLog';
GetOptions('append|a=s@' => \@append_files,
'file|F=s' => \$changelog_file,
'force|f' => \$force,
'verbose|v' => \$verbose) or exit(1);
if (! -d '.git') {
exit 0;
}
my ($hash, $date) = split / /, `git log --max-count=1 --pretty=format:'%H %ad' --date=short HEAD`;
my @modlines;
if (open(my $fd, '-|', 'git diff-index --name-status HEAD 2>/dev/null')) {
chomp(@modlines = map {chomp; [split /\s+/, $_, 2]} <$fd>);
close $fd;
}
if (@modlines) {
$date = strftime '%Y-%m-%d', localtime;
}
my @header;
push @header, "$date Automatically generated <bug-mailutils\@gnu.org>";
push @header, '';
push @header, "\tHEAD $hash";
push @header, '';
my %status = (
A => 'New file',
C => 'Copied file',
D => 'Removed file',
M => 'Changed',
R => 'Renamed',
T => 'Type change',
U => 'Unmerged',
X => 'Unknown'
);
if (@modlines) {
push @header, "\tUncommitted changes:";
push @header, '';
push @header, map {
"\t* $_->[1]: " . ($status{$_->[0]} || 'Unknown') . ";"
} @modlines;
push @header, '';
}
sub headcmp {
my $file = shift;
if (open(my $fd, '<', $changelog_file)) {
while (<$fd>) {
my $line = shift;
last unless defined($line);
chomp;
return 0 unless $line eq $_;
}
return 1 unless @_;
}
return 0;
}
if (!$force && headcmp($changelog_file, @header)) {
exit 0;
}
print " GEN $changelog_file\n" if $verbose;
close STDOUT;
open(STDOUT, '>', $changelog_file)
or die "Can't open $changelog_file for writing: $!";
for (@header) {
print "$_\n";
}
system(@ARGV);
foreach my $file (@append_files) {
if (open(my $fd, '<', $file)) {
while (<$fd>) {
chomp;
last if /^Local Variables:/;
next if /^\f$/;
print "$_\n";
}
close $fd;
} else {
warn "can't open $file: $!";
}
}
print "\f\nLocal Variables:\n";
print <<'EOT';
mode: change-log
version-control: never
buffer-read-only: t
End:
EOT
;