3 # Copyright (c) 2005 Junio C Hamano
7 echo >&2 "usage: $0"' [-n] [-o dir] [--mbox] [--check] [-<diff options>...] upstream [ our-head ]
9 Prepare each commit with its patch since our-head forked from upstream,
10 one file per patch, for e-mail submission. Each output file is
11 numbered sequentially from 1, and uses the first line of the commit
12 message (massaged for pathname safety) as the filename.
14 When -o is specified, output files are created in that directory; otherwise in
15 the current working directory.
17 When -n is specified, instead of "[PATCH] Subject", the first line is formatted
18 as "[PATCH N/M] Subject", unless you have only one patch.
20 When --mbox is specified, the output is formatted to resemble
21 UNIX mailbox format, and can be concatenated together for processing
34 while case "$#" in 0) break;; esac
37 -a|
--a|
--au|
--aut|
--auth|
--autho|
--author)
39 -c|
--c|
--ch|
--che|
--chec|
--check)
41 -d|
--d|
--da|
--dat|
--date)
43 -m|
--m|
--mb|
--mbo|
--mbox)
44 date=t author
=t mbox
=t
;;
45 -n|
--n|
--nu|
--num|
--numb|
--numbe|
--number|
--numbere|
--numbered)
47 -o=*|
--o=*|
--ou=*|
--out=*|
--outp=*|
--outpu=*|
--output=*|
--output-=*|\
48 --output-d=*|
--output-di=*|
--output-dir=*|
--output-dire=*|\
49 --output-direc=*|
--output-direct=*|
--output-directo=*|\
50 --output-director=*|
--output-directory=*)
51 outdir
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
52 -o|
--o|
--ou|
--out|
--outp|
--outpu|
--output|
--output-|
--output-d|\
53 --output-di|
--output-dir|
--output-dire|
--output-direc|
--output-direct|\
54 --output-directo|
--output-director|
--output-directory)
55 case "$#" in 1) usage
;; esac; shift
57 -*) diff_opts
="$diff_opts$LF$1" ;;
64 2) linus
="$1" junio
="$2" ;;
65 1) linus
="$1" junio
=HEAD
;;
68 junio
=`git-rev-parse --verify "$junio"`
69 linus
=`git-rev-parse --verify "$linus"`
71 me
=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
75 *) outdir
="$outdir/" ;;
77 test -d "$outdir" || mkdir
-p "$outdir" ||
exit
80 trap 'rm -f $tmp-*' 0 1 2 3 15
103 s/author \(.*>\) \(.*\)$/au='\''\1'\'' ad='\''\2'\''/p
107 _x40
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
108 _x40
="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
109 stripCommitHead
='/^'"$_x40"' (from '"$_x40"')$/d'
111 git-rev-list
--merge-order "$junio" "^$linus" >$series
112 total
=`wc -l <$series | tr -dc "[0-9]"`
116 git-cat-file commit
"$commit" | git-stripspace
>$commsg
117 title
=`sed -ne "$titleScript" <$commsg`
123 *) num
=' '`printf "%d/%d" $i $total` ;;
127 file=`printf '%04d-%stxt' $i "$title"`
134 s|^\[PATCH[^]]*\] *||'
138 echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
139 mailScript
="$mailScript"'
140 s|^|Subject: [PATCH'"$num"'] |'
143 mailScript
="$mailScript"'
144 s|^|[PATCH'"$num"'] |'
148 eval "$(sed -ne "$whosepatchScript" $commsg)"
149 test "$author,$au" = ",$me" ||
{
150 mailScript
="$mailScript"'
154 test "$date,$au" = ",$me" ||
{
155 mailScript
="$mailScript"'
160 mailScript
="$mailScript"'
166 sed -ne "$mailScript" <$commsg
169 git-diff-tree
-p $diff_opts "$commit" | git-apply
--stat --summary
171 git-diff-tree
-p $diff_opts "$commit" |
sed -e "$stripCommitHead"
181 # This is slightly modified from Andrew Morton's Perfect Patch.
182 # Lines you introduce should not have trailing whitespace.
183 # Also check for an indentation that has SP before a TAB.
184 grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file"
186 : do not
exit with non-zero because we saw no problem
in the last one.