From 35a54ae2e849cf4044175555a43dc4d6d9a3431f Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Wed, 8 Mar 2006 10:59:03 -0300 Subject: Added a script to make easier to import patches sent by email From: Mauro Carvalho Chehab This script is capable to mass import patches on a mbox file, test for it, allow comment editing and applying it. This script requires: 1) git, since it uses gitimport to break a mbox into patches; 2) hg mailqueue. It is easier to manage patches using mq, allowing to work with the patches before applying to the tree. Signed-off-by: Mauro Carvalho Chehab --- mailimport | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 mailimport (limited to 'mailimport') diff --git a/mailimport b/mailimport new file mode 100755 index 000000000..edbde0e06 --- /dev/null +++ b/mailimport @@ -0,0 +1,120 @@ +#!/bin/bash +# Copyright (c) 2006 Mauro Carvalho Chehab (mchehab@infradead.org) +# This code is placed under the terms of the GNU General Public License +# +#This script is capable to mass import patches on a mbox file, test for it, allow +#comment editing and applying it. +# +#This script requires: +#1) git, since it uses gitimport to break a mbox into patches; +#2) hg mailqueue. It is easier to manage patches using mq, allowing to work with +# the patches before applying to the tree. + +head=v4l/scripts/hghead.pl + +if [ "$1" == "" ]; then + echo "Usage: $0 " + exit +fi +MBOX=$1 + +if [ "$TMPDIR" == "" ]; then + TMPDIR=/tmp +fi + +DIR=$TMPDIR/mailimport$$ +mkdir $DIR +if [ "$?" != "0" ]; then + echo "*** Error at mkdir $DIR" + exit; +fi +trap "rm -rf $DIR" EXIT +TMP2=$DIR/patchheader + +apply_patch () { + next=$1 + + echo patch -s -t -p1 --dry-run -l -N -d linux -i $next + patch -s -t -p1 --dry-run -l -N -d linux -i $next + if [ "$?" != "0" ]; then + $head $next + echo "*** ERROR" + exit + fi + + nano $next + + unset cont + until [ "$cont" == "0" ]; do + cont=0 + $head $next >$TMP2 + + if [ "`grep 'Bad formed author' $TMP2`" != "" ]; then + echo Patch bad formed. Please fix. + sleep 1 + nano $next + cont=1 + fi + done + +# hg qnew doesn't support specifying a date +# date="`perl -ne '{ if ( s/^# Date: //) { print; } }' $TMP2`" +# echo "Patch date is $date" +# patch -s -t -p1 -l -N -d linux -i ../$next +# cd linux +# hg addremove `diffstat -p1 -l $next` +# cd .. + + name=`cat $next | perl -ne ' + if (s/Subject:\s+(.*)/$1/) { + m/\s*(.*)\s*\n/; + $_="$1"; + + tr/[A-Z]/[a-z]/; + s/[^a-z0-9]/_/g; + s/_+$//; + s/_+/_/g; + s/^v4l_dvb_\d+[a-z]*_//g; + + printf "%s.patch",$_; + exit; + }'` + + cat $next| grep -v "^#" >$TMPDIR/$name + + echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name + hg qnew -m "`cat $TMP2|grep -v "^#"`" $name + patch -s -t -p1 -l -N -d linux -i $next + hg qrefresh +} + +echo git-mailsplit $MBOX $DIR +echo -n "Number of patches at file: " +git-mailsplit $MBOX $DIR +echo + +for i in $DIR/*; do + cat $i| git-mailinfo $DIR/msg $DIR/patch>$DIR/author + cat $DIR/msg|grep -vi ^CC: >$DIR/msg2 + + cat $DIR/author|perl -ne "if (m/Author[:]\\s*(.*)\\n/) { \$auth=\$1; } else \ + { if (m/Email[:]\\s*(.*)\\n/) { print \"From: \$auth \<\$1\>\n\"; } else \ + { if (m/Subject[:]\\s*(.*)\\n/) { \ + \$sub=\$1; \ + \$sub=~ s;^(media|dvb|v4l|video|drivers|[-_/: \\t])*(.*);\$2;; \ + print \"Subject: \$sub\\n\"; \ + } else \ + { print; } } \ + }" >$DIR/author2 + + out=$DIR/patch.diff + + cat $DIR/author2 + + echo "Signed-off-by: $CHANGE_LOG_NAME <$CHANGE_LOG_EMAIL_ADDRESS>" >>$DIR/msg2 + + echo "cat $DIR/author2 $DIR/msg2 $DIR/patch >$out" + cat $DIR/author2 $DIR/msg2 $DIR/patch >$out + + apply_patch $out +done -- cgit v1.2.3 From 8c70d56c5138c6455c8e718e644ffab506adc081 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 9 Mar 2006 11:59:15 -0300 Subject: mailimport now accepts both kernel and v4l/dvb tree patches From: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- mailimport | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'mailimport') diff --git a/mailimport b/mailimport index edbde0e06..1f6c15668 100755 --- a/mailimport +++ b/mailimport @@ -33,13 +33,19 @@ TMP2=$DIR/patchheader apply_patch () { next=$1 + pdir=linux - echo patch -s -t -p1 --dry-run -l -N -d linux -i $next - patch -s -t -p1 --dry-run -l -N -d linux -i $next + echo patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + patch -s -t -p1 --dry-run -l -N -d $pdif -i $next if [ "$?" != "0" ]; then - $head $next - echo "*** ERROR" - exit + pdir=. + echo patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + if [ "$?" != "0" ]; then + $head $next + echo "*** ERROR" + exit + fi fi nano $next @@ -84,7 +90,7 @@ apply_patch () { echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name hg qnew -m "`cat $TMP2|grep -v "^#"`" $name - patch -s -t -p1 -l -N -d linux -i $next + patch -s -t -p1 -l -N -d $pdir -i $next hg qrefresh } -- cgit v1.2.3 From cca8bcd7f5e2af33e7d32fce1fc75a901e953290 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 9 Mar 2006 17:45:46 -0300 Subject: Clears whitespaces before refreshing the patch From: Mauro Carvalho Chehab This avoids introducing whitespaces by patches. Signed-off-by: Mauro Carvalho Chehab --- mailimport | 1 + 1 file changed, 1 insertion(+) (limited to 'mailimport') diff --git a/mailimport b/mailimport index 1f6c15668..ee8b0ac0c 100755 --- a/mailimport +++ b/mailimport @@ -91,6 +91,7 @@ apply_patch () { echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name hg qnew -m "`cat $TMP2|grep -v "^#"`" $name patch -s -t -p1 -l -N -d $pdir -i $next + make whitespace hg qrefresh } -- cgit v1.2.3 From b1d9bdd768643dbb593d8ba0d18a0dcd9be28a29 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 10 Mar 2006 14:03:11 -0300 Subject: Now, Mailimport tests also v4l/dvb patch structure From: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- mailimport | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'mailimport') diff --git a/mailimport b/mailimport index edbde0e06..6b3ff47cc 100755 --- a/mailimport +++ b/mailimport @@ -33,13 +33,19 @@ TMP2=$DIR/patchheader apply_patch () { next=$1 + pdir=linux - echo patch -s -t -p1 --dry-run -l -N -d linux -i $next - patch -s -t -p1 --dry-run -l -N -d linux -i $next + echo patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + patch -s -t -p1 --dry-run -l -N -d $pdir -i $next if [ "$?" != "0" ]; then - $head $next - echo "*** ERROR" - exit + pdir=. + echo patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + patch -s -t -p1 --dry-run -l -N -d $pdir -i $next + if [ "$?" != "0" ]; then + $head $next + echo "*** ERROR" + exit + fi fi nano $next @@ -84,7 +90,7 @@ apply_patch () { echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name hg qnew -m "`cat $TMP2|grep -v "^#"`" $name - patch -s -t -p1 -l -N -d linux -i $next + patch -s -t -p1 -l -N -d $pdir -i $next hg qrefresh } -- cgit v1.2.3 From 02474d0a0181592ab0ce78cc5b536b76d23a4799 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 10 Mar 2006 14:20:58 -0300 Subject: Added better handling for errors at mailscript From: Mauro Carvalho Chehab Now, it checks if author have signed its own patch. Also, prints better error messages. Signed-off-by: Mauro Carvalho Chehab --- mailimport | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mailimport') diff --git a/mailimport b/mailimport index 554ed7eed..08a9ac34f 100755 --- a/mailimport +++ b/mailimport @@ -43,7 +43,7 @@ apply_patch () { patch -s -t -p1 --dry-run -l -N -d $pdir -i $next if [ "$?" != "0" ]; then $head $next - echo "*** ERROR" + echo "*** ERROR: Patch didn't applied well" exit fi fi @@ -55,8 +55,8 @@ apply_patch () { cont=0 $head $next >$TMP2 - if [ "`grep 'Bad formed author' $TMP2`" != "" ]; then - echo Patch bad formed. Please fix. + if [ "`grep '^Bad:' $TMP2`" != "" ]; then + echo "*** ERROR: Patch bad formed. Please fix." sleep 1 nano $next cont=1 -- cgit v1.2.3 From 7b1dd4f2f9eabe19369f76fa871d6978eba4c79d Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 10 Mar 2006 14:29:11 -0300 Subject: Allows go ahead when a patch is not appling From: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- mailimport | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mailimport') diff --git a/mailimport b/mailimport index 08a9ac34f..f1a64af35 100755 --- a/mailimport +++ b/mailimport @@ -10,6 +10,7 @@ #2) hg mailqueue. It is easier to manage patches using mq, allowing to work with # the patches before applying to the tree. +#exitonerror=1 head=v4l/scripts/hghead.pl if [ "$1" == "" ]; then @@ -44,7 +45,11 @@ apply_patch () { if [ "$?" != "0" ]; then $head $next echo "*** ERROR: Patch didn't applied well" - exit + if [ "$exitonerror" != "" ]; then + exit + else + return + fi fi fi -- cgit v1.2.3 From 1254c4a78ff6728e02609f72002c87783b1a610e Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 10 Mar 2006 15:20:59 -0300 Subject: Some fixes and improvements at mailimport From: Mauro Carvalho Chehab hg mq were offering some troubles, because it seems to be also updated at master site. So, now, default is not to use it. Several validations added. Also improved output log by separating subject from from: line. Signed-off-by: Mauro Carvalho Chehab --- mailimport | 80 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'mailimport') diff --git a/mailimport b/mailimport index f1a64af35..b563eecd9 100755 --- a/mailimport +++ b/mailimport @@ -10,7 +10,12 @@ #2) hg mailqueue. It is easier to manage patches using mq, allowing to work with # the patches before applying to the tree. +#uncomment to use mq +#usemq=1 + +#uncomment to stop at the first error while testing a patch with --dry-run #exitonerror=1 + head=v4l/scripts/hghead.pl if [ "$1" == "" ]; then @@ -68,36 +73,53 @@ apply_patch () { fi done -# hg qnew doesn't support specifying a date -# date="`perl -ne '{ if ( s/^# Date: //) { print; } }' $TMP2`" -# echo "Patch date is $date" -# patch -s -t -p1 -l -N -d linux -i ../$next -# cd linux -# hg addremove `diffstat -p1 -l $next` -# cd .. - - name=`cat $next | perl -ne ' - if (s/Subject:\s+(.*)/$1/) { - m/\s*(.*)\s*\n/; - $_="$1"; - - tr/[A-Z]/[a-z]/; - s/[^a-z0-9]/_/g; - s/_+$//; - s/_+/_/g; - s/^v4l_dvb_\d+[a-z]*_//g; - - printf "%s.patch",$_; - exit; - }'` - - cat $next| grep -v "^#" >$TMPDIR/$name - - echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name - hg qnew -m "`cat $TMP2|grep -v "^#"`" $name - patch -s -t -p1 -l -N -d $pdir -i $next make whitespace - hg qrefresh + + committer=`grep "Committer:" $TMP2|sed s/"#Committer: "//` + + if [ "$usemq" != "" ]; then + name=`cat $next | perl -ne ' + if (s/Subject:\s+(.*)/$1/) { + m/\s*(.*)\s*\n/; + $_="$1"; + + tr/[A-Z]/[a-z]/; + s/[^a-z0-9]/_/g; + s/_+$//; + s/_+/_/g; + s/^v4l_dvb_\d+[a-z]*_//g; + + printf "%s.patch",$_; + exit; + }'` + + cat $next| grep -v "^#" >$TMPDIR/$name + + echo hg -m "`cat $TMP2|grep -v "^#"`" qnew $name + hg qnew -m "`cat $TMP2|grep -v "^#"`" $name + hg qrefresh + else + patch -s -t -p1 -l -N -d $pdir -i $next + if [ "$?" != "0" ]; then + echo "*** ERROR at: patch -s -t -p1 -l -N -d $pdir -i $next" + exit + fi + cur=`pwd` + cd $pdir + hg addremove `diffstat -p1 -l $next` + if [ "$?" != "0" ]; then + echo "*** ERROR at hg addremove" + exit + fi + # Commit the changed files + hg commit -u "$committer" -m "`cat $TMP2|grep -v "^#"`" `diffstat -p1 -l $next` + if [ "$?" != "0" ]; then + echo "*** ERROR at hg commit" + cd $cur + exit + fi + cd $cur + fi } echo git-mailsplit $MBOX $DIR -- cgit v1.2.3