Skip to content

Instantly share code, notes, and snippets.

@panzy
Last active September 1, 2017 09:18
Show Gist options
  • Save panzy/b4e2d44cb005d58c0d917aee881e3887 to your computer and use it in GitHub Desktop.
Save panzy/b4e2d44cb005d58c0d917aee881e3887 to your computer and use it in GitHub Desktop.
like git-am, but for svn: Apply a series of patches from a mailbox. -- MAY BE DANGEROUS!!
#!/bin/bash
#
# like git-am, but for svn: Apply a series of patches from a mailbox.
#
# usage:
# $ svn-am.sh PATCH-FILES
#
# --
# panzy
# 2017-09-01 16:34:10
# extract and decode subject from patch file.
# arg1: patch filename
function getSubject {
# Subject samples
#
# (1)
# Subject: [PATCH 01/10] fix: addrbook api sometimes response undefined etag.
#
# (2) RFC 2047 encoded
#
# Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=E6=AD=A3=E5=BC=8F=E7=8E=AF?=
# =?UTF-8?q?=E5=A2=83=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=EF=BC=88=E5=9B=A0?=
# =?UTF-8?q?=E4=B8=BA=E5=BD=93=E5=89=8D=20pmmanage=20=E6=AD=A3=E5=BC=8F?=
# =?UTF-8?q?=E7=8E=AF=E5=A2=83=E8=BF=98=E6=B2=A1=E6=9C=89=E5=90=AF=E7=94=A8?=
# =?UTF-8?q?=20auth=EF=BC=89=E3=80=82?=
cat $1 |
# extract Subject header lines:
# 1. begin with /^Suject/;
# 2. end with /^[^ ]/;
awk 'BEGIN { flag = 0 } /^[^ ]/ { if (flag) flag = 0 } /^Subject/ { flag = 1; print } /^ / { if (flag) print }' |
# decode RFC 2047, https://github.com/sfindeisen/conv2047
conv2047.pl -d |
# remove literal "Subject: [PATCH m/n]"
sed 's/^Subject[^]]*\] //' |
# join lines
xargs
}
for f in "$@"
do
echo apply $f
patchResult=`svn patch $f`
if [[ $patchResult =~ 'Summary of conflicts:' ]]
then
echo "$patchResult"
break
else
svn commit --encoding UTF-8 -m "`getSubject $f`"
fi
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment