summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-09-27 22:58:02 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-09-27 22:58:02 (GMT)
commit4ad0f80ec3a136d1c45ee7a9957a8acdef6d4afc (patch)
tree4e57aa36762fe168b57e32bffb6115f8cdb57eb2 /tools
parent9ae1cd8f91aa6b53404e66588679d852d3972bcd (diff)
downloadmonitoring-plugins-4ad0f80ec3a136d1c45ee7a9957a8acdef6d4afc.tar.gz
Add tools/generate-change-log
Add the tools/generate-change-log script for auto-generating the ChangeLog file from the Git history when running "make dist".
Diffstat (limited to 'tools')
-rwxr-xr-xtools/generate-change-log67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/generate-change-log b/tools/generate-change-log
new file mode 100755
index 0000000..03321fd
--- /dev/null
+++ b/tools/generate-change-log
@@ -0,0 +1,67 @@
1#!/usr/bin/env perl
2#
3# Copyright (c) 2013 Nagios Plugins Development Team
4#
5# Originally written by Holger Weiss <holger@zedat.fu-berlin.de>.
6#
7# This file is free software; the Nagios Plugins Development Team gives
8# unlimited permission to copy and/or distribute it, with or without
9# modifications, as long as this notice is preserved.
10#
11# This program is distributed in the hope that it will be useful, but WITHOUT
12# ANY WARRANTY, to the extent permitted by law; without even the implied
13# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14#
15
16use warnings;
17use strict;
18use Text::Wrap;
19
20# The lines will have a length of no more than $columns - 1.
21$Text::Wrap::columns = 81;
22
23if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) {
24 print "Not a Git repository, so I won't update the ChangeLog.\n";
25 exit 0;
26}
27
28my $regex =
29 '^commit [0-9a-f]+\n' .
30 '^Author: (?<name>.+) <(?<email>.*)>\n' .
31 '^Date: (?<date>\d{4}-\d{2}-\d{2})\n' .
32 '^\n' .
33 '(?<message>(^ .*\n)+)' .
34 '^\n' .
35 '(?<files>(^.+\n)+)';
36
37my $git_log = qx'git log -M -C --stat --name-only --date=short';
38die "Cannot get `git log' output\n" if $? != 0;
39
40my ($prev_date, $prev_name, $prev_email);
41
42while ($git_log =~ /$regex/gm) {
43 my %commit = %+;
44
45 if (not defined $prev_date
46 or $commit{date} ne $prev_date
47 or $commit{name} ne $prev_name
48 or $commit{email} ne $prev_email) {
49 print "$commit{date} $commit{name} <$commit{email}>\n\n";
50 }
51 $prev_date = $commit{date};
52 $prev_name = $commit{name};
53 $prev_email = $commit{email};
54
55 my @files = split(/\n/, $commit{files});
56 my @message = map { s/^ {4}//; $_ } split(/\n/, $commit{message});
57 my $first_line = shift(@message);
58 $first_line =~ s/^$files[-1]: //;
59 my $intro = sprintf('* %s: %s', join(', ', @files), $first_line);
60
61 print fill("\t", "\t", $intro), "\n";
62 foreach my $line (@message) {
63 print "\t$line" if length($line) > 0;
64 print "\n";
65 }
66 print "\n";
67}