[aiaiai] email-lda: use git-apply to more accurately find patch emails

Jacob Keller jacob.e.keller at intel.com
Wed Aug 26 03:50:44 PDT 2015


Instead of using the subject as the sole arbiter of whether an email
contains a patch, reject all emails which cannot be recognized by
git-apply. In this way, we can locate even patches with non-standard
subject lines. Use the subject line to differentiate between patch
series and individual patches when possible.

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
---
 email/aiaiai-email-lda          | 26 ++++++++++++++++----------
 email/aiaiai-email-sh-functions | 11 +++++++++++
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/email/aiaiai-email-lda b/email/aiaiai-email-lda
index 4927dd194b2a..657bd2c482f3 100755
--- a/email/aiaiai-email-lda
+++ b/email/aiaiai-email-lda
@@ -348,13 +348,12 @@ separator()
 	fi
 }
 
-# Process one e-mail. This e-mail may be part of a patch-set, or an individual
-# patch, or not a patch at all. The patches and non-patches are distinguished
-# using the subject (see the 'subject_check()' function). Non-patches are
-# dropped. Individual patches are queued right away. Patch-sets are stored in
-# a temporary directory and queued only when all the of them are collected.
-#
-# The e-mail to process is passed in "$1" in form of a path to the mbox file.
+# Proccess one e-mail. This e-mail may be part of a patch-set, may contain an
+# individual patch, or may not contain a patch at all. The patches and
+# non-patches are distinguished using is_email_patch() which is based on "git
+# apply --stat". Patch-set emails are distinquished from patches via use of the
+# subject line. Individual patches are queued right away. Patch-sets are stored
+# in a temporary location and queued when the entire patch set is collected.
 process_mbox()
 {
 	local mbox="$1";
@@ -379,9 +378,16 @@ process_mbox()
 	verbose "            Subject: $subj"
 	verbose "            Message-Id: $id"
 
-	# Filter out e-mails which do not start with the right prefix"
-	subject_check "$subj" ||
-		{ reject "$mbox" "\"$prefix_format\" prefix not found"; return; }
+	# Filter out e-mails which do not contain a patch
+	email_contains_patch "$mbox" ||
+		{ reject "$mbox" "mbox does not contain a patch"; return; }
+
+	# Queue patches which don't match subject format immediately
+	if ! subject_check "$subj" ; then
+		verbose "Queuing stand-alone patch with unrecognized subject format \"$subj\""
+		queue_mboxfile "$mbox" ""
+		return
+	fi
 
 	# If the patch prefix contains m/n, fetch m and n.
 	local m="$(subject_m "$subj")"
diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions
index cb0feed23a41..b4c6763a7782 100644
--- a/email/aiaiai-email-sh-functions
+++ b/email/aiaiai-email-sh-functions
@@ -60,6 +60,17 @@ subject_check()
 	[ -n "$(printf "%s" "$1" | LC_ALL=C sed -n -E "/$__single/ p")" ]
 }
 
+# Check that an mbox will be recognized by git-apply
+# Usage: email_contains_patch <mbox>
+#
+# Based on return code from "git apply --stat". This command will print
+# diffstat information about the patch, and will fail with exit code 128 if the
+# file can't be recognized as a patch.
+email_contains_patch()
+{
+	git apply --stat "$1" >/dev/null
+}
+
 # Strip an e-mail address from the comma-separated list of e-mail addresses
 # Usage: strip_address <list> <email>
 strip_address()
-- 
2.5.0.280.g4aaba03




More information about the aiaiai mailing list