Blob Blame History Raw
#!/bin/bash

# Print git log in .changes format. Expects a revision range as argument

last_commit=
last_ts=
last_email=

commit_marker()
{
	if test -n "$last_commit"; then
		echo "- commit ${last_commit:0:7}"
		echo
	fi
}

git rev-list --no-merges --pretty=format:'%at %H' "$@" | grep -v '^commit' |\
sort -rn -s -k1,1 | ( while read x commit; do
	raw=$(git cat-file commit "$commit")
	headers=$(echo "$raw" | sed '/^$/Q')
	msg=$(echo "$raw" | sed '1,/^$/d')
	ts=$(echo "$headers" | sed -rn 's/^author .*> ([^ ]*) .*/\1/p')
	date=$(LANG=C TZ=CET date -d @$ts)
	email=$(echo "$headers" | sed -rn 's/^author .* <(.*)> .*/\1/p')

	if test "$last_email" != "$email" -o "$last_ts" != "$ts"; then
		commit_marker
		echo "-------------------------------------------------------------------"
		echo "$date - $email"
		echo
		last_commit=$commit
	fi
	last_ts=$ts
	last_email=$email
	echo "$msg" | sed '
		1 s/^[^-]/- &/
		/^$/d
		/^Signed-off-by:/d
		2,$ s/^[^-]/  &/'
done
commit_marker )