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## 7## Update: Ryan Anderson finally shamed me into naming this "applymbox". 8## 9## You give it a mbox-format collection of emails, and it will try to 10## apply them to the kernel using "applypatch" 11## 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. 18## 19## git-am is supposed to be the newer and better tool for this job. 20 21USAGE='[-u] [-k] [-q] [-m] (-c .dotest/<num> | mbox) [signoff]' 22. git-sh-setup 23 24git var GIT_COMMITTER_IDENT >/dev/null ||exit 25 26keep_subject= query_apply=continue= utf8=-u resume=t 27while case"$#"in0)break;;esac 28do 29case"$1"in 30-u) utf8=-u;; 31-n) utf8=-n;; 32-k) keep_subject=-k;; 33-q) query_apply=t ;; 34-c)continue="$2"; resume=f;shift;; 35-m) fall_back_3way=t ;; 36-*) usage ;; 37*)break;; 38esac 39shift 40done 41 42case"$continue"in 43'') 44rm-rf .dotest 45mkdir .dotest 46 num_msgs=$(git-mailsplit "$1" .dotest)||exit1 47echo"$num_msgspatch(es) to process." 48shift 49esac 50 51files=$(git-diff-index --cached --name-only HEAD)||exit 52if["$files"];then 53echo"Dirty index: cannot apply patches (dirty:$files)">&2 54exit1 55fi 56 57case"$query_apply"in 58t)touch .dotest/.query_apply 59esac 60case"$fall_back_3way"in 61t) : >.dotest/.3way 62esac 63case"$keep_subject"in 64-k) : >.dotest/.keep_subject 65esac 66 67signoff="$1" 68set x .dotest/0* 69shift 70while case"$#"in0)break;;esac 71do 72 i="$1" 73case"$resume,$continue"in 74 f,$i) resume=t;; 75 f,*)shift 76continue;; 77*) 78 git-mailinfo$keep_subject $utf8 \ 79 .dotest/msg .dotest/patch<$i>.dotest/info ||exit1 80test -s .dotest/patch|| { 81echo"Patch is empty. Was it split wrong?" 82exit1 83} 84 git-stripspace< .dotest/msg > .dotest/msg-clean 85;; 86esac 87while:;# for fixing up and retry 88do 89 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff" 90case"$?"in 910) 92# Remove the cleanly applied one to reduce clutter. 93rm-f .dotest/$i 94;; 952) 96# 2 is a special exit code from applypatch to indicate that 97# the patch wasn't applied, but continue anyway 98;; 99*) 100 ret=$? 101iftest -f .dotest/.query_apply 102then 103echo>&2"* Patch failed." 104echo>&2"* You could fix it up in your editor and" 105echo>&2" retry. If you want to do so, say yes here" 106echo>&2" AFTER fixing .dotest/patch up." 107echo>&2-n"Retry [y/N]? " 108read yesno 109case"$yesno"in 110[Yy]*) 111continue;; 112esac 113fi 114exit$ret 115esac 116break 117done 118shift 119done 120# return to pristine 121rm-fr .dotest