make_emacs_changelog 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/perl
  2. $commitrange = shift @ARGV;
  3. if (!$commitrange) {
  4. print STDERR "Enter commitrange: ";
  5. $commitrange = <>;
  6. $commitrange =~ s/\s*(.*?)\s+/$1/;
  7. }
  8. $syncdate = shift @ARGV;
  9. if (!$syncdate) {
  10. print STDERR "Enter syncdate YYYY-MM-DD: ";
  11. $syncdate = <>;
  12. $syncdate =~ s/\s*(.*?)\s+/$1/;
  13. }
  14. $kind = shift @ARGV;
  15. if (!$kind) {
  16. print STDERR 'Enter kind ("lisp" or "texi" or "card" or press RET): ';
  17. $kind = <>;
  18. $kind =~ s/\s*(.*?)\s+/$1/;
  19. $kind =~ s/"(.*?)"/$1/;
  20. }
  21. if ($kind ne "lisp" and $kind ne "texi" and $kind ne "card"
  22. and $kind ne "") {
  23. die "Invalid Changelog kind";
  24. }
  25. # Run git log to get the commits the messages
  26. open IN,"git log --no-merges --format='%aN%n<%aE>%n%b%x0c' $commitrange|";
  27. undef $/;
  28. $log = <IN>;
  29. @commits = split(/\f/,$log);
  30. foreach my $commit (@commits) {
  31. $name = ( $commit=~ s/([^\n]+)\n//m ) ? $1 : "N/A";
  32. $address = ( $commit=~ s/([^\n]+)\n//m ) ? $1 : "N/A";
  33. $tiny = $commit =~ s/TINYCHANGE//mg ? " (tiny change)" : "";
  34. $entry = $commit;
  35. if ($entry) {
  36. # add linebreaks before each starred line except the very first
  37. $entry =~ s/\A\n*/@/mg;
  38. $entry =~ s/^\*/\n*/mg;
  39. $entry =~ s/\A@//mg;
  40. # normalize starred lines
  41. $entry =~ s/^(\*[^(]*\S)\(/\1 (/mg;
  42. # remove blocks of more than one empty line
  43. $entry =~s/(\n\s*){3,}/\n\n/mg;
  44. # Fix the path when directories have been omitted
  45. $entry =~ s/^\* ([-a-zA-Z]+\.el)/* lisp\/$1/mg;
  46. $entry =~ s/^\* (org[a-z]*\.texi?)/* doc\/$1/mg;
  47. # remove stuff which is not for this output
  48. if ($kind =~ /\S/) {
  49. remove_parts("contrib/","testing/","xemacs/","UTILITIES/","etc/");
  50. remove_parts(".*Makefile","README",".+\.mk");
  51. }
  52. if ($kind eq "lisp") { remove_parts("doc/") }
  53. if ($kind eq "texi") { remove_parts("lisp/","doc/orgcard","doc/orgguide") }
  54. if ($kind eq "card") { remove_parts("lisp/","doc/org\\.","doc/orgguide") }
  55. # remove/replace parts of the path
  56. $entry =~ s:^\* lisp/:* :mg;
  57. $entry =~ s:^\* doc/orgcard:* refcards/orgcard:mg;
  58. $entry =~ s:^\* doc/:* misc/:mg;
  59. # remove empty space at beginning and end
  60. $entry =~ s/\A\s*//;
  61. $entry =~ s/\s*\Z//;
  62. # remove everything that is not a starred entry
  63. $entry = join( "\n\n", grep( /^\*/, split( /\n\n/, $entry )));
  64. # If there is anything left in the entry, print it
  65. if ($entry =~ /\S/) {
  66. # indent each line by exactly one TAB
  67. $entry =~ s/^/\t/mg;
  68. print "$syncdate $name $address$tiny\n\n$entry\n\n\n";
  69. }
  70. }
  71. }
  72. sub remove_parts {
  73. foreach $path (@_) {
  74. $re = "^[ \t]*\\*\\s+" . $path . "[^\\000]*?(?=^[ \\t]*\\*|\\Z)";
  75. $entry =~ s/$re/\n$1/mg;
  76. }
  77. }