Simplify rfc1345.el a bit
[emacs.git] / build-aux / gitlog-to-emacslog
blob085d2c2512d82e709450053b7a44a3bfcd79b6fc
1 #!/bin/sh
3 # Convert git log output to ChangeLog format for GNU Emacs.
5 # Copyright (C) 2014-2016 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=
28 force=
29 output=ChangeLog
30 nmax=2
32 while [ $# -gt 0 ]; do
33 case "$1" in
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 ;;
39 esac
40 shift
41 done
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
46 exit 1
49 # If not specified in the command line, get gen_origin from the existing
50 # ChangeLog file.
51 [ "$gen_origin" ] || {
52 gen_origin_line=`
53 grep -E '^commit [0-9a-f]+ [(]inclusive[)]' ChangeLog.$nmax
54 ` || {
55 printf '%s\n' "ChangeLog.$nmax lacks a 'commit ... (inclusive)' line" >&2
56 exit 1
58 set $gen_origin_line
59 gen_origin=$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.
71 test -e .git || {
72 >"$output"
73 exit
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 -e "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.
96 years=`
97 sed -n 's/^\([0-9][0-9]*\).*/\1/p' "ChangeLog.tmp" |
98 sort -nu
100 start_year=
101 end_year=
102 for year in ${years:-`date +%Y`}; do
103 : ${start_year:=$year}
104 end_year=$year
105 done
107 if test "$start_year" = "$end_year"; then
108 year_range=$start_year
109 else
110 year_range=$start_year-$end_year
113 # Update gen_origin
114 if test "$gen_origin" != "$new_origin"; then
115 sed -n '
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.
125 sed -n '
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"