* build-aux/gitlog-to-emacslog: Add "for earlier changes" to footer.
[emacs.git] / build-aux / gitlog-to-emacslog
blob0db91d52205239d15bbabe802d5d38a62ff5d89c
1 #!/bin/sh
3 # Convert git log output to ChangeLog format for GNU Emacs.
5 # Copyright (C) 2014-2015 Free Software Foundation, Inc.
7 # Author: Paul Eggert
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 LC_ALL=C
23 export LC_ALL
25 # The newest revision that should not appear in the generated ChangeLog.
26 gen_origin=2c1b8604946efbcd8ec5dd6c6dda7541ce4fc3c0
27 force=
28 output=ChangeLog
30 while [ $# -gt 0 ]; do
31 case "$1" in
32 -g|--gen-origin) gen_origin="$2" ; shift ;;
33 -f|--force) force=1 ;;
34 -o|--output) output="$2" ; shift ;;
35 *) echo "Unrecognized argument: $1" >&2; exit 1 ;;
36 esac
37 shift
38 done
40 if [ -f "${distprefix}$output" ]; then
41 [ ! "$force" ] && echo "${distprefix}$output exists" && exit 1
42 rm -f "${distprefix}$output" || exit 1
45 # If this is not a Git repository, just generate an empty ChangeLog.
46 test -d ${srcprefix}.git || {
47 >"${distprefix}$output"
48 exit
51 # Use Gnulib's packaged ChangeLog generator.
52 ${srcprefix}build-aux/gitlog-to-changelog --ignore-matching='^; ' \
53 --format='%B' \
54 "$gen_origin.." >"${distprefix}ChangeLog.tmp" || exit
56 if test -s "${distprefix}ChangeLog.tmp"; then
58 # Fix up bug references.
59 # This would be better as eg a --transform option to gitlog-to-changelog,
60 # but... effort. FIXME does not handle rare cases like:
61 # Fixes: debbugs:19434 debbugs:19519
62 sed 's/ Fixes: \(debbugs:\|bug#\)\([0-9][0-9]*\)/ (Bug#\2)/' \
63 "${distprefix}ChangeLog.tmp" > "${distprefix}ChangeLog.tmp2"
64 mv "${distprefix}ChangeLog.tmp2" "${distprefix}ChangeLog.tmp"
66 # Find the years covered by the generated ChangeLog, so that
67 # a proper copyright notice can be output.
68 years=`
69 sed -n 's/^\([0-9][0-9]*\).*/\1/p' "${distprefix}ChangeLog.tmp" |
70 sort -nu
72 start_year=
73 end_year=
74 for year in $years; do
75 : ${start_year:=$year}
76 end_year=$year
77 done
79 if test "$start_year" = "$end_year"; then
80 year_range=$start_year
81 else
82 year_range=$start_year-$end_year
85 # Append a proper copyright notice.
86 sed -n '
87 1i\
89 /^See ChangeLog.1 for earlier/,${
90 s/ChangeLog\.1/ChangeLog.2/
91 s/\(Copyright[ (C)]*\)[0-9]*-[0-9]*/\1'"$year_range"'/
94 ' <ChangeLog.2 >>"${distprefix}ChangeLog.tmp" || exit
97 # Install the generated ChangeLog.
98 test "$output" = "ChangeLog.tmp" || \
99 mv -i "${distprefix}ChangeLog.tmp" "${distprefix}$output"