@matheusbsbs / matheus-bagliano / commits / 603d874587
Fork 0

format-patch: take sequence of ranges.

This enhances set of revs you can give format-patch. Originally, format-patch took either one rev, or two revs: format-patch rev1 format-patch rev1 rev2 The first format was a short-hand for "format-patch rev1 HEAD" (i.e. rev2==HEAD). What this meant was to find commits that are in branch rev2 that has not been merged to branch rev1. The above notation is still supported, but now it takes sequence of "from1..to1 from2..to2 ...". In short, the second format has become a short-hand for "format-patch rev1..rev2". Commits in to1 but not in from1, to2 but not in from2, ... are formatted as emailable patches. With this, cherry-picking from other branch can be written as: git-format-patch -k --stdout master..branch1 master..branch2 | git-am -k -3 which is generally faster than traditional cherry-pick (which always did 3-way merge) if patches apply cleanly, and still falls back on 3-way merge if some of them do not. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 13, 2005 at 23:18 UTC 603d874587c1b6126c4415d1ca91cfc799fe9043
1 file changed +63 -36
git-format-patch.sh
+63 -36
@@ -6,7 +6,9 @@
6 . git-sh-setup || die "Not a git archive."
7
8 usage () {
9 - echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox] [--check] [--signoff] [-<diff options>...] upstream [ our-head ]
9 + echo >&2 "usage: $0"' [-n] [-o dir | --stdout] [--keep-subject] [--mbox]
10 + [--check] [--signoff] [-<diff options>...]
11 + ( from..to ... | upstream [ our-head ] )
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
@@ -75,25 +77,70 @@ tt)
77 die '--keep-subject and --numbered are incompatible.' ;;
78 esac
79
78 -rev1= rev2=
79 -case "$#" in
80 -2)
81 - rev1="$1" rev2="$2" ;;
82 -1)
83 - case "$1" in
84 - *..*)
85 - rev1=`expr "$1" : '\(.*\)\.\.'`
86 - rev2=`expr "$1" : '.*\.\.\(.*\)'`
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 ;;
88 - *)
89 - rev1="$1"
90 - rev2="HEAD"
100 +1,*)
101 + # single rev1
102 + set x "$1..HEAD"
103 + shift
104 + ;;
105 +2,?*..?*)
106 + # not traditional "rev1" "rev2"
107 + ;;
108 +2,*)
109 + set x "$1..$2"
110 + shift
111 ;;
92 - esac ;;
93 -*)
94 - usage ;;
112 esac
113
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 +
144 me=`git-var GIT_AUTHOR_IDENT | sed -e 's/>.*/>/'`
145
146 case "$outdir" in
@@ -102,13 +149,6 @@ case "$outdir" in
149 esac
150 test -d "$outdir" || mkdir -p "$outdir" || exit
151
105 -tmp=.tmp-series$$
106 -trap 'rm -f $tmp-*' 0 1 2 3 15
107 -
108 -series=$tmp-series
109 -commsg=$tmp-commsg
110 -filelist=$tmp-files
111 -
152 titleScript='
153 /./d
154 /^$/n
@@ -130,19 +170,6 @@ whosepatchScript='
170 q
171 }'
172
133 -git-cherry -v "$rev1" "$rev2" |
134 -while read sign rev comment
135 -do
136 - case "$sign" in
137 - '-')
138 - echo >&2 "Merged already: $comment"
139 - ;;
140 - *)
141 - echo $rev
142 - ;;
143 - esac
144 -done >$series
145 -
173 process_one () {
174 mailScript='
175 /./d