0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-22 15:48:31 +00:00
org-mode/UTILITIES/make_emacs_changelog
Achim Gratz ca117aae00 simplify parsing in make_emacs_changelog
* UTILITIES/make_emacs_changelog: Re-write log parser using a custom
  git-log format and omit comments from output.
2012-05-30 12:30:22 +02:00

95 lines
2.6 KiB
Perl
Executable file

#!/usr/bin/perl
$commitrange = shift @ARGV;
if (!$commitrange) {
print STDERR "Enter commitrange: ";
$commitrange = <>;
$commitrange =~ s/\s*(.*?)\s+/$1/;
}
$syncdate = shift @ARGV;
if (!$syncdate) {
print STDERR "Enter syncdate YYYY-MM-DD: ";
$syncdate = <>;
$syncdate =~ s/\s*(.*?)\s+/$1/;
}
$kind = shift @ARGV;
if (!$kind) {
print STDERR 'Enter kind ("lisp" or "texi" or "card" or press RET): ';
$kind = <>;
$kind =~ s/\s*(.*?)\s+/$1/;
$kind =~ s/"(.*?)"/$1/;
}
if ($kind ne "lisp" and $kind ne "texi" and $kind ne "card"
and $kind ne "") {
die "Invalid Changelog kind";
}
# Run git log to get the commits the messages
open IN,"git log --no-merges --format='%aN%n<%aE>%n%b%x0c' $commitrange|";
undef $/;
$log = <IN>;
@commits = split(/\f/,$log);
foreach my $commit (@commits) {
$name = ( $commit=~ s/([^\n]+)\n//m ) ? $1 : "N/A";
$address = ( $commit=~ s/([^\n]+)\n//m ) ? $1 : "N/A";
$tiny = $commit =~ s/TINYCHANGE//mg ? " (tiny change)" : "";
$entry = $commit;
if ($entry) {
# add linebreaks before each starred line except the very first
$entry =~ s/\A\n*/@/mg;
$entry =~ s/^\*/\n*/mg;
$entry =~ s/\A@//mg;
# normalize starred lines
$entry =~ s/^(\*[^(]*\S)\(/\1 (/mg;
# remove blocks of more than one empty line
$entry =~s/(\n\s*){3,}/\n\n/mg;
# Fix the path when directories have been omitted
$entry =~ s/^\* ([-a-zA-Z]+\.el)/* lisp\/$1/mg;
$entry =~ s/^\* (org[a-z]*\.texi?)/* doc\/$1/mg;
# remove stuff which is not for this output
if ($kind =~ /\S/) {
remove_parts("contrib/","testing/","xemacs/","UTILITIES/","etc/");
remove_parts(".*Makefile","README",".+\.mk");
}
if ($kind eq "lisp") { remove_parts("doc/") }
if ($kind eq "texi") { remove_parts("lisp/","doc/orgcard","doc/orgguide") }
if ($kind eq "card") { remove_parts("lisp/","doc/org\\.","doc/orgguide") }
# remove/replace parts of the path
$entry =~ s:^\* lisp/:* :mg;
$entry =~ s:^\* doc/orgcard:* refcards/orgcard:mg;
$entry =~ s:^\* doc/:* misc/:mg;
# remove empty space at beginning and end
$entry =~ s/\A\s*//;
$entry =~ s/\s*\Z//;
# remove everything that is not a starred entry
$entry = join( "\n\n", grep( /^\*/, split( /\n\n/, $entry )));
# If there is anything left in the entry, print it
if ($entry =~ /\S/) {
# indent each line by exactly one TAB
$entry =~ s/^/\t/mg;
print "$syncdate $name $address$tiny\n\n$entry\n\n\n";
}
}
}
sub remove_parts {
foreach $path (@_) {
$re = "^[ \t]*\\*\\s+" . $path . "[^\\000]*?(?=^[ \\t]*\\*|\\Z)";
$entry =~ s/$re/\n$1/mg;
}
}