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] [--check] [--signoff] [-<diff options>...] upstream [ our-head ]
11 Prepare each commit with its patch since our-head forked from upstream,
12 one file per patch, for e-mail submission. Each output file is
13 numbered sequentially from 1, and uses the first line of the commit
14 message (massaged for pathname safety) as the filename.
16 When -o is specified, output files are created in that directory; otherwise in
17 the current working directory.
19 When -n is specified, instead of "[PATCH] Subject", the first line is formatted
20 as "[PATCH N/M] Subject", unless you have only one patch.
22 When --mbox is specified, the output is formatted to resemble
23 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 -k|--k|--ke|--kee|--keep|--keep-|--keep-s|--keep-su|--keep-sub|\
46 --keep-subj|--keep-subje|--keep-subjec|--keep-subject)
48 -n|--n|--nu|--num|--numb|--numbe|--number|--numbere|--numbered)
50 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
52 --st|--std|--stdo|--stdou|--stdout)
53 stdout=t mbox=t date=t author=t ;;
54 -o=*|--o=*|--ou=*|--out=*|--outp=*|--outpu=*|--output=*|--output-=*|\
55 --output-d=*|--output-di=*|--output-dir=*|--output-dire=*|\
56 --output-direc=*|--output-direct=*|--output-directo=*|\
57 --output-director=*|--output-directory=*)
58 outdir=`expr "$1" : '-[^=]*=\(.*\)'` ;;
59 -o|--o|--ou|--out|--outp|--outpu|--output|--output-|--output-d|\
60 --output-di|--output-dir|--output-dire|--output-direc|--output-direct|\
61 --output-directo|--output-director|--output-directory)
62 case "$#" in 1) usage ;; esac; shift
64 -*' '* | -*"$LF"* | -*' '*)
65 # Ignore diff option that has whitespace for now.
67 -*) diff_opts="$diff_opts$1 " ;;
73 case "$keep_subject$numbered" in
75 die '--keep-subject and --numbered are incompatible.' ;;
81 rev1="$1" rev2="$2" ;;
85 rev1=`expr "$1" : '\(.*\)\.\.'`
86 rev2=`expr "$1" : '.*\.\.\(.*\)'`
97 me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
101 *) outdir="$outdir/" ;;
103 test -d "$outdir" || mkdir -p "$outdir" || exit
106 trap 'rm -f $tmp-*' 0 1 2 3 15
115 s/^\[PATCH[^]]*\] *//
116 s/[^-a-z.A-Z_0-9]/-/g
129 s/author \(.*>\) \(.*\)$/au='\''\1'\'' ad='\''\2'\''/p
133 git-cherry -v "$rev1" "$rev2" |
134 while read sign rev comment
138 echo >&2 "Merged already: $comment"
150 case "$keep_subject" in
153 mailScript="$mailScript"'
154 s|^\[PATCH[^]]*\] *||
155 s|^|[PATCH'"$num"'] |'
158 mailScript="$mailScript"'
162 echo 'From nobody Mon Sep 17 00:00:00 2001' ;# UNIX "From" line
166 eval "$(sed -ne "$whosepatchScript" $commsg)"
167 test "$author,$au" = ",$me" || {
168 mailScript="$mailScript"'
172 test "$date,$au" = ",$me" || {
173 mailScript="$mailScript"'
178 mailScript="$mailScript"'
184 (cat $commsg ; echo; echo) |
185 sed -ne "$mailScript" |
188 test "$signoff" = "t" && {
189 offsigner=`git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`
190 line="Signed-off-by: $offsigner"
191 grep -q "^$line\$" $commsg || {
200 git-diff-tree -p $diff_opts "$commit" | git-apply --stat --summary
202 git-cat-file commit "$commit^" | sed -e 's/^tree /applies-to: /' -e q
203 git-diff-tree -p $diff_opts "$commit"
205 echo "@@GIT_VERSION@@"
214 total=`wc -l <$series | tr -dc "[0-9]"`
218 git-cat-file commit "$commit" | git-stripspace >$commsg
219 title=`sed -ne "$titleScript" <$commsg`
225 *) num=' '`printf "%d/%d" $i $total` ;;
229 file=`printf '%04d-%stxt' $i "$title"`
230 if test '' = "$stdout"
233 process_one >"$outdir$file"
236 # This is slightly modified from Andrew Morton's Perfect Patch.
237 # Lines you introduce should not have trailing whitespace.
238 # Also check for an indentation that has SP before a TAB.
239 grep -n '^+\([ ]* .*\|.*[ ]\)$' "$outdir$file"