From: Nick Bowler Date: Thu, 27 Jul 2023 02:51:44 +0000 (-0400) Subject: Use gitlog-to-changelog w/ "make dist". X-Git-Tag: v1~9 X-Git-Url: http://git.draconx.ca/gitweb/rarpd-dx.git/commitdiff_plain/74180c354fa89301c5a3dbdf3d15709ab16439f9 Use gitlog-to-changelog w/ "make dist". --- diff --git a/ChangeLog b/ChangeLog index e2db6c3..4e0b7e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,341 +1 @@ -2020-08-29 Nuno Silva - - common: fix infinite loop when getrandom fails - - Fixes: https://github.com/iputils/iputils/issues/291 - -2020-01-06 Sami Kerola - - common: flush streams before closing them - - On loaded systems slow tty can give false positive exit failure due pending - bytes. Flush the streams that hopefully makes these problems less likely. - - Reference: https://github.com/iputils/iputils/commit/4655ecc5105c383669ef529f21f3344f99e7372f#commitcomment-36628770 - -2019-11-24 Sami Kerola - - rdisc / ninfod: fix format string warning - - warning: format string is not a string literal [-Wformat-nonliteral] - - The above was reported for rdisc.c lines 210 and 212, and ninfod/ninfod.c - lines 162 and 165. - - Reviewed-by: Petr Vorel - -2019-10-31 Philipp Kammerer - - doc: Proofreading rarpd.xml - - A few suggestions to make the manpage more easy to read - -2019-10-17 Maciej Żenczykowski - - iputils_common.h: fix missing #include - - This fixes: - In file included from ping/ping6_common.c:61: - iputils_common.h:63:32: error: declaration of 'struct timespec' will not be visible outside of this function [-Werror,-Wvisibility] - extern void timespecsub(struct timespec *a, struct timespec *b, - ^ - - Change-Id: Icc30a25c30fc606f46def07704cdc6997018d58f - -2019-09-10 Sami Kerola - - ninfod: retire gettimeofday() in favor of clock_gettime() - - Apply to ninfod similar fix as da9a6105b2cab2f92135a282d00cc939760e64c0. - - Discussion about this and the next change spanned over several pull - requests that are mentioned below. - - Reference: https://github.com/iputils/iputils/pull/213 - Reference: https://github.com/iputils/iputils/pull/214 - Reference; https://github.com/iputils/iputils/pull/215 - Acked-by: Petr Vorel - -2019-09-10 Sami Kerola - - common: make seeding pseudo-random number generator easy - - Unify how srand() calls are done, with some care to try avoiding bad - seeding with hope pseudo-random numbers are unpredictable. - - Acked-by: Petr Vorel - -2019-06-10 Petr Vorel - - common: move various fallback definitions into iputils_common.h - -2019-03-25 Jan Tojnar - - doc: Use namespace correctly - - The files declared xmlns:db but did not use the db namespace at all. - They did not define the default namespace at all, which coincidentally - worked with Docbook 4 stylesheets, making them think the files were - written in Docbook 4. - - I fixed the namespaces of the documents and switched to the correct - Docbook 5 stylesheets. - -2019-03-23 Sami Kerola - - common: use single ARRAY_SIZE definition across files - - The ARRAY_SIZE is Rusty Russell’s version, that looks a bit more complicated - than the original, but there is a reason to that. This macro will ensure - macro is used properly, and fail compilation if it is not. See reference - link for further explanation. - - Reference: http://zubplot.blogspot.com/2015/01/gcc-is-wonderful-better-arraysize-macro.html - -2019-03-09 Sami Kerola - - documentation: fix various spelling typos - - Foudn with codespell. - - Reference: https://github.com/codespell-project/codespell - -2019-02-03 Sami Kerola - - libcommon: add string to a number conversion function - - Based on standard libc strtol(), but has convenience wrapping to catch - errors so that one can convert numbers with just a single function call. - -2019-02-02 Sami Kerola - - clang scan-build: fix various build warning - - arping: fix dereference of null pointer. - clockdiff: fix assigned value is garbage or undefined warnings. - ninfod: fix dead assignment and use of uninitialized argument value. - ping: fix dead assignment. - rarpd: fix uninitialized argument value. - rdisc: fix uninitialized argument value. - tracepath: fix dereference of null pointer. - -2019-01-01 Sami Kerola - - rarpd: use libc function to run in the background - - ninfod: check writing a pid file was successful - -2019-01-01 Sami Kerola - - libcommon: check standard streams status at exit - - Earlier commands happily successed when writing to standard out or error did - not work. Following demonstrates old and new behavior of all commands in - this project. - - $ ping -c 1 127.0.0.1 > /dev/full ; echo $? - 0 - $ ping -c 1 127.0.0.1 > /dev/full ; echo $? - ./builddir/ping: write error: No space left on device - 1 - -2018-12-22 Sami Kerola - - rarpd: use error() to report command errors - -2018-12-22 Sami Kerola - - common: move error() portability go-around to common library - - This allows use of error() in other programs. The static common library can - also be used for other utility functions in future. - -2018-12-20 Sami Kerola - - man: reindent xml files - - Due to great amount of change in this update normal review is not possible. - I used following to ensure there are no unexpected changes. - - # Generate old manual pages. - git checkout origin/master - make clean && make - mkdir a - for i in builddir/doc/*; do man $i > a/${i##*/}; done - # Generate new manual pages. - git checkout - make clean && make - mkdir b - for i in builddir/doc/*; do man $i > b/${i##*/}; done - # Compare. - diff -ruP a b - -2018-12-20 Sami Kerola - - man: update to docbook 5 - -2018-12-20 Sami Kerola - - man: fix rarpd command name in synopsis - - While going through this manual page I noticed --help output being - incomplete, so lets sort that out in same go. - -2018-12-18 Sami Kerola - - localization: move nls headers to iputils_common.h - - Aboid boilerplating. - -2018-10-03 Sami Kerola - - warnings: fix multiple errno printing format specifier issues - - All of these report same warning: - ISO C does not support the ‘%m’ gnu_printf format [-Wformat=] - -2018-10-03 Sami Kerola - - add version print out to remaining commands - - For some reason version print out was not implemented in all commands. This - fixes that. - -2018-10-03 Sami Kerola - - ping, rarpd, rdisc: remove historical no-op SA_INTERRUPT - - The sigaction option SA_INTERRUPT has been no-op for long time. - - Reference: https://lwn.net/Articles/229673/ - -2018-10-03 Sami Kerola - - usage: unify usage outputs, and improve their helpfulness - - Just listing options, like ping(8) did, does not help users. - -2018-10-03 Sami Kerola - - various: do not use kernel data types in userspace - - It is long standing recommendation not to mix kernel and user space headers. - See reference for details. - - Reference: https://lwn.net/Articles/113349/ - -2018-10-03 Sami Kerola - - docs: fix docbook xml expectations warnings - - This version of xslproc: - - $ xsltproc --version - Using libxml 20907, libxslt 10132-GITv1.1.32-3-g32c88216 and libexslt 820 - xsltproc was compiled against libxml 20906, libxslt 10132 and libexslt 820 - libxslt 10132 was compiled against libxml 20906 - libexslt 820 was compiled against libxml 20906 - - Printed following warning at each manual page creation. - - [17/25] Generating arping.8 with a custom command. - Note: meta source : no *info/productname or alternative arping - Note: meta source : see http://www.docbook.org/tdg5/en/html/produ arping - Note: meta source : no refentry/refmeta/refmiscinfo@class=source arping - Note: meta source : see http://www.docbook.org/tdg5/en/html/refmi arping - Note: meta version: no *info/productnumber or alternative arping - Note: meta version: see http://www.docbook.org/tdg5/en/html/produ arping - Note: meta version: no refentry/refmeta/refmiscinfo@class=version arping - Note: meta version: see http://www.docbook.org/tdg5/en/html/refmi arping - Warn: meta source : using "iputils" for "source" arping - -2018-10-03 Sami Kerola - - warnings: fix multiple unused parameter warnings - - This fixes multiple instances of unnused parameter warnings, that look like: - ping.c:1025:36: warning: unused parameter 'len' [-Wunused-parameter] - -2018-10-03 Sami Kerola - - warnings: fix multiple signed and unsigned integer expressions - - This fixes many many instances of the following warnings. - - warning: comparison between signed and unsigned integer expressions - [-Wsign-compare] - - Unfortunately the fix includes lots of type casts. Each of them was - considered from overflow point of view, and will hopefully not cause any - issues. - -2018-10-03 Sami Kerola - - warnings: fix rarpd variable initialisation - - Refer struct field names in initialiser, and trust compilers to be standard - compliant and fill rest of the data with zeros. This fixes following - compiler warning: - - rarpd.c:307:4: warning: missing initializer for field 'lladdr' of 'struct - rarp_map' [-Wmissing-field-initializers] - -2018-10-03 Sami Kerola - - warnings: add marker to implicit fallthrough - - This fixes an implicit fallthrough warning, that looks like: - rarpd.c:483:41: warning: this statement may fall through [-Wimplicit-fallthrough=] - -2018-10-03 Sami Kerola - - warnings: remove variable shadowing - - This fixes multiple instances of variable shadowing warning, that look like: - warning: declaration of 'var' shadows a previous local [-Wshadow] - -2017-08-05 David Heidelberg - - doc: convert from converting SGML to XML - - This work is mostly inspired by systemd manpages procedure creation. [1] - - With this commit, you can freely throw SGML tools and you should be fine - with xsltproc :) - - Enjoy! - - Also, please don't be shy fix bugs, it will need more polishing! - - [1] https://github.com/systemd/systemd/tree/master/man - - Fixes bug: https://github.com/iputils/iputils/issues/1 - Fixes bug: https://github.com/iputils/iputils/issues/27 - -2014-04-18 David Heidelberger - - replace non-POSIX compilant caddr_t with char * - - fix include paths, now compile with both glibc and musl - -2012-01-09 YOSHIFUJI Hideaki - - rarpd: Check return value of chdir(). - -2007-10-12 YOSHIFUJI Hideaki - - [RARPD]: Fixed several signedness issues for char strings. - -2007-04-04 YOSHIFUJI Hideaki - - Fix white space errors. - -2006-12-20 Mike Frysinger - - [PATCH] Use socklen_t in all the right places. - -2006-04-16 YOSHIFUJI Hideaki - - Initial import of iputils - - Obtained from . +Stub changelog, see the git history for changes. diff --git a/ChangeLog.iputils b/ChangeLog.iputils new file mode 100644 index 0000000..e2db6c3 --- /dev/null +++ b/ChangeLog.iputils @@ -0,0 +1,341 @@ +2020-08-29 Nuno Silva + + common: fix infinite loop when getrandom fails + + Fixes: https://github.com/iputils/iputils/issues/291 + +2020-01-06 Sami Kerola + + common: flush streams before closing them + + On loaded systems slow tty can give false positive exit failure due pending + bytes. Flush the streams that hopefully makes these problems less likely. + + Reference: https://github.com/iputils/iputils/commit/4655ecc5105c383669ef529f21f3344f99e7372f#commitcomment-36628770 + +2019-11-24 Sami Kerola + + rdisc / ninfod: fix format string warning + + warning: format string is not a string literal [-Wformat-nonliteral] + + The above was reported for rdisc.c lines 210 and 212, and ninfod/ninfod.c + lines 162 and 165. + + Reviewed-by: Petr Vorel + +2019-10-31 Philipp Kammerer + + doc: Proofreading rarpd.xml + + A few suggestions to make the manpage more easy to read + +2019-10-17 Maciej Żenczykowski + + iputils_common.h: fix missing #include + + This fixes: + In file included from ping/ping6_common.c:61: + iputils_common.h:63:32: error: declaration of 'struct timespec' will not be visible outside of this function [-Werror,-Wvisibility] + extern void timespecsub(struct timespec *a, struct timespec *b, + ^ + + Change-Id: Icc30a25c30fc606f46def07704cdc6997018d58f + +2019-09-10 Sami Kerola + + ninfod: retire gettimeofday() in favor of clock_gettime() + + Apply to ninfod similar fix as da9a6105b2cab2f92135a282d00cc939760e64c0. + + Discussion about this and the next change spanned over several pull + requests that are mentioned below. + + Reference: https://github.com/iputils/iputils/pull/213 + Reference: https://github.com/iputils/iputils/pull/214 + Reference; https://github.com/iputils/iputils/pull/215 + Acked-by: Petr Vorel + +2019-09-10 Sami Kerola + + common: make seeding pseudo-random number generator easy + + Unify how srand() calls are done, with some care to try avoiding bad + seeding with hope pseudo-random numbers are unpredictable. + + Acked-by: Petr Vorel + +2019-06-10 Petr Vorel + + common: move various fallback definitions into iputils_common.h + +2019-03-25 Jan Tojnar + + doc: Use namespace correctly + + The files declared xmlns:db but did not use the db namespace at all. + They did not define the default namespace at all, which coincidentally + worked with Docbook 4 stylesheets, making them think the files were + written in Docbook 4. + + I fixed the namespaces of the documents and switched to the correct + Docbook 5 stylesheets. + +2019-03-23 Sami Kerola + + common: use single ARRAY_SIZE definition across files + + The ARRAY_SIZE is Rusty Russell’s version, that looks a bit more complicated + than the original, but there is a reason to that. This macro will ensure + macro is used properly, and fail compilation if it is not. See reference + link for further explanation. + + Reference: http://zubplot.blogspot.com/2015/01/gcc-is-wonderful-better-arraysize-macro.html + +2019-03-09 Sami Kerola + + documentation: fix various spelling typos + + Foudn with codespell. + + Reference: https://github.com/codespell-project/codespell + +2019-02-03 Sami Kerola + + libcommon: add string to a number conversion function + + Based on standard libc strtol(), but has convenience wrapping to catch + errors so that one can convert numbers with just a single function call. + +2019-02-02 Sami Kerola + + clang scan-build: fix various build warning + + arping: fix dereference of null pointer. + clockdiff: fix assigned value is garbage or undefined warnings. + ninfod: fix dead assignment and use of uninitialized argument value. + ping: fix dead assignment. + rarpd: fix uninitialized argument value. + rdisc: fix uninitialized argument value. + tracepath: fix dereference of null pointer. + +2019-01-01 Sami Kerola + + rarpd: use libc function to run in the background + + ninfod: check writing a pid file was successful + +2019-01-01 Sami Kerola + + libcommon: check standard streams status at exit + + Earlier commands happily successed when writing to standard out or error did + not work. Following demonstrates old and new behavior of all commands in + this project. + + $ ping -c 1 127.0.0.1 > /dev/full ; echo $? + 0 + $ ping -c 1 127.0.0.1 > /dev/full ; echo $? + ./builddir/ping: write error: No space left on device + 1 + +2018-12-22 Sami Kerola + + rarpd: use error() to report command errors + +2018-12-22 Sami Kerola + + common: move error() portability go-around to common library + + This allows use of error() in other programs. The static common library can + also be used for other utility functions in future. + +2018-12-20 Sami Kerola + + man: reindent xml files + + Due to great amount of change in this update normal review is not possible. + I used following to ensure there are no unexpected changes. + + # Generate old manual pages. + git checkout origin/master + make clean && make + mkdir a + for i in builddir/doc/*; do man $i > a/${i##*/}; done + # Generate new manual pages. + git checkout + make clean && make + mkdir b + for i in builddir/doc/*; do man $i > b/${i##*/}; done + # Compare. + diff -ruP a b + +2018-12-20 Sami Kerola + + man: update to docbook 5 + +2018-12-20 Sami Kerola + + man: fix rarpd command name in synopsis + + While going through this manual page I noticed --help output being + incomplete, so lets sort that out in same go. + +2018-12-18 Sami Kerola + + localization: move nls headers to iputils_common.h + + Aboid boilerplating. + +2018-10-03 Sami Kerola + + warnings: fix multiple errno printing format specifier issues + + All of these report same warning: + ISO C does not support the ‘%m’ gnu_printf format [-Wformat=] + +2018-10-03 Sami Kerola + + add version print out to remaining commands + + For some reason version print out was not implemented in all commands. This + fixes that. + +2018-10-03 Sami Kerola + + ping, rarpd, rdisc: remove historical no-op SA_INTERRUPT + + The sigaction option SA_INTERRUPT has been no-op for long time. + + Reference: https://lwn.net/Articles/229673/ + +2018-10-03 Sami Kerola + + usage: unify usage outputs, and improve their helpfulness + + Just listing options, like ping(8) did, does not help users. + +2018-10-03 Sami Kerola + + various: do not use kernel data types in userspace + + It is long standing recommendation not to mix kernel and user space headers. + See reference for details. + + Reference: https://lwn.net/Articles/113349/ + +2018-10-03 Sami Kerola + + docs: fix docbook xml expectations warnings + + This version of xslproc: + + $ xsltproc --version + Using libxml 20907, libxslt 10132-GITv1.1.32-3-g32c88216 and libexslt 820 + xsltproc was compiled against libxml 20906, libxslt 10132 and libexslt 820 + libxslt 10132 was compiled against libxml 20906 + libexslt 820 was compiled against libxml 20906 + + Printed following warning at each manual page creation. + + [17/25] Generating arping.8 with a custom command. + Note: meta source : no *info/productname or alternative arping + Note: meta source : see http://www.docbook.org/tdg5/en/html/produ arping + Note: meta source : no refentry/refmeta/refmiscinfo@class=source arping + Note: meta source : see http://www.docbook.org/tdg5/en/html/refmi arping + Note: meta version: no *info/productnumber or alternative arping + Note: meta version: see http://www.docbook.org/tdg5/en/html/produ arping + Note: meta version: no refentry/refmeta/refmiscinfo@class=version arping + Note: meta version: see http://www.docbook.org/tdg5/en/html/refmi arping + Warn: meta source : using "iputils" for "source" arping + +2018-10-03 Sami Kerola + + warnings: fix multiple unused parameter warnings + + This fixes multiple instances of unnused parameter warnings, that look like: + ping.c:1025:36: warning: unused parameter 'len' [-Wunused-parameter] + +2018-10-03 Sami Kerola + + warnings: fix multiple signed and unsigned integer expressions + + This fixes many many instances of the following warnings. + + warning: comparison between signed and unsigned integer expressions + [-Wsign-compare] + + Unfortunately the fix includes lots of type casts. Each of them was + considered from overflow point of view, and will hopefully not cause any + issues. + +2018-10-03 Sami Kerola + + warnings: fix rarpd variable initialisation + + Refer struct field names in initialiser, and trust compilers to be standard + compliant and fill rest of the data with zeros. This fixes following + compiler warning: + + rarpd.c:307:4: warning: missing initializer for field 'lladdr' of 'struct + rarp_map' [-Wmissing-field-initializers] + +2018-10-03 Sami Kerola + + warnings: add marker to implicit fallthrough + + This fixes an implicit fallthrough warning, that looks like: + rarpd.c:483:41: warning: this statement may fall through [-Wimplicit-fallthrough=] + +2018-10-03 Sami Kerola + + warnings: remove variable shadowing + + This fixes multiple instances of variable shadowing warning, that look like: + warning: declaration of 'var' shadows a previous local [-Wshadow] + +2017-08-05 David Heidelberg + + doc: convert from converting SGML to XML + + This work is mostly inspired by systemd manpages procedure creation. [1] + + With this commit, you can freely throw SGML tools and you should be fine + with xsltproc :) + + Enjoy! + + Also, please don't be shy fix bugs, it will need more polishing! + + [1] https://github.com/systemd/systemd/tree/master/man + + Fixes bug: https://github.com/iputils/iputils/issues/1 + Fixes bug: https://github.com/iputils/iputils/issues/27 + +2014-04-18 David Heidelberger + + replace non-POSIX compilant caddr_t with char * + + fix include paths, now compile with both glibc and musl + +2012-01-09 YOSHIFUJI Hideaki + + rarpd: Check return value of chdir(). + +2007-10-12 YOSHIFUJI Hideaki + + [RARPD]: Fixed several signedness issues for char strings. + +2007-04-04 YOSHIFUJI Hideaki + + Fix white space errors. + +2006-12-20 Mike Frysinger + + [PATCH] Use socklen_t in all the right places. + +2006-04-16 YOSHIFUJI Hideaki + + Initial import of iputils + + Obtained from . diff --git a/Makefile.am b/Makefile.am index e5f558f..31d7c11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,3 +38,49 @@ EXTRA_DIST += $(dist_man_MANS:.8=.xml) $(srcdir)/doc/custom-man.xsl sbin_PROGRAMS = rarpd rarpd_SOURCES = src/rarpd.c src/iputils_common.c src/iputils_common.h + +# When running "make dist" in a VPATH build with a read-only srcdir, Automake +# will produce a distribution with all files read-only. Moreover, the files +# are read-only in distdir when the dist hooks are run. This hook will fix +# up the permissions. All dist hooks that modify files in distdir should list +# unfuck-distdir as a prerequisite. +dist-hook: unfuck-distdir +unfuck-distdir: + find '$(distdir)' -type f -exec chmod u+w {} + +.PHONY: unfuck-distdir + +GITLOG_FLAGS = --format='%s%n%n%b%n' + +dist-hook: generate-changelog +generate-changelog: unfuck-distdir + -: "$${GIT_DIR=$(top_srcdir)/.git}"; \ + export GIT_DIR; test -d "$$GIT_DIR" || exit 0; { \ + $(top_srcdir)/gitlog-to-changelog $(GITLOG_FLAGS) && \ + echo && \ + cat $(top_srcdir)/ChangeLog.iputils; \ + } >$(distdir)/ChangeLog.gen && \ + mv -f '$(distdir)/ChangeLog.gen' '$(distdir)/ChangeLog' + rm -f '$(distdir)/ChangeLog.gen' +.PHONY: generate-changelog + + +GENERIC_V = $(GENERIC_V_@AM_V@) +GENERIC_V_ = $(GENERIC_V_@AM_DEFAULT_V@) +GENERIC_V_0 = @printf '%2.0s%$(DX_ALIGN_V)s %s\n' + +TEST_DISTRIBUTION = false +TEST_DISTRIBUTION_OR_ERROR = if $(TEST_DISTRIBUTION); \ + then echo 'Proceeding anyway...'; \ + else echo 'Run $(MAKE) TEST_DISTRIBUTION=true to ignore this failure.'; \ + false; \ + fi + +distcheck-hook: + $(GENERIC_V) : 'CHECK ' ChangeLog; \ + $(AWK) '/^Stub/ { print FILENAME ":" NR ":", $$0; exit 1 }' \ + $(distdir)/ChangeLog || { \ + echo 'ERROR: *** Packaged ChangeLog was not properly generated from git log.'; \ + echo ' *** The source version was used instead, but this appears to'; \ + echo ' *** be the stub from a git checkout. The "git" and "perl"'; \ + echo ' *** programs are required for ChangeLog generation to work.'; \ + $(TEST_DISTRIBUTION_OR_ERROR); } >&2 diff --git a/gitlog-to-changelog b/gitlog-to-changelog new file mode 100755 index 0000000..9ff15f6 --- /dev/null +++ b/gitlog-to-changelog @@ -0,0 +1,516 @@ +#!/bin/sh +#! -*-perl-*- + +# Convert git log output to ChangeLog format. + +# Copyright (C) 2008-2021 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Written by Jim Meyering + +# This is a prologue that allows to run a perl script as an executable +# on systems that are compliant to a POSIX version before POSIX:2017. +# On such systems, the usual invocation of an executable through execlp() +# or execvp() fails with ENOEXEC if it is a script that does not start +# with a #! line. The script interpreter mentioned in the #! line has +# to be /bin/sh, because on GuixSD systems that is the only program that +# has a fixed file name. The second line is essential for perl and is +# also useful for editing this file in Emacs. The next two lines below +# are valid code in both sh and perl. When executed by sh, they re-execute +# the script through the perl program found in $PATH. The '-x' option +# is essential as well; without it, perl would re-execute the script +# through /bin/sh. When executed by perl, the next two lines are a no-op. +eval 'exec perl -wSx "$0" "$@"' + if 0; + +my $VERSION = '2021-02-24 23:42'; # UTC +# The definition above must lie within the first 8 lines in order +# for the Emacs time-stamp write hook (at end) to update it. +# If you change this file with Emacs, please let the write hook +# do its job. Otherwise, update this string manually. + +use strict; +use warnings; +use Getopt::Long; +use POSIX qw(strftime); + +(my $ME = $0) =~ s|.*/||; + +# use File::Coda; # https://meyering.net/code/Coda/ +END { + defined fileno STDOUT or return; + close STDOUT and return; + warn "$ME: failed to close standard output: $!\n"; + $? ||= 1; +} + +sub usage ($) +{ + my ($exit_code) = @_; + my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); + if ($exit_code != 0) + { + print $STREAM "Try '$ME --help' for more information.\n"; + } + else + { + print $STREAM < ChangeLog + $ME -- -n 5 foo > last-5-commits-to-branch-foo + +SPECIAL SYNTAX: + +The following types of strings are interpreted specially when they appear +at the beginning of a log message line. They are not copied to the output. + + Copyright-paperwork-exempt: Yes + Append the "(tiny change)" notation to the usual "date name email" + ChangeLog header to mark a change that does not require a copyright + assignment. + Co-authored-by: Joe User + List the specified name and email address on a second + ChangeLog header, denoting a co-author. + Signed-off-by: Joe User + These lines are simply elided. + +In a FILE specified via --amend, comment lines (starting with "#") are ignored. +FILE must consist of pairs where SHA is a 40-byte SHA1 (alone on +a line) referring to a commit in the current project, and CODE refers to one +or more consecutive lines of Perl code. Pairs must be separated by one or +more blank line. + +Here is sample input for use with --amend=FILE, from coreutils: + +3a169f4c5d9159283548178668d2fae6fced3030 +# fix typo in title: +s/all tile types/all file types/ + +1379ed974f1fa39b12e2ffab18b3f7a607082202 +# Due to a bug in vc-dwim, I mis-attributed a patch by Paul to myself. +# Change the author to be Paul. Note the escaped "@": +s,Jim .*>,Paul Eggert , + +EOF + } + exit $exit_code; +} + +# If the string $S is a well-behaved file name, simply return it. +# If it contains white space, quotes, etc., quote it, and return the new string. +sub shell_quote($) +{ + my ($s) = @_; + if ($s =~ m![^\w+/.,-]!) + { + # Convert each single quote to '\'' + $s =~ s/\'/\'\\\'\'/g; + # Then single quote the string. + $s = "'$s'"; + } + return $s; +} + +sub quoted_cmd(@) +{ + return join (' ', map {shell_quote $_} @_); +} + +# Parse file F. +# Comment lines (starting with "#") are ignored. +# F must consist of pairs where SHA is a 40-byte SHA1 +# (alone on a line) referring to a commit in the current project, and +# CODE refers to one or more consecutive lines of Perl code. +# Pairs must be separated by one or more blank line. +sub parse_amend_file($) +{ + my ($f) = @_; + + open F, '<', $f + or die "$ME: $f: failed to open for reading: $!\n"; + + my $fail; + my $h = {}; + my $in_code = 0; + my $sha; + while (defined (my $line = )) + { + $line =~ /^\#/ + and next; + chomp $line; + $line eq '' + and $in_code = 0, next; + + if (!$in_code) + { + $line =~ /^([[:xdigit:]]{40})$/ + or (warn "$ME: $f:$.: invalid line; expected an SHA1\n"), + $fail = 1, next; + $sha = lc $1; + $in_code = 1; + exists $h->{$sha} + and (warn "$ME: $f:$.: duplicate SHA1\n"), + $fail = 1, next; + } + else + { + $h->{$sha} ||= ''; + $h->{$sha} .= "$line\n"; + } + } + close F; + + $fail + and exit 1; + + return $h; +} + +# git_dir_option $SRCDIR +# +# From $SRCDIR, the --git-dir option to pass to git (none if $SRCDIR +# is undef). Return as a list (0 or 1 element). +sub git_dir_option($) +{ + my ($srcdir) = @_; + my @res = (); + if (defined $srcdir) + { + my $qdir = shell_quote $srcdir; + my $cmd = "cd $qdir && git rev-parse --show-toplevel"; + my $qcmd = shell_quote $cmd; + my $git_dir = qx($cmd); + defined $git_dir + or die "$ME: cannot run $qcmd: $!\n"; + $? == 0 + or die "$ME: $qcmd had unexpected exit code or signal ($?)\n"; + chomp $git_dir; + push @res, "--git-dir=$git_dir/.git"; + } + @res; +} + +{ + my $since_date; + my $until_date; + my $format_string = '%s%n%b%n'; + my $amend_file; + my $append_dot = 0; + my $cluster = 1; + my $ignore_matching; + my $ignore_line; + my $strip_tab = 0; + my $strip_cherry_pick = 0; + my $srcdir; + GetOptions + ( + help => sub { usage 0 }, + version => sub { print "$ME version $VERSION\n"; exit }, + 'since=s' => \$since_date, + 'until=s' => \$until_date, + 'format=s' => \$format_string, + 'amend=s' => \$amend_file, + 'append-dot' => \$append_dot, + 'cluster!' => \$cluster, + 'ignore-matching=s' => \$ignore_matching, + 'ignore-line=s' => \$ignore_line, + 'strip-tab' => \$strip_tab, + 'strip-cherry-pick' => \$strip_cherry_pick, + 'srcdir=s' => \$srcdir, + ) or usage 1; + + defined $since_date + and unshift @ARGV, "--since=$since_date"; + defined $until_date + and unshift @ARGV, "--until=$until_date"; + + # This is a hash that maps an SHA1 to perl code (i.e., s/old/new/) + # that makes a correction in the log or attribution of that commit. + my $amend_code = defined $amend_file ? parse_amend_file $amend_file : {}; + + my @cmd = ('git', + git_dir_option $srcdir, + qw(log --log-size), + '--pretty=format:%H:%ct %an <%ae>%n%n'.$format_string, @ARGV); + open PIPE, '-|', @cmd + or die ("$ME: failed to run '". quoted_cmd (@cmd) ."': $!\n" + . "(Is your Git too old? Version 1.5.1 or later is required.)\n"); + + my $prev_multi_paragraph; + my $prev_date_line = ''; + my @prev_coauthors = (); + my @skipshas = (); + while (1) + { + defined (my $in = ) + or last; + $in =~ /^log size (\d+)$/ + or die "$ME:$.: Invalid line (expected log size):\n$in"; + my $log_nbytes = $1; + + my $log; + my $n_read = read PIPE, $log, $log_nbytes; + $n_read == $log_nbytes + or die "$ME:$.: unexpected EOF\n"; + + # Extract leading hash. + my ($sha, $rest) = split ':', $log, 2; + defined $sha + or die "$ME:$.: malformed log entry\n"; + $sha =~ /^[[:xdigit:]]{40}$/ + or die "$ME:$.: invalid SHA1: $sha\n"; + + my $skipflag = 0; + if (@skipshas) + { + foreach(@skipshas) + { + if ($sha =~ /^$_/) + { + $skipflag = $_; + last; + } + } + } + + # If this commit's log requires any transformation, do it now. + my $code = $amend_code->{$sha}; + if (defined $code) + { + eval 'use Safe'; + my $s = new Safe; + # Put the unpreprocessed entry into "$_". + $_ = $rest; + + # Let $code operate on it, safely. + my $r = $s->reval("$code") + or die "$ME:$.:$sha: failed to eval \"$code\":\n$@\n"; + + # Note that we've used this entry. + delete $amend_code->{$sha}; + + # Update $rest upon success. + $rest = $_; + } + + # Remove lines inserted by "git cherry-pick". + if ($strip_cherry_pick) + { + $rest =~ s/^\s*Conflicts:\n.*//sm; + $rest =~ s/^\s*\(cherry picked from commit [\da-f]+\)\n//m; + } + + my @line = split /[ \t]*\n/, $rest; + my $author_line = shift @line; + defined $author_line + or die "$ME:$.: unexpected EOF\n"; + $author_line =~ /^(\d+) (.*>)$/ + or die "$ME:$.: Invalid line " + . "(expected date/author/email):\n$author_line\n"; + + # Format 'Copyright-paperwork-exempt: Yes' as a standard ChangeLog + # `(tiny change)' annotation. + my $tiny = (grep (/^(?:Copyright-paperwork-exempt|Tiny-change):\s+[Yy]es$/, @line) + ? ' (tiny change)' : ''); + + my $date_line = sprintf "%s %s$tiny\n", + strftime ("%Y-%m-%d", localtime ($1)), $2; + + my @coauthors = grep /^Co-authored-by:.*$/, @line; + # Omit meta-data lines we've already interpreted. + @line = grep !/^(?:Signed-off-by:[ ].*>$ + |Co-authored-by:[ ] + |Copyright-paperwork-exempt:[ ] + |Tiny-change:[ ] + )/x, @line; + + # Remove leading and trailing blank lines. + if (@line) + { + while ($line[0] =~ /^\s*$/) { shift @line; } + while ($line[$#line] =~ /^\s*$/) { pop @line; } + } + + # Handle Emacs gitmerge.el "skipped" commits. + # Yes, this should be controlled by an option. So sue me. + if ( grep /^(; )?Merge from /, @line ) + { + my $found = 0; + foreach (@line) + { + if (grep /^The following commit.*skipped:$/, $_) + { + $found = 1; + ## Reset at each merge to reduce chance of false matches. + @skipshas = (); + next; + } + if ($found && $_ =~ /^([[:xdigit:]]{7,}) [^ ]/) + { + push ( @skipshas, $1 ); + } + } + } + + # Ignore commits that match the --ignore-matching pattern, if specified. + if (defined $ignore_matching && @line && $line[0] =~ /$ignore_matching/) + { + $skipflag = 1; + } + elsif ($skipflag) + { + ## Perhaps only warn if a pattern matches more than once? + warn "$ME: warning: skipping $sha due to $skipflag\n"; + } + + if (! $skipflag) + { + if (defined $ignore_line && @line) + { + @line = grep ! /$ignore_line/, @line; + while ($line[$#line] =~ /^\s*$/) { pop @line; } + } + + # Record whether there are two or more paragraphs. + my $multi_paragraph = grep /^\s*$/, @line; + + # Format 'Co-authored-by: A U Thor ' lines in + # standard multi-author ChangeLog format. + for (@coauthors) + { + s/^Co-authored-by:\s*/\t /; + s/\s*/ + or warn "$ME: warning: missing email address for " + . substr ($_, 5) . "\n"; + } + + # If clustering of commit messages has been disabled, if this header + # would be different from the previous date/name/etc. header, + # or if this or the previous entry consists of two or more paragraphs, + # then print the header. + if ( ! $cluster + || $date_line ne $prev_date_line + || "@coauthors" ne "@prev_coauthors" + || $multi_paragraph + || $prev_multi_paragraph) + { + $prev_date_line eq '' + or print "\n"; + print $date_line; + @coauthors + and print join ("\n", @coauthors), "\n"; + } + $prev_date_line = $date_line; + @prev_coauthors = @coauthors; + $prev_multi_paragraph = $multi_paragraph; + + # If there were any lines + if (@line == 0) + { + warn "$ME: warning: empty commit message:\n" + . " commit $sha\n $date_line\n"; + } + else + { + if ($append_dot) + { + # If the first line of the message has enough room, then + if (length $line[0] < 72) + { + # append a dot if there is no other punctuation or blank + # at the end. + $line[0] =~ /[[:punct:]\s]$/ + or $line[0] .= '.'; + } + } + + # Remove one additional leading TAB from each line. + $strip_tab + and map { s/^\t// } @line; + + # Prefix each non-empty line with a TAB. + @line = map { length $_ ? "\t$_" : '' } @line; + + print "\n", join ("\n", @line), "\n"; + } + } + + defined ($in = ) + or last; + $in ne "\n" + and die "$ME:$.: unexpected line:\n$in"; + } + + close PIPE + or die "$ME: error closing pipe from " . quoted_cmd (@cmd) . "\n"; + # FIXME-someday: include $PROCESS_STATUS in the diagnostic + + # Complain about any unused entry in the --amend=F specified file. + my $fail = 0; + foreach my $sha (keys %$amend_code) + { + warn "$ME:$amend_file: unused entry: $sha\n"; + $fail = 1; + } + + exit $fail; +} + +# Local Variables: +# mode: perl +# indent-tabs-mode: nil +# eval: (add-hook 'before-save-hook 'time-stamp) +# time-stamp-line-limit: 50 +# time-stamp-start: "my $VERSION = '" +# time-stamp-format: "%:y-%02m-%02d %02H:%02M" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "'; # UTC" +# End: