]> granicus.if.org Git - sudo/commitdiff
Add script to generate ChangeLog from git log output.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Sun, 10 Dec 2017 03:40:28 +0000 (20:40 -0700)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Sun, 10 Dec 2017 03:40:28 +0000 (20:40 -0700)
MANIFEST
Makefile.in
log2cl.pl [new file with mode: 0755]

index 46fc6a1a7b28441678aee0acf5cbf41db2d64e08..26fb997f7e0756efedc6f5abe38b731748cbeacc 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -207,6 +207,7 @@ lib/zlib/zlib.exp
 lib/zlib/zlib.h
 lib/zlib/zutil.c
 lib/zlib/zutil.h
+log2cl.pl
 ltmain.sh
 m4/ax_append_flag.m4
 m4/ax_check_compile_flag.m4
index 9f68e5b2266a359ed01a9e13d42810ea8dc496b7..1c732a9e68b86c5b6bd9c24d00f96a54b80b4e1a 100644 (file)
@@ -185,6 +185,10 @@ ChangeLog:
            else \
                rm -f $@.tmp; \
            fi; \
+       elif test -d $(srcdir)/.git && cd $(srcdir); then \
+           $(top_srcdir)/log2cl.pl -b master > $@; \
+       else \
+           echo "ChangeLog data not available" > $@; \
        fi
 
 config.status:
diff --git a/log2cl.pl b/log2cl.pl
new file mode 100755 (executable)
index 0000000..efae9e2
--- /dev/null
+++ b/log2cl.pl
@@ -0,0 +1,103 @@
+#!/usr/bin/env perl
+#
+# Copyright (c) 2017 Todd C. Miller <Todd.Miller@sudo.ws>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Simple script to massage "git log" output into a GNU style ChangeLog.
+# The goal is to emulate "hg log --style=changelog" via perl format.
+
+use warnings;
+
+my $format="%ad  %aN  <%aE>%n%h%n%s%n%b%nFILES:";
+my @cmd = ("git", "log", "--log-size", "--name-only", "--date=short", "--format=$format", @ARGV);
+open(LOG, '-|', @cmd) || die "$0: unable to run git log: $!";
+
+my $hash;
+my $body;
+my @files;
+my $key_date = "";
+my $log_size = 0;
+my $state = 0;
+
+while (<LOG>) {
+    chomp;
+    if (/^log size (\d+)$/) {
+       # XXX - should use log_size to make sure we get the entire entry
+       $log_size = $1;
+
+       # Print previous entry if there is one
+       print_entry($hash, $body, @files) if defined($hash);
+
+       # Init new entry
+       $state = 1;
+       undef $hash;
+       undef $body;
+       undef @files;
+
+       # Check for continued entry
+       $_ = <LOG>;
+       last unless defined($_);
+       chomp;
+       if ($_ ne $key_date) {
+           # New entry
+           print "$_\n\n";
+           $key_date = $_;
+       }
+    } elsif (/^FILES:$/) {
+       $state = 3;
+    } else {
+       if ($state == 1) {
+           # hash
+           $hash = $_;
+           $state++;
+       } elsif ($state == 2) {
+           # message body
+           if (defined($body)) {
+               $body .= " $_";
+           } else {
+               $body = $_;
+           }
+       } elsif ($state == 3) {
+           # file list
+           push(@files, $_) unless $_ eq "";
+       } else {
+           warn "unexpected state $state for $_\n";
+       }
+    }
+}
+
+# Print the last entry
+print_entry($hash, $body, @files) if defined($hash);
+
+exit(0);
+
+sub print_entry
+{
+    my $hash = '[' . shift . ']';
+    my $body = shift;
+    my $files = "* " . join(", ", @_) . ":";
+
+    local $= = 9999;   # to silence warning (hack)
+
+    format =
+       ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
+       $files
+       ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
+       $body
+       ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+       $hash
+
+.
+    write;
+}