#!/usr/bin/env bash
#
# Update patches using git-format-patch from a source tree prepared by
# patch_git.sh.
#
# (c) 2021 Phil Sutter <phil@nwl.cc>

wrkdist=$1
wd=$(pwd)

cd "$wrkdist"
top="HEAD"
git log --grep='^OpenADK patch marker:' --format='%H %s'$logopt | \
		while read hash o p m series; do
	patchdir=$(<.git/patch_tmp/${series}/__patchdir__)
	while read patchfile; do
		rm ${patchdir}/$patchfile
	done < .git/patch_tmp/${series}/__patchfiles__
	git format-patch --no-numbered --no-signoff --no-cover-letter \
		--no-signature -o "$patchdir" ${hash}..${top}
	top=${hash}^
done