#!/bin/sh

./gitlog-to-changelog \
  --ignore-matching='^; ' --ignore-line='^; ' \
  --ignore-commits="f3fed64957b4e88cfa1ff2c5ddfb665f249624cc,\
1b2b7aee26dd611a44226530f9a010ec9bf22add" \
  --format='%B' >ChangeLog

# Find the years covered by the generated ChangeLog, so that
# a proper copyright notice can be output.
years=$(sed -n 's/^\([0-9][0-9]*\).*/\1/p' ChangeLog | sort -nu)
start_year=$(echo "$years" | head -1)
end_year=$(echo "$years" | tail -1)

if test "$start_year" = "$end_year"; then
  year_range=$start_year
else
  year_range=$start_year-$end_year
fi

copyright_notice="
;; Local Variables:
;; coding: utf-8
;; End:

  Copyright (C) $year_range Akib Azmain Turja.

  This file is not part of GNU Emacs.

  GNU Emacs is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  GNU Emacs is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>."

echo "$copyright_notice" >>ChangeLog