gitlog-to-emacslog 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. # Convert git log output to ChangeLog format for GNU Emacs.
  3. # Copyright (C) 2014-2016 Free Software Foundation, Inc.
  4. # Author: Paul Eggert
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. LC_ALL=C
  16. export LC_ALL
  17. # The newest revision that should not appear in the generated ChangeLog.
  18. gen_origin=
  19. force=
  20. output=ChangeLog
  21. nmax=2
  22. while [ $# -gt 0 ]; do
  23. case "$1" in
  24. -g|--gen-origin) gen_origin="$2" ; shift ;;
  25. -f|--force) force=1 ;;
  26. -n|--nmax) nmax="$2"; shift ;;
  27. -o|--output) output="$2" ; shift ;;
  28. *) printf '%s\n' "Unrecognized argument: $1" >&2; exit 1 ;;
  29. esac
  30. shift
  31. done
  32. if [ ! -f ChangeLog.$nmax ]; then
  33. printf '%s\n' "Can't find ChangeLog.$nmax" >&2
  34. printf '%s\n' "Must be run from the top source directory" >&2
  35. exit 1
  36. fi
  37. # If not specified in the command line, get gen_origin from the existing
  38. # ChangeLog file.
  39. [ "$gen_origin" ] || {
  40. gen_origin_line=`
  41. grep -E '^commit [0-9a-f]+ [(]inclusive[)]' ChangeLog.$nmax
  42. ` || {
  43. printf '%s\n' "ChangeLog.$nmax lacks a 'commit ... (inclusive)' line" >&2
  44. exit 1
  45. }
  46. set $gen_origin_line
  47. gen_origin=$2
  48. }
  49. # Get the new value for gen_origin from the latest version in the repository.
  50. new_origin=`git log --pretty=format:%H 'HEAD^!'` || exit
  51. if [ -f "$output" ]; then
  52. [ ! "$force" ] && printf '%s\n' "$output exists" >&2 && exit 1
  53. rm -f "$output" || exit 1
  54. fi
  55. # If this is not a Git repository, just generate an empty ChangeLog.
  56. test -e .git || {
  57. >"$output"
  58. exit
  59. }
  60. # Use Gnulib's packaged ChangeLog generator.
  61. # Maybe we should skip all "Merge branch 'master'" messages.
  62. # See eg the cairo-related ones.
  63. ./build-aux/gitlog-to-changelog \
  64. --ignore-matching="^; |^Merge branch '[^']*' of git\.(savannah|sv)\.gnu\.org:/srv/git/emacs|^Merge remote-tracking branch '.*'$" \
  65. --ignore-line='^; ' --format='%B' \
  66. "$gen_origin..$new_origin" >"ChangeLog.tmp" || exit
  67. if test -e "ChangeLog.tmp"; then
  68. # Fix up bug references.
  69. # This would be better as eg a --transform option to gitlog-to-changelog,
  70. # but... effort. FIXME does not handle rare cases like:
  71. # Fixes: debbugs:19434 debbugs:19519
  72. sed 's/ Fixes: \(debbugs:\|bug#\)\([0-9][0-9]*\)/ (Bug#\2)/' \
  73. "ChangeLog.tmp" > "ChangeLog.tmp2"
  74. mv "ChangeLog.tmp2" "ChangeLog.tmp"
  75. # Find the years covered by the generated ChangeLog, so that
  76. # a proper copyright notice can be output.
  77. years=`
  78. sed -n 's/^\([0-9][0-9]*\).*/\1/p' "ChangeLog.tmp" |
  79. sort -nu
  80. `
  81. start_year=
  82. end_year=
  83. for year in ${years:-`date +%Y`}; do
  84. : ${start_year:=$year}
  85. end_year=$year
  86. done
  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. # Update gen_origin
  93. if test "$gen_origin" != "$new_origin"; then
  94. sed -n '
  95. 1i\
  96. /^This file records repository revisions/p
  97. s/^commit [0-9a-f]* (exclusive)/commit '"$gen_origin"' (exclusive)/p
  98. s/^commit [0-9a-f]* (inclusive)/commit '"$new_origin"' (inclusive)/p
  99. ' <ChangeLog.$nmax >>"ChangeLog.tmp" || exit
  100. fi
  101. # Append a proper copyright notice.
  102. sed -n '
  103. /^See ChangeLog.[0-9]* for earlier/,${
  104. s/ChangeLog\.[0-9]*/ChangeLog.'$nmax'/
  105. s/\(Copyright[ (C)]*\)[0-9]*-[0-9]*/\1'"$year_range"'/
  106. p
  107. }
  108. ' <ChangeLog.$nmax >>"ChangeLog.tmp" || exit
  109. fi
  110. # Install the generated ChangeLog.
  111. test "$output" = "ChangeLog.tmp" || mv "ChangeLog.tmp" "$output"