blob: 5569fdcc3463b214411d5a168a00783b0d390044 [file] [log] [blame]
Linus Torvalds853916f2005-04-12 01:40:20 -07001#!/bin/sh
2##
3## "dotest" is my stupid name for my patch-application script, which
4## I never got around to renaming after I tested it. We're now on the
5## second generation of scripts, still called "dotest".
6##
Linus Torvaldsc5f76742005-07-16 10:05:26 -07007## Update: Ryan Anderson finally shamed me into naming this "applymbox".
8##
Linus Torvalds853916f2005-04-12 01:40:20 -07009## You give it a mbox-format collection of emails, and it will try to
10## apply them to the kernel using "applypatch"
11##
Junio C Hamano37275312005-07-22 16:04:19 -070012## The patch application may fail in the middle. In which case:
13## (1) look at .dotest/patch and fix it up to apply
14## (2) re-run applymbox with -c .dotest/msg-number for the current one.
15## Pay a special attention to the commit log message if you do this and
16## use a Signoff_file, because applypatch wants to append the sign-off
17## message to msg-clean every time it is run.
Petr Baudis42e2cba2005-10-21 02:28:42 +020018##
19## git-am is supposed to be the newer and better tool for this job.
James Bottomleyad4e9ce2005-04-20 08:23:00 -070020
freku045@student.liu.se806f36d2005-12-13 23:30:31 +010021USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]'
Junio C Hamanoae2b0f12005-11-24 00:12:11 -080022. git-sh-setup
Linus Torvaldsd571c2b2005-08-18 15:31:40 -070023
Junio C Hamanoe3b59a42006-02-18 20:51:26 -080024git var GIT_COMMITTER_IDENT >/dev/null || exit
25
Junio C Hamanod4a9ce72005-08-28 12:33:16 -070026keep_subject= query_apply= continue= utf8= resume=t
Junio C Hamano37275312005-07-22 16:04:19 -070027while case "$#" in 0) break ;; esac
Linus Torvalds853916f2005-04-12 01:40:20 -070028do
Junio C Hamano37275312005-07-22 16:04:19 -070029 case "$1" in
Junio C Hamanod4a9ce72005-08-28 12:33:16 -070030 -u) utf8=-u ;;
Junio C Hamano6bff6a62005-08-16 22:18:27 -070031 -k) keep_subject=-k ;;
Junio C Hamano37275312005-07-22 16:04:19 -070032 -q) query_apply=t ;;
33 -c) continue="$2"; resume=f; shift ;;
Junio C Hamanoe1355542005-11-29 14:14:42 -080034 -m) fall_back_3way=t ;;
Junio C Hamano37275312005-07-22 16:04:19 -070035 -*) usage ;;
36 *) break ;;
37 esac
38 shift
39done
40
41case "$continue" in
42'')
43 rm -rf .dotest
44 mkdir .dotest
Junio C Hamanoe11fc022005-10-06 14:25:52 -070045 num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
46 echo "$num_msgs patch(es) to process."
Junio C Hamanob50abe82005-07-29 15:37:11 -070047 shift
Junio C Hamano37275312005-07-22 16:04:19 -070048esac
49
Junio C Hamano215a7ad2005-09-07 17:26:23 -070050files=$(git-diff-index --cached --name-only HEAD) || exit
Linus Torvaldsd571c2b2005-08-18 15:31:40 -070051if [ "$files" ]; then
52 echo "Dirty index: cannot apply patches (dirty: $files)" >&2
53 exit 1
54fi
55
Junio C Hamano37275312005-07-22 16:04:19 -070056case "$query_apply" in
57t) touch .dotest/.query_apply
58esac
Junio C Hamano47f0b6d2005-10-06 14:25:52 -070059case "$fall_back_3way" in
60t) : >.dotest/.3way
61esac
Junio C Hamano6bff6a62005-08-16 22:18:27 -070062case "$keep_subject" in
63-k) : >.dotest/.keep_subject
64esac
Junio C Hamano37275312005-07-22 16:04:19 -070065
Junio C Hamanob50abe82005-07-29 15:37:11 -070066signoff="$1"
67set x .dotest/0*
68shift
69while case "$#" in 0) break;; esac
Junio C Hamano37275312005-07-22 16:04:19 -070070do
Junio C Hamanob50abe82005-07-29 15:37:11 -070071 i="$1"
72 case "$resume,$continue" in
73 f,$i) resume=t;;
Junio C Hamano07a95d02005-09-04 10:37:07 -070074 f,*) shift
75 continue;;
Junio C Hamanob50abe82005-07-29 15:37:11 -070076 *)
Junio C Hamanod4a9ce72005-08-28 12:33:16 -070077 git-mailinfo $keep_subject $utf8 \
Junio C Hamano6bff6a62005-08-16 22:18:27 -070078 .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
Junio C Hamanob50abe82005-07-29 15:37:11 -070079 git-stripspace < .dotest/msg > .dotest/msg-clean
80 ;;
81 esac
82 while :; # for fixing up and retry
83 do
84 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
85 case "$?" in
Junio C Hamano4ebe63d2005-10-06 14:25:52 -070086 0)
87 # Remove the cleanly applied one to reduce clutter.
88 rm -f .dotest/$i
89 ;;
90 2)
James Bottomleyad4e9ce2005-04-20 08:23:00 -070091 # 2 is a special exit code from applypatch to indicate that
92 # the patch wasn't applied, but continue anyway
Junio C Hamanob50abe82005-07-29 15:37:11 -070093 ;;
94 *)
95 ret=$?
96 if test -f .dotest/.query_apply
97 then
98 echo >&2 "* Patch failed."
99 echo >&2 "* You could fix it up in your editor and"
100 echo >&2 " retry. If you want to do so, say yes here"
101 echo >&2 " AFTER fixing .dotest/patch up."
102 echo >&2 -n "Retry [y/N]? "
103 read yesno
104 case "$yesno" in
105 [Yy]*)
106 continue ;;
107 esac
108 fi
109 exit $ret
110 esac
111 break
112 done
113 shift
Linus Torvalds853916f2005-04-12 01:40:20 -0700114done
James Bottomleyad4e9ce2005-04-20 08:23:00 -0700115# return to pristine
116rm -fr .dotest