2005-04-12 08:40:20 +00: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 17:05:26 +00:00
|
|
|
## Update: Ryan Anderson finally shamed me into naming this "applymbox".
|
|
|
|
##
|
2005-04-12 08:40:20 +00:00
|
|
|
## You give it a mbox-format collection of emails, and it will try to
|
|
|
|
## apply them to the kernel using "applypatch"
|
|
|
|
##
|
2005-07-22 23:04:19 +00: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-10-21 00:28:42 +00:00
|
|
|
##
|
|
|
|
## git-am is supposed to be the newer and better tool for this job.
|
2005-04-20 15:23:00 +00:00
|
|
|
|
2005-12-13 22:30:31 +00:00
|
|
|
USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
|
2005-11-24 08:12:11 +00:00
|
|
|
. git-sh-setup
|
2005-08-18 22:31:40 +00:00
|
|
|
|
2006-02-19 04:51:26 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >/dev/null || exit
|
|
|
|
|
2005-08-28 19:33:16 +00:00
|
|
|
keep_subject= query_apply= continue= utf8= resume=t
|
2005-07-22 23:04:19 +00:00
|
|
|
while case "$#" in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
2005-08-28 19:33:16 +00:00
|
|
|
-u) utf8=-u ;;
|
2005-08-17 05:18:27 +00:00
|
|
|
-k) keep_subject=-k ;;
|
2005-07-22 23:04:19 +00:00
|
|
|
-q) query_apply=t ;;
|
|
|
|
-c) continue="$2"; resume=f; shift ;;
|
2005-11-29 22:14:42 +00:00
|
|
|
-m) fall_back_3way=t ;;
|
2005-07-22 23:04:19 +00:00
|
|
|
-*) usage ;;
|
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
case "$continue" in
|
|
|
|
'')
|
|
|
|
rm -rf .dotest
|
|
|
|
mkdir .dotest
|
2005-10-06 21:25:52 +00:00
|
|
|
num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
|
|
|
|
echo "$num_msgs patch(es) to process."
|
2005-07-29 22:37:11 +00:00
|
|
|
shift
|
2005-04-20 15:23:00 +00:00
|
|
|
esac
|
2005-07-22 23:04:19 +00:00
|
|
|
|
2005-09-08 00:26:23 +00:00
|
|
|
files=$(git-diff-index --cached --name-only HEAD) || exit
|
2005-08-18 22:31:40 +00:00
|
|
|
if [ "$files" ]; then
|
|
|
|
echo "Dirty index: cannot apply patches (dirty: $files)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2005-07-22 23:04:19 +00:00
|
|
|
case "$query_apply" in
|
|
|
|
t) touch .dotest/.query_apply
|
|
|
|
esac
|
2005-10-06 21:25:52 +00:00
|
|
|
case "$fall_back_3way" in
|
|
|
|
t) : >.dotest/.3way
|
|
|
|
esac
|
2005-08-17 05:18:27 +00:00
|
|
|
case "$keep_subject" in
|
|
|
|
-k) : >.dotest/.keep_subject
|
|
|
|
esac
|
2005-07-22 23:04:19 +00:00
|
|
|
|
2005-07-29 22:37:11 +00:00
|
|
|
signoff="$1"
|
|
|
|
set x .dotest/0*
|
|
|
|
shift
|
|
|
|
while case "$#" in 0) break;; esac
|
2005-04-12 08:40:20 +00:00
|
|
|
do
|
2005-07-29 22:37:11 +00:00
|
|
|
i="$1"
|
|
|
|
case "$resume,$continue" in
|
|
|
|
f,$i) resume=t;;
|
2005-09-04 17:37:07 +00:00
|
|
|
f,*) shift
|
|
|
|
continue;;
|
2005-07-29 22:37:11 +00:00
|
|
|
*)
|
2005-08-28 19:33:16 +00:00
|
|
|
git-mailinfo $keep_subject $utf8 \
|
2005-08-17 05:18:27 +00:00
|
|
|
.dotest/msg .dotest/patch <$i >.dotest/info || exit 1
|
2005-07-29 22:37:11 +00: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 21:25:52 +00:00
|
|
|
0)
|
|
|
|
# Remove the cleanly applied one to reduce clutter.
|
|
|
|
rm -f .dotest/$i
|
|
|
|
;;
|
|
|
|
2)
|
2005-04-20 15:23:00 +00:00
|
|
|
# 2 is a special exit code from applypatch to indicate that
|
|
|
|
# the patch wasn't applied, but continue anyway
|
2005-07-29 22:37:11 +00: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 08:40:20 +00:00
|
|
|
done
|
2005-04-20 15:23:00 +00:00
|
|
|
# return to pristine
|
|
|
|
rm -fr .dotest
|