From: Todd C. Miller Date: Sun, 10 Dec 2017 03:40:28 +0000 (-0700) Subject: Add script to generate ChangeLog from git log output. X-Git-Tag: SUDO_1_8_22^2~47 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5f5a60f822f1cf31e5295c038dce04050dc8358a;p=sudo Add script to generate ChangeLog from git log output. --- diff --git a/MANIFEST b/MANIFEST index 46fc6a1a7..26fb997f7 100644 --- 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 diff --git a/Makefile.in b/Makefile.in index 9f68e5b22..1c732a9e6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 index 000000000..efae9e211 --- /dev/null +++ b/log2cl.pl @@ -0,0 +1,103 @@ +#!/usr/bin/env perl +# +# Copyright (c) 2017 Todd C. Miller +# +# 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 () { + 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 + $_ = ; + 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; +}