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