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