summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmailimport120
-rwxr-xr-xv4l/scripts/hghead.pl143
2 files changed, 263 insertions, 0 deletions
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 <mbox>"
+ 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
diff --git a/v4l/scripts/hghead.pl b/v4l/scripts/hghead.pl
new file mode 100755
index 000000000..d0f657c08
--- /dev/null
+++ b/v4l/scripts/hghead.pl
@@ -0,0 +1,143 @@
+#!/usr/bin/perl
+use strict;
+use Date::Parse;
+
+#################################################################
+# analyse diffs
+
+my $in = shift;
+my $line;
+my $subject;
+my $from=0;
+my $sub_ok=0;
+my $init=0;
+my $num=0;
+my $maint_ok=0;
+my $noblank=1;
+my $maintainer_name=$ENV{CHANGE_LOG_NAME};
+my $maintainer_email=$ENV{CHANGE_LOG_EMAIL_ADDRESS};
+my $from="";
+my $body="";
+my $signed="";
+
+open IN, "<$in";
+
+while ($line = <IN>) {
+ if ($line =~ m/Index.*/) {
+ last;
+ }
+ if ($line =~ m/^diff .*/) {
+ last;
+ }
+ if ($line =~ m/^\-\-\- .*/) {
+ last;
+ }
+ if ($line =~ m/^\-\-\-.*/) {
+ last;
+ }
+ if ($line =~ m/^\+\+\+ .*/) {
+ last;
+ }
+
+ if ($line =~ m/^Date:\s*(.*)/) {
+ my $time = str2time($1);
+# my $timestr = gmtime($time);
+
+ if ($time) {
+ print "# Date: $time\n";
+ }
+ next;
+ }
+ if ($line =~ m/^From:/) {
+ if ($line =~ m/^From:[\s\"]*([^\"]*)[\s\"]*<(.*)>/) {
+ if ($1 eq "") {
+ next;
+ }
+ my $name=$1;
+ my $email=$2;
+ $name =~ s/\s+$//;
+ $email =~ s/\s+$//;
+ $from= "From: $name <$email>\n";
+ next;
+ }
+ print "Bad formed author\n";
+ die;
+ }
+
+ if ($line =~ m/^Subject:\s*(.*)\n/) {
+ $subject=$1;
+ next;
+ }
+
+ if ($line =~ m;^ .*\/.*\| *[0-9]*;) {
+ next;
+ }
+ if ($line =~m/\d+\s*file.* changed, /) {
+ next;
+ }
+
+ if ($line =~ m/^Signed-off-by:.*/) {
+ $noblank=1;
+ if ($line =~ m/$maintainer_name/) {
+ $maint_ok=1;
+ }
+
+ $signed="$signed$line";
+ next;
+ }
+ if ($line =~ m/^Acked-by:.*/) {
+ print $line;
+ next;
+ }
+
+ if ($line =~ m/^[a-zA-Z\-]*:/) {
+ if ($line =~ m/Changeset:\s*(.*)\n/) {
+ $num=$1;
+ }
+ print "# $line";
+ next;
+ }
+
+ if ($line =~ m|^(V4L\/DVB\s*\(.+\)\s*:.*)\n|) {
+ $subject=$1;
+ $line="\n";
+ }
+
+ if ($sub_ok == 0) {
+ $sub_ok=1;
+ substr( $subject, 0, 1 ) = uc (substr ($subject, 0, 1));
+ if ($subject =~ m|V4L\/DVB\s*(.+)|) {
+ print "$1\n\n";
+ } else {
+ print "$subject\n\n";
+ }
+ if ($line =~ m/^\n/) {
+ next;
+ }
+ }
+
+ if ($noblank) {
+ if ($line =~ m/^\n/) {
+ next;
+ }
+ }
+ if (!$init) {
+ $init=1;
+ $noblank=0;
+ }
+ $body="$body$line";
+}
+close IN;
+
+if ($from eq "") {
+ print "Bad formed author\n";
+ die;
+}
+if (!$maint_ok) {
+ $signed=$signed."Signed-off-by: $maintainer_name <$maintainer_email>\n";
+}
+$body=~s/\n+$//;
+$body=~s/^\n+$//;
+
+print "$from\n$body\n\n$signed";
+