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 24keep_subject= query_apply=continue= utf8= resume=t 25while case"$#"in0)break;;esac 26do 27case"$1"in 28-u) utf8=-u;; 29-k) keep_subject=-k;; 30-q) query_apply=t ;; 31-c)continue="$2"; resume=f;shift;; 32-m) fall_back_3way=t ;; 33-*) usage ;; 34*)break;; 35esac 36shift 37done 38 39case"$continue"in 40'') 41rm-rf .dotest 42mkdir .dotest 43 num_msgs=$(git-mailsplit "$1" .dotest)||exit1 44echo"$num_msgspatch(es) to process." 45shift 46esac 47 48files=$(git-diff-index --cached --name-only HEAD)||exit 49if["$files"];then 50echo"Dirty index: cannot apply patches (dirty:$files)">&2 51exit1 52fi 53 54case"$query_apply"in 55t)touch .dotest/.query_apply 56esac 57case"$fall_back_3way"in 58t) : >.dotest/.3way 59esac 60case"$keep_subject"in 61-k) : >.dotest/.keep_subject 62esac 63 64signoff="$1" 65set x .dotest/0* 66shift 67while case"$#"in0)break;;esac 68do 69 i="$1" 70case"$resume,$continue"in 71 f,$i) resume=t;; 72 f,*)shift 73continue;; 74*) 75 git-mailinfo$keep_subject $utf8 \ 76 .dotest/msg .dotest/patch<$i>.dotest/info ||exit1 77 git-stripspace< .dotest/msg > .dotest/msg-clean 78;; 79esac 80while:;# for fixing up and retry 81do 82 git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff" 83case"$?"in 840) 85# Remove the cleanly applied one to reduce clutter. 86rm-f .dotest/$i 87;; 882) 89# 2 is a special exit code from applypatch to indicate that 90# the patch wasn't applied, but continue anyway 91;; 92*) 93 ret=$? 94iftest -f .dotest/.query_apply 95then 96echo>&2"* Patch failed." 97echo>&2"* You could fix it up in your editor and" 98echo>&2" retry. If you want to do so, say yes here" 99echo>&2" AFTER fixing .dotest/patch up." 100echo>&2-n"Retry [y/N]? " 101read yesno 102case"$yesno"in 103[Yy]*) 104continue;; 105esac 106fi 107exit$ret 108esac 109break 110done 111shift 112done 113# return to pristine 114rm-fr .dotest