2005-04-12 10:40:20 +02:00
|
|
|
#!/bin/sh
|
|
|
|
##
|
|
|
|
## "dotest" is my stupid name for my patch-application script, which
|
|
|
|
## I never got around to renaming after I tested it. We're now on the
|
|
|
|
## second generation of scripts, still called "dotest".
|
|
|
|
##
|
2005-07-16 19:05:26 +02:00
|
|
|
## Update: Ryan Anderson finally shamed me into naming this "applymbox".
|
|
|
|
##
|
2005-04-12 10:40:20 +02:00
|
|
|
## You give it a mbox-format collection of emails, and it will try to
|
|
|
|
## apply them to the kernel using "applypatch"
|
|
|
|
##
|
2005-07-23 01:04:19 +02:00
|
|
|
## The patch application may fail in the middle. In which case:
|
|
|
|
## (1) look at .dotest/patch and fix it up to apply
|
|
|
|
## (2) re-run applymbox with -c .dotest/msg-number for the current one.
|
|
|
|
## Pay a special attention to the commit log message if you do this and
|
|
|
|
## use a Signoff_file, because applypatch wants to append the sign-off
|
|
|
|
## message to msg-clean every time it is run.
|
2005-04-20 17:23:00 +02:00
|
|
|
|
2005-09-08 02:26:23 +02:00
|
|
|
. git-sh-setup || die "Not a git archive"
|
2005-08-19 00:31:40 +02:00
|
|
|
|
2005-08-28 21:33:16 +02:00
|
|
|
usage () {
|
2005-10-06 23:25:52 +02:00
|
|
|
echo >&2 "applymbox [-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]"
|
2005-08-28 21:33:16 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
keep_subject= query_apply= continue= utf8= resume=t
|
2005-07-23 01:04:19 +02:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
2005-08-28 21:33:16 +02:00
|
|
|
-u) utf8=-u ;;
|
2005-08-17 07:18:27 +02:00
|
|
|
-k) keep_subject=-k ;;
|
2005-07-23 01:04:19 +02:00
|
|
|
-q) query_apply=t ;;
|
|
|
|
-c) continue="$2"; resume=f; shift ;;
|
2005-10-06 23:25:52 +02:00
|
|
|
-m) fallback_3way=t ;;
|
2005-07-23 01:04:19 +02:00
|
|
|
-*) usage ;;
|
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
case "$continue" in
|
|
|
|
'')
|
|
|
|
rm -rf .dotest
|
|
|
|
mkdir .dotest
|
2005-10-06 23:25:52 +02:00
|
|
|
num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
|
|
|
|
echo "$num_msgs patch(es) to process."
|
2005-07-30 00:37:11 +02:00
|
|
|
shift
|
2005-04-20 17:23:00 +02:00
|
|
|
esac
|
2005-07-23 01:04:19 +02:00
|
|
|
|
2005-09-08 02:26:23 +02:00
|
|
|
files=$(git-diff-index --cached --name-only HEAD) || exit
|
2005-08-19 00:31:40 +02:00
|
|
|
if [ "$files" ]; then
|
|
|
|
echo "Dirty index: cannot apply patches (dirty: $files)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-07-23 01:04:19 +02:00
|
|
|
case "$query_apply" in
|
|
|
|
t) touch .dotest/.query_apply
|
|
|
|
esac
|
2005-10-06 23:25:52 +02:00
|
|
|
case "$fall_back_3way" in
|
|
|
|
t) : >.dotest/.3way
|
|
|
|
esac
|
2005-08-17 07:18:27 +02:00
|
|
|
case "$keep_subject" in
|
|
|
|
-k) : >.dotest/.keep_subject
|
|
|
|
esac
|
2005-07-23 01:04:19 +02:00
|
|
|
|
2005-07-30 00:37:11 +02:00
|
|
|
signoff="$1"
|
|
|
|
set x .dotest/0*
|
|
|
|
shift
|
|
|
|
while case "$#" in 0) break;; esac
|
2005-04-12 10:40:20 +02:00
|
|
|
do
|
2005-07-30 00:37:11 +02:00
|
|
|
i="$1"
|
|
|
|
case "$resume,$continue" in
|
|
|
|
f,$i) resume=t;;
|
2005-09-04 19:37:07 +02:00
|
|
|
f,*) shift
|
|
|
|
continue;;
|
2005-07-30 00:37:11 +02:00
|
|
|
*)
|
2005-08-28 21:33:16 +02:00
|
|
|
git-mailinfo $keep_subject $utf8 \
|
2005-08-17 07:18:27 +02:00
|
|
|
.dotest/msg .dotest/patch <$i >.dotest/info || exit 1
|
2005-07-30 00:37:11 +02:00
|
|
|
git-stripspace < .dotest/msg > .dotest/msg-clean
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
while :; # for fixing up and retry
|
|
|
|
do
|
|
|
|
git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
|
|
|
|
case "$?" in
|
2005-10-06 23:25:52 +02:00
|
|
|
0)
|
|
|
|
# Remove the cleanly applied one to reduce clutter.
|
|
|
|
rm -f .dotest/$i
|
|
|
|
;;
|
|
|
|
2)
|
2005-04-20 17:23:00 +02:00
|
|
|
# 2 is a special exit code from applypatch to indicate that
|
|
|
|
# the patch wasn't applied, but continue anyway
|
2005-07-30 00:37:11 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ret=$?
|
|
|
|
if test -f .dotest/.query_apply
|
|
|
|
then
|
|
|
|
echo >&2 "* Patch failed."
|
|
|
|
echo >&2 "* You could fix it up in your editor and"
|
|
|
|
echo >&2 " retry. If you want to do so, say yes here"
|
|
|
|
echo >&2 " AFTER fixing .dotest/patch up."
|
|
|
|
echo >&2 -n "Retry [y/N]? "
|
|
|
|
read yesno
|
|
|
|
case "$yesno" in
|
|
|
|
[Yy]*)
|
|
|
|
continue ;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
exit $ret
|
|
|
|
esac
|
|
|
|
break
|
|
|
|
done
|
|
|
|
shift
|
2005-04-12 10:40:20 +02:00
|
|
|
done
|
2005-04-20 17:23:00 +02:00
|
|
|
# return to pristine
|
|
|
|
rm -fr .dotest
|