3 # Convert git log output to ChangeLog format for GNU Emacs.
5 # Copyright (C) 2014-2017 Free Software Foundation, Inc.
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/>.
25 # The newest revision that should not appear in the generated ChangeLog.
32 while [ $# -gt 0 ]; do
34 -g|
--gen-origin) gen_origin
="$2" ; shift ;;
35 -f|
--force) force
=1 ;;
36 -n|
--nmax) nmax
="$2"; shift ;;
37 -o|
--output) output
="$2" ; shift ;;
38 *) printf '%s\n' "Unrecognized argument: $1" >&2; exit 1 ;;
43 if [ ! -f ChangeLog.
$nmax ]; then
44 printf '%s\n' "Can't find ChangeLog.$nmax" >&2
45 printf '%s\n' "Must be run from the top source directory" >&2
49 # If not specified in the command line, get gen_origin from the existing
51 [ "$gen_origin" ] ||
{
53 grep -E '^commit [0-9a-f]+ [(]inclusive[)]' ChangeLog.$nmax
55 printf '%s\n' "ChangeLog.$nmax lacks a 'commit ... (inclusive)' line" >&2
62 # Get the new value for gen_origin from the latest version in the repository.
63 new_origin
=`git log --pretty=format:%H 'HEAD^!'` ||
exit
65 if [ -f "$output" ]; then
66 [ ! "$force" ] && printf '%s\n' "$output exists" >&2 && exit 1
67 rm -f "$output" ||
exit 1
70 # If this is not a Git repository, just generate an empty ChangeLog.
76 # Use Gnulib's packaged ChangeLog generator.
77 # Maybe we should skip all "Merge branch 'master'" messages.
78 # See eg the cairo-related ones.
79 .
/build-aux
/gitlog-to-changelog \
80 --ignore-matching="^; |^Merge branch '[^']*' of git\.(savannah|sv)\.gnu\.org:/srv/git/emacs|^Merge remote-tracking branch '.*'$" \
81 --ignore-line='^; ' --format='%B' \
82 "$gen_origin..$new_origin" >"ChangeLog.tmp" ||
exit
84 if test -r "ChangeLog.tmp"; then
86 # Fix up bug references.
87 # This would be better as eg a --transform option to gitlog-to-changelog,
88 # but... effort. FIXME does not handle rare cases like:
89 # Fixes: debbugs:19434 debbugs:19519
90 sed 's/ Fixes: \(debbugs:\|bug#\)\([0-9][0-9]*\)/ (Bug#\2)/' \
91 "ChangeLog.tmp" > "ChangeLog.tmp2"
92 mv "ChangeLog.tmp2" "ChangeLog.tmp"
94 # Find the years covered by the generated ChangeLog, so that
95 # a proper copyright notice can be output.
97 sed -n 's/^\([0-9][0-9]*\).*/\1/p' "ChangeLog.tmp" |
102 for year
in ${years:-`date +%Y`}; do
103 : ${start_year:=$year}
107 if test "$start_year" = "$end_year"; then
108 year_range
=$start_year
110 year_range
=$start_year-$end_year
114 if test "$gen_origin" != "$new_origin"; then
118 /^This file records repository revisions/p
119 s/^commit [0-9a-f]* (exclusive)/commit '"$gen_origin"' (exclusive)/p
120 s/^commit [0-9a-f]* (inclusive)/commit '"$new_origin"' (inclusive)/p
121 ' <ChangeLog.
$nmax >>"ChangeLog.tmp" ||
exit
124 # Append a proper copyright notice.
126 /^See ChangeLog.[0-9]* for earlier/,${
127 s/ChangeLog\.[0-9]*/ChangeLog.'$nmax'/
128 s/\(Copyright[ (C)]*\)[0-9]*-[0-9]*/\1'"$year_range"'/
131 ' <ChangeLog.
$nmax >>"ChangeLog.tmp" ||
exit
134 # Install the generated ChangeLog.
135 test "$output" = "ChangeLog.tmp" ||
mv "ChangeLog.tmp" "$output"