]> code.delx.au - gnu-emacs/blob - build-aux/gitlog-to-emacslog
; Auto-commit of ChangeLog files.
[gnu-emacs] / build-aux / gitlog-to-emacslog
1 #!/bin/sh
2
3 # Convert git log output to ChangeLog format for GNU Emacs.
4
5 # Copyright (C) 2014-2015 Free Software Foundation, Inc.
6
7 # Author: Paul Eggert
8
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.
13
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.
18
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/>.
21
22 LC_ALL=C
23 export LC_ALL
24
25 # The newest revision that should not appear in the generated ChangeLog.
26 gen_origin=b98a2ef74758f78831d7c6dd4ae13f3433d77869
27 force=
28 output=ChangeLog
29 nmax=2
30
31 while [ $# -gt 0 ]; do
32 case "$1" in
33 -g|--gen-origin) gen_origin="$2" ; shift ;;
34 -f|--force) force=1 ;;
35 -n|--nmax) nmax="$2"; shift ;;
36 -o|--output) output="$2" ; shift ;;
37 *) echo "Unrecognized argument: $1" >&2; exit 1 ;;
38 esac
39 shift
40 done
41
42 if [ ! -f ChangeLog.$nmax ]; then
43 echo "Can't find ChangeLog.$nmax" >&2
44 echo "Must be run from the top source directory" >&2
45 exit 1
46 fi
47
48 if [ -f "$output" ]; then
49 [ ! "$force" ] && echo "$output exists" >&2 && exit 1
50 rm -f "$output" || exit 1
51 fi
52
53 # If this is not a Git repository, just generate an empty ChangeLog.
54 test -d .git || {
55 >"$output"
56 exit
57 }
58
59 # Use Gnulib's packaged ChangeLog generator.
60 ./build-aux/gitlog-to-changelog --ignore-matching='^; ' \
61 --ignore-line='^; ' --format='%B' \
62 "$gen_origin.." >"ChangeLog.tmp" || exit
63
64 if test -s "ChangeLog.tmp"; then
65
66 # Fix up bug references.
67 # This would be better as eg a --transform option to gitlog-to-changelog,
68 # but... effort. FIXME does not handle rare cases like:
69 # Fixes: debbugs:19434 debbugs:19519
70 sed 's/ Fixes: \(debbugs:\|bug#\)\([0-9][0-9]*\)/ (Bug#\2)/' \
71 "ChangeLog.tmp" > "ChangeLog.tmp2"
72 mv "ChangeLog.tmp2" "ChangeLog.tmp"
73
74 # Find the years covered by the generated ChangeLog, so that
75 # a proper copyright notice can be output.
76 years=`
77 sed -n 's/^\([0-9][0-9]*\).*/\1/p' "ChangeLog.tmp" |
78 sort -nu
79 `
80 start_year=
81 end_year=
82 for year in $years; do
83 : ${start_year:=$year}
84 end_year=$year
85 done
86
87 if test "$start_year" = "$end_year"; then
88 year_range=$start_year
89 else
90 year_range=$start_year-$end_year
91 fi
92
93 # Append a proper copyright notice.
94 sed -n '
95 1i\
96
97 /^See ChangeLog.[0-9]* for earlier/,${
98 s/ChangeLog\.[0-9]*/ChangeLog.'$nmax'/
99 s/\(Copyright[ (C)]*\)[0-9]*-[0-9]*/\1'"$year_range"'/
100 p
101 }
102 ' <ChangeLog.$nmax >>"ChangeLog.tmp" || exit
103 fi
104
105 # Install the generated ChangeLog.
106 test "$output" = "ChangeLog.tmp" || mv "ChangeLog.tmp" "$output"