Skip to content

Commit c574e68

Browse files
Oblomovgitster
authored andcommitted
git-am foreign patch support: StGIT support
Support StGIT patches by implementing a simple perl-based converter mimicking StGIT's own parse_patch. Also support StGIT patch series by 'exploding' the index into a list of files and re-running the mail splitting with patch_format set to stgit. Signed-off-by: Giuseppe Bilotta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 15ced75 commit c574e68

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

git-am.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,63 @@ split_patches () {
191191
exit 1
192192
}
193193
;;
194+
stgit-series)
195+
if test $# -ne 1
196+
then
197+
echo "Only one StGIT patch series can be applied at once"
198+
exit 1
199+
fi
200+
series_dir=`dirname "$1"`
201+
series_file="$1"
202+
shift
203+
{
204+
set x
205+
while read filename
206+
do
207+
set "$@" "$series_dir/$filename"
208+
done
209+
# remove the safety x
210+
shift
211+
# remove the arg coming from the first-line comment
212+
shift
213+
} < "$series_file"
214+
# set the patch format appropriately
215+
patch_format=stgit
216+
# now handle the actual StGIT patches
217+
split_patches "$@"
218+
;;
219+
stgit)
220+
this=0
221+
for stgit in "$@"
222+
do
223+
this=`expr "$this" + 1`
224+
msgnum=`printf "%0${prec}d" $this`
225+
# Perl version of StGIT parse_patch. The first nonemptyline
226+
# not starting with Author, From or Date is the
227+
# subject, and the body starts with the next nonempty
228+
# line not starting with Author, From or Date
229+
perl -ne 'BEGIN { $subject = 0 }
230+
if ($subject > 1) { print ; }
231+
elsif (/^\s+$/) { next ; }
232+
elsif (/^Author:/) { print s/Author/From/ ; }
233+
elsif (/^(From|Date)/) { print ; }
234+
elsif ($subject) {
235+
$subject = 2 ;
236+
print "\n" ;
237+
print ;
238+
} else {
239+
print "Subject: ", $_ ;
240+
$subject = 1;
241+
}
242+
' < "$stgit" > "$dotest/$msgnum" || {
243+
echo "Failed to import $patch_format patch $stgit"
244+
exit 1
245+
}
246+
done
247+
echo "$this" > "$dotest/last"
248+
this=
249+
msgnum=
250+
;;
194251
*)
195252
echo "Patch format $patch_format is not supported."
196253
exit 1

0 commit comments

Comments
 (0)