2008-09-25 11:17:08 +00:00
|
|
|
#!/usr/bin/env perl
|
2019-03-19 11:08:17 +01:00
|
|
|
# Copyright: 2008, The Geany contributors
|
2009-09-04 11:21:29 +00:00
|
|
|
# License: GNU GPL V2 or later, as published by the Free Software Foundation, USA.
|
2008-09-25 11:17:08 +00:00
|
|
|
# Warranty: NONE
|
2008-04-01 12:53:26 +00:00
|
|
|
|
|
|
|
# Searches a ChangeLog file for a line matching 'matchstring', then matches
|
|
|
|
# all lines until two consecutive empty lines are found. The process then
|
|
|
|
# repeats until all matching blocks of text are found.
|
|
|
|
# Results are printed in reverse, hence in chronological order (as ChangeLogs
|
|
|
|
# are usually written in reverse date order).
|
2009-08-14 13:50:41 +00:00
|
|
|
#
|
|
|
|
# The resulting lines are then formatted to be easier to read and edit into a
|
|
|
|
# NEWS file.
|
|
|
|
|
|
|
|
# Example ChangeLog format:
|
|
|
|
#2009-04-03 Joe Author <joe@example.net>
|
|
|
|
#
|
|
|
|
# * src/file.c, src/file.h,
|
|
|
|
# src/another.c:
|
|
|
|
# Some change description,
|
|
|
|
# spanning several lines.
|
2009-08-14 15:09:21 +00:00
|
|
|
# * foo.c: Combined line.
|
2008-04-01 12:53:26 +00:00
|
|
|
|
|
|
|
use strict;
|
2008-09-25 11:17:08 +00:00
|
|
|
use warnings;
|
2008-04-01 12:53:26 +00:00
|
|
|
|
|
|
|
my $argc = $#ARGV + 1;
|
2010-12-30 18:13:21 +00:00
|
|
|
my ($matchstr, $infile);
|
2008-04-01 12:53:26 +00:00
|
|
|
|
2010-12-30 18:13:21 +00:00
|
|
|
if ($argc == 1)
|
|
|
|
{
|
|
|
|
($infile) = @ARGV;
|
|
|
|
$matchstr = '.';
|
|
|
|
}
|
|
|
|
elsif ($argc == 2)
|
|
|
|
{
|
|
|
|
($matchstr, $infile) = @ARGV;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die <<END;
|
2009-08-14 13:50:41 +00:00
|
|
|
Usage:
|
2010-12-30 18:13:21 +00:00
|
|
|
$0 changelogfile >outfile
|
2009-09-04 11:21:29 +00:00
|
|
|
$0 matchstring changelogfile >outfile
|
2009-08-14 13:50:41 +00:00
|
|
|
|
2010-12-30 18:13:21 +00:00
|
|
|
matchstring is a case-insensitive regular expression, e.g. 'joe|fred'.
|
2009-08-14 13:50:41 +00:00
|
|
|
END
|
2010-12-30 18:13:21 +00:00
|
|
|
}
|
2008-04-01 12:53:26 +00:00
|
|
|
|
|
|
|
open(INPUT, $infile)
|
|
|
|
or die "Couldn't open $infile for reading: $!\n";
|
|
|
|
|
|
|
|
my $entry; # the current matching block of text
|
2009-08-14 13:50:41 +00:00
|
|
|
my @entries; # changelog entries, one per date
|
|
|
|
|
|
|
|
# first parse each ChangeLog entry into an array
|
|
|
|
|
2008-04-01 12:53:26 +00:00
|
|
|
my $found = 0; # if we're in a matching block of text
|
|
|
|
my $blank = 0; # whether the last line was empty
|
|
|
|
|
|
|
|
while (<INPUT>) {
|
|
|
|
my $line = $_; # read a line, including \n char
|
|
|
|
|
|
|
|
if (! $found) {
|
|
|
|
($line =~ m/$matchstr/) and $found = 1;
|
|
|
|
} else {
|
2009-08-14 13:50:41 +00:00
|
|
|
if (length($line) <= 1) { # current line is empty
|
2008-04-01 12:53:26 +00:00
|
|
|
if ($blank > 0) { # previous line was also empty
|
|
|
|
push(@entries, $entry); # append entry
|
|
|
|
$entry = "";
|
|
|
|
$found = 0; # now look for next match
|
|
|
|
$blank = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$blank = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-14 13:50:41 +00:00
|
|
|
if ($found) {
|
|
|
|
$entry .= $line;
|
|
|
|
}
|
2008-04-01 12:53:26 +00:00
|
|
|
}
|
|
|
|
close(INPUT);
|
|
|
|
|
2009-08-14 13:50:41 +00:00
|
|
|
# reformat entries
|
2008-04-01 12:53:26 +00:00
|
|
|
foreach $entry (reverse @entries) {
|
2009-08-14 13:50:41 +00:00
|
|
|
my @lines = split(/\n/, $entry);
|
|
|
|
my $fl = 0; # in file list lines
|
|
|
|
my $cm = 0; # in commit message lines
|
|
|
|
|
|
|
|
foreach my $line (@lines){
|
|
|
|
my $flset = $fl;
|
|
|
|
|
2009-08-14 16:21:29 +00:00
|
|
|
# strip trailing space
|
|
|
|
$line =~ s/\s+$//g;
|
|
|
|
|
2009-08-14 13:50:41 +00:00
|
|
|
if (!$cm){
|
|
|
|
# check if in filelist
|
|
|
|
($line =~ m/ \* /) and $fl = 1;
|
|
|
|
# join filelist together on one line
|
|
|
|
$fl and ($line =~ s/^ / /);
|
2009-08-14 15:09:21 +00:00
|
|
|
if ($fl and ($line =~ m/:/)){
|
|
|
|
$fl = 0;
|
|
|
|
# separate ' * foo.c: Some edit.' messages:
|
|
|
|
if (!($line =~ m/:$/)) {
|
|
|
|
($line =~ s/:/:\n*/);
|
|
|
|
}
|
|
|
|
}
|
2009-08-14 13:50:41 +00:00
|
|
|
$fl and ($line =~ m/,$/) or $fl = 0;
|
|
|
|
}
|
|
|
|
if (!$flset){
|
|
|
|
# Asterisk commit messages
|
|
|
|
if (!$cm and ($line =~ m/^ /)){
|
|
|
|
$cm = 1;
|
|
|
|
$line =~ s/^( )/$1* /;
|
|
|
|
} else {
|
|
|
|
$cm and ($line =~ s/^( )/$1 /); # indent continuing lines
|
|
|
|
}
|
|
|
|
$cm and ($line =~ m/\.$/) and $cm = 0;
|
|
|
|
}
|
|
|
|
#~ print $fl.','.$cm.','.$line."\n"; next; # debug
|
|
|
|
|
|
|
|
# change file list start char to easily distinguish between file list and commit messages
|
|
|
|
$line =~ s/^ \* /@ /g;
|
2009-08-14 16:21:29 +00:00
|
|
|
# strip <email> from date line
|
|
|
|
$line =~ s/^([0-9-]+.*?)\s+<.+>$/$1/g;
|
2009-08-14 13:50:41 +00:00
|
|
|
# remove indent
|
|
|
|
$line =~ s/^ //g;
|
|
|
|
|
|
|
|
if ($line ne ""){
|
|
|
|
print $line;
|
|
|
|
(!$fl) and print "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print "\n";
|
2008-04-01 12:53:26 +00:00
|
|
|
}
|