]>
Commit | Line | Data |
---|---|---|
0acfc972 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
215a7ad1 | 6 | . git-sh-setup || die "Not a git archive." |
4282c4fb | 7 | |
0acfc972 | 8 | usage () { |
603d8745 JH |
9 | echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox] |
10 | [--check] [--signoff] [-<diff options>...] | |
11 | ( from..to ... | upstream [ our-head ] ) | |
0acfc972 JH |
12 | |
13 | Prepare each commit with its patch since our-head forked from upstream, | |
14 | one file per patch, for e-mail submission. Each output file is | |
15 | numbered sequentially from 1, and uses the first line of the commit | |
16 | message (massaged for pathname safety) as the filename. | |
17 | ||
18 | When -o is specified, output files are created in that directory; otherwise in | |
19 | the current working directory. | |
20 | ||
21 | When -n is specified, instead of "[PATCH] Subject", the first line is formatted | |
22 | as "[PATCH N/M] Subject", unless you have only one patch. | |
5c2c972f JH |
23 | |
24 | When --mbox is specified, the output is formatted to resemble | |
25 | UNIX mailbox format, and can be concatenated together for processing | |
26 | with applymbox. | |
0acfc972 JH |
27 | ' |
28 | exit 1 | |
29 | } | |
30 | ||
31 | diff_opts= | |
0acfc972 JH |
32 | LF=' |
33 | ' | |
0acfc972 | 34 | |
5c2c972f | 35 | outdir=./ |
0acfc972 JH |
36 | while case "$#" in 0) break;; esac |
37 | do | |
38 | case "$1" in | |
5c2c972f JH |
39 | -a|--a|--au|--aut|--auth|--autho|--author) |
40 | author=t ;; | |
41 | -c|--c|--ch|--che|--chec|--check) | |
42 | check=t ;; | |
44d2eb51 JH |
43 | -d|--d|--da|--dat|--date) |
44 | date=t ;; | |
5c2c972f JH |
45 | -m|--m|--mb|--mbo|--mbox) |
46 | date=t author=t mbox=t ;; | |
af5260ee JH |
47 | -k|--k|--ke|--kee|--keep|--keep-|--keep-s|--keep-su|--keep-sub|\ |
48 | --keep-subj|--keep-subje|--keep-subjec|--keep-subject) | |
49 | keep_subject=t ;; | |
0acfc972 JH |
50 | -n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered) |
51 | numbered=t ;; | |
d9ac9df4 | 52 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
b097584b | 53 | signoff=t ;; |
655c7470 JH |
54 | --st|--std|--stdo|--stdou|--stdout) |
55 | stdout=t mbox=t date=t author=t ;; | |
0acfc972 JH |
56 | -o=*|--o=*|--ou=*|--out=*|--outp=*|--outpu=*|--output=*|--output-=*|\ |
57 | --output-d=*|--output-di=*|--output-dir=*|--output-dire=*|\ | |
58 | --output-direc=*|--output-direct=*|--output-directo=*|\ | |
59 | --output-director=*|--output-directory=*) | |
60 | outdir=`expr "$1" : '-[^=]*=\(.*\)'` ;; | |
61 | -o|--o|--ou|--out|--outp|--outpu|--output|--output-|--output-d|\ | |
62 | --output-di|--output-dir|--output-dire|--output-direc|--output-direct|\ | |
63 | --output-directo|--output-director|--output-directory) | |
64 | case "$#" in 1) usage ;; esac; shift | |
65 | outdir="$1" ;; | |
4a5b63e3 JH |
66 | -*' '* | -*"$LF"* | -*' '*) |
67 | # Ignore diff option that has whitespace for now. | |
68 | ;; | |
69 | -*) diff_opts="$diff_opts$1 " ;; | |
0acfc972 JH |
70 | *) break ;; |
71 | esac | |
72 | shift | |
73 | done | |
74 | ||
af5260ee JH |
75 | case "$keep_subject$numbered" in |
76 | tt) | |
77 | die '--keep-subject and --numbered are incompatible.' ;; | |
78 | esac | |
79 | ||
603d8745 JH |
80 | tmp=.tmp-series$$ |
81 | trap 'rm -f $tmp-*' 0 1 2 3 15 | |
82 | ||
83 | series=$tmp-series | |
84 | commsg=$tmp-commsg | |
85 | filelist=$tmp-files | |
86 | ||
87 | # Backward compatible argument parsing hack. | |
88 | # | |
89 | # Historically, we supported: | |
90 | # 1. "rev1" is equivalent to "rev1..HEAD" | |
91 | # 2. "rev1..rev2" | |
92 | # 3. "rev1" "rev2 is equivalent to "rev1..rev2" | |
93 | # | |
94 | # We want to take a sequence of "rev1..rev2" in general. | |
95 | ||
96 | case "$#,$1" in | |
97 | 1,?*..?*) | |
98 | # single "rev1..rev2" | |
99 | ;; | |
100 | 1,*) | |
101 | # single rev1 | |
102 | set x "$1..HEAD" | |
103 | shift | |
104 | ;; | |
105 | 2,?*..?*) | |
106 | # not traditional "rev1" "rev2" | |
4a5b63e3 | 107 | ;; |
603d8745 JH |
108 | 2,*) |
109 | set x "$1..$2" | |
110 | shift | |
4a5b63e3 | 111 | ;; |
0acfc972 JH |
112 | esac |
113 | ||
603d8745 JH |
114 | # Now we have what we want in $@ |
115 | for revpair | |
116 | do | |
117 | case "$revpair" in | |
118 | ?*..?*) | |
119 | rev1=`expr "$revpair" : '\(.*\)\.\.'` | |
120 | rev2=`expr "$revpair" : '.*\.\.\(.*\)'` | |
121 | ;; | |
122 | *) | |
123 | usage | |
124 | ;; | |
125 | esac | |
126 | git-rev-parse --verify "$rev1^0" >/dev/null 2>&1 || | |
127 | die "Not a valid rev $rev1 ($revpair)" | |
128 | git-rev-parse --verify "$rev2^0" >/dev/null 2>&1 || | |
129 | die "Not a valid rev $rev2 ($revpair)" | |
130 | git-cherry -v "$rev1" "$rev2" | | |
131 | while read sign rev comment | |
132 | do | |
133 | case "$sign" in | |
134 | '-') | |
135 | echo >&2 "Merged already: $comment" | |
136 | ;; | |
137 | *) | |
138 | echo $rev | |
139 | ;; | |
140 | esac | |
141 | done | |
142 | done >$series | |
143 | ||
44d2eb51 JH |
144 | me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'` |
145 | ||
0acfc972 JH |
146 | case "$outdir" in |
147 | */) ;; | |
148 | *) outdir="$outdir/" ;; | |
149 | esac | |
150 | test -d "$outdir" || mkdir -p "$outdir" || exit | |
151 | ||
0acfc972 | 152 | titleScript=' |
1855c044 JH |
153 | /./d |
154 | /^$/n | |
155 | s/^\[PATCH[^]]*\] *// | |
0acfc972 JH |
156 | s/[^-a-z.A-Z_0-9]/-/g |
157 | s/\.\.\.*/\./g | |
158 | s/\.*$// | |
159 | s/--*/-/g | |
160 | s/^-// | |
161 | s/-$// | |
162 | s/$/./ | |
1855c044 | 163 | p |
0acfc972 JH |
164 | q |
165 | ' | |
166 | ||
44d2eb51 JH |
167 | whosepatchScript=' |
168 | /^author /{ | |
169 | s/author \(.*>\) \(.*\)$/au='\''\1'\'' ad='\''\2'\''/p | |
170 | q | |
171 | }' | |
172 | ||
655c7470 | 173 | process_one () { |
0acfc972 | 174 | mailScript=' |
1855c044 | 175 | /./d |
af5260ee JH |
176 | /^$/n' |
177 | case "$keep_subject" in | |
178 | t) ;; | |
5c2c972f JH |
179 | *) |
180 | mailScript="$mailScript"' | |
af5260ee | 181 | s|^\[PATCH[^]]*\] *|| |
5c2c972f JH |
182 | s|^|[PATCH'"$num"'] |' |
183 | ;; | |
184 | esac | |
af5260ee JH |
185 | mailScript="$mailScript"' |
186 | s|^|Subject: |' | |
187 | case "$mbox" in | |
188 | t) | |
189 | echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line | |
190 | ;; | |
191 | esac | |
655c7470 | 192 | |
44d2eb51 | 193 | eval "$(sed -ne "$whosepatchScript" $commsg)" |
5c2c972f | 194 | test "$author,$au" = ",$me" || { |
44d2eb51 JH |
195 | mailScript="$mailScript"' |
196 | a\ | |
197 | From: '"$au" | |
198 | } | |
199 | test "$date,$au" = ",$me" || { | |
200 | mailScript="$mailScript"' | |
201 | a\ | |
202 | Date: '"$ad" | |
203 | } | |
204 | ||
205 | mailScript="$mailScript"' | |
0acfc972 JH |
206 | : body |
207 | p | |
208 | n | |
209 | b body' | |
210 | ||
655c7470 JH |
211 | (cat $commsg ; echo; echo) | |
212 | sed -ne "$mailScript" | | |
213 | git-stripspace | |
b097584b JS |
214 | |
215 | test "$signoff" = "t" && { | |
216 | offsigner=`git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'` | |
d9ac9df4 JS |
217 | line="Signed-off-by: $offsigner" |
218 | grep -q "^$line\$" $commsg || { | |
219 | echo | |
220 | echo "$line" | |
221 | echo | |
222 | } | |
b097584b | 223 | } |
cc5625a5 | 224 | echo |
0acfc972 JH |
225 | echo '---' |
226 | echo | |
227 | git-diff-tree -p $diff_opts "$commit" | git-apply --stat --summary | |
228 | echo | |
3ff8cbed | 229 | git-cat-file commit "$commit^" | sed -e 's/^tree /applies-to: /' -e q |
b10c1a74 | 230 | git-diff-tree -p $diff_opts "$commit" |
3ff8cbed JH |
231 | echo "---" |
232 | echo "@@GIT_VERSION@@" | |
5c2c972f JH |
233 | |
234 | case "$mbox" in | |
235 | t) | |
236 | echo | |
237 | ;; | |
238 | esac | |
655c7470 JH |
239 | } |
240 | ||
241 | total=`wc -l <$series | tr -dc "[0-9]"` | |
242 | i=1 | |
243 | while read commit | |
244 | do | |
245 | git-cat-file commit "$commit" | git-stripspace >$commsg | |
246 | title=`sed -ne "$titleScript" <$commsg` | |
247 | case "$numbered" in | |
248 | '') num= ;; | |
249 | *) | |
250 | case $total in | |
251 | 1) num= ;; | |
252 | *) num=' '`printf "%d/%d" $i $total` ;; | |
253 | esac | |
5c2c972f | 254 | esac |
655c7470 JH |
255 | |
256 | file=`printf '%04d-%stxt' $i "$title"` | |
257 | if test '' = "$stdout" | |
258 | then | |
259 | echo "* $file" | |
260 | process_one >"$outdir$file" | |
261 | if test t = "$check" | |
262 | then | |
263 | # This is slightly modified from Andrew Morton's Perfect Patch. | |
264 | # Lines you introduce should not have trailing whitespace. | |
265 | # Also check for an indentation that has SP before a TAB. | |
266 | grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file" | |
267 | : | |
268 | fi | |
269 | else | |
270 | echo >&2 "* $file" | |
271 | process_one | |
272 | fi | |
273 | i=`expr "$i" + 1` | |
0acfc972 | 274 | done <$series |