Linus Torvalds | 853916f | 2005-04-12 01:40:20 -0700 | [diff] [blame] | 1 | #!/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 Torvalds | c5f7674 | 2005-07-16 10:05:26 -0700 | [diff] [blame] | 7 | ## Update: Ryan Anderson finally shamed me into naming this "applymbox". |
| 8 | ## |
Linus Torvalds | 853916f | 2005-04-12 01:40:20 -0700 | [diff] [blame] | 9 | ## 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 Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 12 | ## 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 Baudis | 42e2cba | 2005-10-21 02:28:42 +0200 | [diff] [blame] | 18 | ## |
| 19 | ## git-am is supposed to be the newer and better tool for this job. |
James Bottomley | ad4e9ce | 2005-04-20 08:23:00 -0700 | [diff] [blame] | 20 | |
freku045@student.liu.se | 806f36d | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 21 | USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]' |
Junio C Hamano | ae2b0f1 | 2005-11-24 00:12:11 -0800 | [diff] [blame] | 22 | . git-sh-setup |
Linus Torvalds | d571c2b | 2005-08-18 15:31:40 -0700 | [diff] [blame] | 23 | |
Junio C Hamano | e3b59a4 | 2006-02-18 20:51:26 -0800 | [diff] [blame] | 24 | git var GIT_COMMITTER_IDENT >/dev/null || exit |
| 25 | |
Junio C Hamano | 62c89c6 | 2007-01-09 21:20:01 -0800 | [diff] [blame] | 26 | keep_subject= query_apply= continue= utf8=-u resume=t |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 27 | while case "$#" in 0) break ;; esac |
Linus Torvalds | 853916f | 2005-04-12 01:40:20 -0700 | [diff] [blame] | 28 | do |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 29 | case "$1" in |
Junio C Hamano | d4a9ce7 | 2005-08-28 12:33:16 -0700 | [diff] [blame] | 30 | -u) utf8=-u ;; |
Junio C Hamano | bb1091a | 2007-01-09 21:31:36 -0800 | [diff] [blame] | 31 | -n) utf8=-n ;; |
Junio C Hamano | 6bff6a6 | 2005-08-16 22:18:27 -0700 | [diff] [blame] | 32 | -k) keep_subject=-k ;; |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 33 | -q) query_apply=t ;; |
| 34 | -c) continue="$2"; resume=f; shift ;; |
Junio C Hamano | e135554 | 2005-11-29 14:14:42 -0800 | [diff] [blame] | 35 | -m) fall_back_3way=t ;; |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 36 | -*) usage ;; |
| 37 | *) break ;; |
| 38 | esac |
| 39 | shift |
| 40 | done |
| 41 | |
| 42 | case "$continue" in |
| 43 | '') |
| 44 | rm -rf .dotest |
| 45 | mkdir .dotest |
Junio C Hamano | e11fc02 | 2005-10-06 14:25:52 -0700 | [diff] [blame] | 46 | num_msgs=$(git-mailsplit "$1" .dotest) || exit 1 |
| 47 | echo "$num_msgs patch(es) to process." |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 48 | shift |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 49 | esac |
| 50 | |
Junio C Hamano | 215a7ad | 2005-09-07 17:26:23 -0700 | [diff] [blame] | 51 | files=$(git-diff-index --cached --name-only HEAD) || exit |
Linus Torvalds | d571c2b | 2005-08-18 15:31:40 -0700 | [diff] [blame] | 52 | if [ "$files" ]; then |
| 53 | echo "Dirty index: cannot apply patches (dirty: $files)" >&2 |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 57 | case "$query_apply" in |
| 58 | t) touch .dotest/.query_apply |
| 59 | esac |
Junio C Hamano | 47f0b6d | 2005-10-06 14:25:52 -0700 | [diff] [blame] | 60 | case "$fall_back_3way" in |
| 61 | t) : >.dotest/.3way |
| 62 | esac |
Junio C Hamano | 6bff6a6 | 2005-08-16 22:18:27 -0700 | [diff] [blame] | 63 | case "$keep_subject" in |
| 64 | -k) : >.dotest/.keep_subject |
| 65 | esac |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 66 | |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 67 | signoff="$1" |
| 68 | set x .dotest/0* |
| 69 | shift |
| 70 | while case "$#" in 0) break;; esac |
Junio C Hamano | 3727531 | 2005-07-22 16:04:19 -0700 | [diff] [blame] | 71 | do |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 72 | i="$1" |
| 73 | case "$resume,$continue" in |
| 74 | f,$i) resume=t;; |
Junio C Hamano | 07a95d0 | 2005-09-04 10:37:07 -0700 | [diff] [blame] | 75 | f,*) shift |
| 76 | continue;; |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 77 | *) |
Junio C Hamano | d4a9ce7 | 2005-08-28 12:33:16 -0700 | [diff] [blame] | 78 | git-mailinfo $keep_subject $utf8 \ |
Junio C Hamano | 6bff6a6 | 2005-08-16 22:18:27 -0700 | [diff] [blame] | 79 | .dotest/msg .dotest/patch <$i >.dotest/info || exit 1 |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 80 | git-stripspace < .dotest/msg > .dotest/msg-clean |
| 81 | ;; |
| 82 | esac |
| 83 | while :; # for fixing up and retry |
| 84 | do |
| 85 | git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff" |
| 86 | case "$?" in |
Junio C Hamano | 4ebe63d | 2005-10-06 14:25:52 -0700 | [diff] [blame] | 87 | 0) |
| 88 | # Remove the cleanly applied one to reduce clutter. |
| 89 | rm -f .dotest/$i |
| 90 | ;; |
| 91 | 2) |
James Bottomley | ad4e9ce | 2005-04-20 08:23:00 -0700 | [diff] [blame] | 92 | # 2 is a special exit code from applypatch to indicate that |
| 93 | # the patch wasn't applied, but continue anyway |
Junio C Hamano | b50abe8 | 2005-07-29 15:37:11 -0700 | [diff] [blame] | 94 | ;; |
| 95 | *) |
| 96 | ret=$? |
| 97 | if test -f .dotest/.query_apply |
| 98 | then |
| 99 | echo >&2 "* Patch failed." |
| 100 | echo >&2 "* You could fix it up in your editor and" |
| 101 | echo >&2 " retry. If you want to do so, say yes here" |
| 102 | echo >&2 " AFTER fixing .dotest/patch up." |
| 103 | echo >&2 -n "Retry [y/N]? " |
| 104 | read yesno |
| 105 | case "$yesno" in |
| 106 | [Yy]*) |
| 107 | continue ;; |
| 108 | esac |
| 109 | fi |
| 110 | exit $ret |
| 111 | esac |
| 112 | break |
| 113 | done |
| 114 | shift |
Linus Torvalds | 853916f | 2005-04-12 01:40:20 -0700 | [diff] [blame] | 115 | done |
James Bottomley | ad4e9ce | 2005-04-20 08:23:00 -0700 | [diff] [blame] | 116 | # return to pristine |
| 117 | rm -fr .dotest |