3 # Copyright (c) 2005 Junio C Hamano
6 . git-sh-setup || die
"Not a git archive."
9 echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
10 [--check] [--signoff] [-<diff options>...]
11 ( from..to ... | upstream [ our-head ] )
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.
18 When -o is specified, output files are created in that directory; otherwise in
19 the current working directory.
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.
24 When --mbox is specified, the output is formatted to resemble
25 UNIX mailbox format, and can be concatenated together for processing
36 while case "$#" in 0) break;; esac
39 -a|
--a|
--au|
--aut|
--auth|
--autho|
--author)
41 -c|
--c|
--ch|
--che|
--chec|
--check)
43 -d|
--d|
--da|
--dat|
--date)
45 -m|
--m|
--mb|
--mbo|
--mbox)
46 date=t author
=t mbox
=t
;;
47 -k|
--k|
--ke|
--kee|
--keep|
--keep-|
--keep-s|
--keep-su|
--keep-sub|\
48 --keep-subj|
--keep-subje|
--keep-subjec|
--keep-subject)
50 -n|
--n|
--nu|
--num|
--numb|
--numbe|
--number|
--numbere|
--numbered)
52 -s|
--s|
--si|
--sig|
--sign|
--signo|
--signof|
--signoff)
54 --st|
--std|
--stdo|
--stdou|
--stdout)
55 stdout
=t mbox
=t
date=t author
=t
;;
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
66 -*' '* |
-*"$LF"* |
-*' '*)
67 # Ignore diff option that has whitespace for now.
69 -*) diff_opts
="$diff_opts$1 " ;;
75 case "$keep_subject$numbered" in
77 die
'--keep-subject and --numbered are incompatible.' ;;
81 trap 'rm -f $tmp-*' 0 1 2 3 15
87 # Backward compatible argument parsing hack.
89 # Historically, we supported:
90 # 1. "rev1" is equivalent to "rev1..HEAD"
92 # 3. "rev1" "rev2 is equivalent to "rev1..rev2"
94 # We want to take a sequence of "rev1..rev2" in general.
106 # not traditional "rev1" "rev2"
114 # Now we have what we want in $@
119 rev1
=`expr "$revpair" : '\(.*\)\.\.'`
120 rev2
=`expr "$revpair" : '.*\.\.\(.*\)'`
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
135 echo >&2 "Merged already: $comment"
144 me
=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
148 *) outdir
="$outdir/" ;;
150 test -d "$outdir" || mkdir
-p "$outdir" ||
exit
155 s/^\[PATCH[^]]*\] *//
156 s/[^-a-z.A-Z_0-9]/-/g
169 s/author \(.*>\) \(.*\)$/au='\''\1'\'' ad='\''\2'\''/p
177 case "$keep_subject" in
180 mailScript
="$mailScript"'
181 s|^\[PATCH[^]]*\] *||
182 s|^|[PATCH'"$num"'] |'
185 mailScript
="$mailScript"'
189 echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
193 eval "$(sed -ne "$whosepatchScript" $commsg)"
194 test "$author,$au" = ",$me" ||
{
195 mailScript
="$mailScript"'
199 test "$date,$au" = ",$me" ||
{
200 mailScript
="$mailScript"'
205 mailScript
="$mailScript"'
211 (cat $commsg ; echo; echo) |
212 sed -ne "$mailScript" |
215 test "$signoff" = "t" && {
216 offsigner
=`git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`
217 line
="Signed-off-by: $offsigner"
218 grep -q "^$line\$" $commsg ||
{
227 git-diff-tree
-p $diff_opts "$commit" | git-apply
--stat --summary
229 git-cat-file commit
"$commit^" |
sed -e 's/^tree /applies-to: /' -e q
230 git-diff-tree
-p $diff_opts "$commit"
232 echo "@@GIT_VERSION@@"
241 total
=`wc -l <$series | tr -dc "[0-9]"`
245 git-cat-file commit
"$commit" | git-stripspace
>$commsg
246 title
=`sed -ne "$titleScript" <$commsg`
252 *) num
=' '`printf "%d/%d" $i $total` ;;
256 file=`printf '%04d-%stxt' $i "$title"`
257 if test '' = "$stdout"
260 process_one
>"$outdir$file"
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"