3 # Copyright (c) 2005 Junio C Hamano
8 # Force diff to run in C locale.
13 echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
14 [--check] [--signoff] [-<diff options>...]
16 ( from..to ... | upstream [ our-head ] )
18 Prepare each commit with its patch since our-head forked from upstream,
19 one file per patch, for e-mail submission. Each output file is
20 numbered sequentially from 1, and uses the first line of the commit
21 message (massaged for pathname safety) as the filename.
23 When -o is specified, output files are created in that directory; otherwise in
24 the current working directory.
26 When -n is specified, instead of "[PATCH] Subject", the first line is formatted
27 as "[PATCH N/M] Subject", unless you have only one patch.
29 When --mbox is specified, the output is formatted to resemble
30 UNIX mailbox format, and can be concatenated together for processing
41 while case "$#" in 0) break;; esac
44 -a|
--a|
--au|
--aut|
--auth|
--autho|
--author)
46 -c|
--c|
--ch|
--che|
--chec|
--check)
48 -d|
--d|
--da|
--dat|
--date)
50 -m|
--m|
--mb|
--mbo|
--mbox)
51 date=t author
=t mbox
=t
;;
52 -k|
--k|
--ke|
--kee|
--keep|
--keep-|
--keep-s|
--keep-su|
--keep-sub|\
53 --keep-subj|
--keep-subje|
--keep-subjec|
--keep-subject)
55 -n|
--n|
--nu|
--num|
--numb|
--numbe|
--number|
--numbere|
--numbered)
57 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
59 --st|
--std|
--stdo|
--stdou|
--stdout)
60 stdout
=t mbox
=t
date=t author
=t
;;
61 -o=*|
--o=*|
--ou=*|
--out=*|
--outp=*|
--outpu=*|
--output=*|
--output-=*|\
62 --output-d=*|
--output-di=*|
--output-dir=*|
--output-dire=*|\
63 --output-direc=*|
--output-direct=*|
--output-directo=*|\
64 --output-director=*|
--output-directory=*)
65 outdir
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
66 -o|
--o|
--ou|
--out|
--outp|
--outpu|
--output|
--output-|
--output-d|\
67 --output-di|
--output-dir|
--output-dire|
--output-direc|
--output-direct|\
68 --output-directo|
--output-director|
--output-directory)
69 case "$#" in 1) usage
;; esac; shift
71 -h|
--h|
--he|
--hel|
--help)
74 -*' '* |
-*"$LF"* |
-*' '*)
75 # Ignore diff option that has whitespace for now.
77 -*) diff_opts
="$diff_opts$1 " ;;
83 case "$keep_subject$numbered" in
85 die
'--keep-subject and --numbered are incompatible.' ;;
89 trap 'rm -f $tmp-*' 0 1 2 3 15
95 # Backward compatible argument parsing hack.
97 # Historically, we supported:
98 # 1. "rev1" is equivalent to "rev1..HEAD"
100 # 3. "rev1" "rev2 is equivalent to "rev1..rev2"
102 # We want to take a sequence of "rev1..rev2" in general.
103 # Also, "rev1.." should mean "rev1..HEAD"; git-diff users are
104 # familiar with that syntax.
108 # single "rev1..rev2"
111 # single "rev1.." should mean "rev1..HEAD"
121 # not traditional "rev1" "rev2"
129 # Now we have what we want in $@
134 rev1
=`expr "$revpair" : '\(.*\)\.\.'`
135 rev2
=`expr "$revpair" : '.*\.\.\(.*\)'`
142 git-rev-parse
--verify "$rev1^0" >/dev
/null
2>&1 ||
143 die
"Not a valid rev $rev1 ($revpair)"
144 git-rev-parse
--verify "$rev2^0" >/dev
/null
2>&1 ||
145 die
"Not a valid rev $rev2 ($revpair)"
146 git-cherry
-v "$rev1" "$rev2" |
147 while read sign
rev comment
151 echo >&2 "Merged already: $comment"
160 me
=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
164 *) outdir
="$outdir/" ;;
166 test -d "$outdir" || mkdir
-p "$outdir" ||
exit
171 s/^\[PATCH[^]]*\] *//
172 s/[^-a-z.A-Z_0-9]/-/g
185 s/author \(.*>\) \(.*\)$/au='\''\1'\'' ad='\''\2'\''/p
193 case "$keep_subject" in
196 mailScript
="$mailScript"'
197 s|^\[PATCH[^]]*\] *||
198 s|^|[PATCH'"$num"'] |'
201 mailScript
="$mailScript"'
205 echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
209 eval "$(sed -ne "$whosepatchScript" $commsg)"
210 test "$author,$au" = ",$me" ||
{
211 mailScript
="$mailScript"'
215 test "$date,$au" = ",$me" ||
{
216 mailScript
="$mailScript"'
221 mailScript
="$mailScript"'
227 (cat $commsg ; echo; echo) |
228 sed -ne "$mailScript" |
231 test "$signoff" = "t" && {
232 offsigner
=`git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`
233 line
="Signed-off-by: $offsigner"
234 grep -q "^$line\$" $commsg ||
{
243 git-diff-tree
-p $diff_opts "$commit" | git-apply
--stat --summary
245 git-diff-tree
-p $diff_opts "$commit"
247 echo "@@GIT_VERSION@@"
256 total
=`wc -l <$series | tr -dc "[0-9]"`
257 case "$total,$numbered" in
261 numfmt
=`echo "$total" | wc -c`
262 numfmt
=$
(($numfmt-1))
263 numfmt
=" %0${numfmt}d/$total"
269 git-cat-file commit
"$commit" | git-stripspace
>$commsg
270 title
=`sed -ne "$titleScript" <$commsg`
274 num
=`printf "$numfmt" $i` ;;
277 file=`printf '%04d-%stxt' $i "$title"`
278 if test '' = "$stdout"
281 process_one
>"$outdir$file"
284 # This is slightly modified from Andrew Morton's Perfect Patch.
285 # Lines you introduce should not have trailing whitespace.
286 # Also check for an indentation that has SP before a TAB.
287 grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file"