]> www.infradead.org Git - users/dedekind/aiaiai.git/commitdiff
email-lda: use git-apply to more accurately find patch emails
authorJacob Keller <jacob.e.keller@intel.com>
Wed, 26 Aug 2015 01:00:06 +0000 (18:00 -0700)
committerJacob Keller <jacob.e.keller@intel.com>
Wed, 26 Aug 2015 20:33:00 +0000 (13:33 -0700)
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@intel.com>
email/aiaiai-email-lda
email/aiaiai-email-sh-functions

index 4927dd194b2a993b41c2e89df87fd422be1c1ca0..0ac9f0b4cd09c521f981175defaeeea109410b43 100755 (executable)
@@ -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,21 @@ 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
+       if ! email_contains_patch "$mbox" ; then
+               # Keep cover letter patches, but discard anything else
+               [ $(subject_m "$subj") = "0" ] ||
+                       { reject "$mbox" "mbox contains no patch and is not a cover letter"; return ; }
+       fi
+
+       # 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")"
index cb0feed23a412ab646f1e29cac66139cba1e64e0..b4c6763a7782b16e40fc83292f015d63288e8970 100644 (file)
@@ -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()