#!/bin/sh -efu
#
# Copyright (C) 2008  Alexey Gladkov <legion@altlinux.org>
#
# This file 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

# http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs

format_group() { :; }
format_header() { :; }

format_commit() {
	if [ "$aname <$aemail>" != "${old_name:-releaser}" ]; then
		local stamp="$(LC_TIME=C date -d "@$atime" '+%Y-%m-%d')"
		printf '%s\n\n' "$stamp  $aname <$aemail>"
		old_name="$aname <$aemail>"
	fi
	{
		printf '* '
		git log -n1 --pretty=format: --name-only "$hash" |
			sed -e '/^$/d' -e 's/^.*/&, /' -e '$s/, $/: /' |
			tr -d '\n'
		printf '%s.\n' "$subj"
	} |
		fmt -w"$cwidth" |
		sed -e 's/^[^*]/  &/' -e 's/^.*/\t&/'
	printf '\n'
}

format_footer() { :; }
