[aiaiai PATCH v3 09/12] email-test-patchset: automatically obtain a base commit to test against

Artem Bityutskiy artem.bityutskiy at linux.intel.com
Fri Feb 7 02:36:04 PST 2014

From: Jacob Keller <jacob.e.keller at intel.com>

In our environment, a queue of patches is used. Often, developers will
submit a v2 of a patch already in the queue before the maintainer can
"pop" this patch off the queue. This function setup here enables
determining if a patch with the same canonical subject is already
applied to the tree. A special parameter "base" is used to prevent going
back before the "published" upstream branch of the tree.

This enables aiaiai to be smart enough to figure out when a patch should
be tested against the tip of queue, or against the parent of a previous
version. This relies on new patch versions having identical canonical
subject lines, though. (Equivalent except for the [... PATCH ...]

Signed-off-by: Jacob Keller <jacob.e.keller at intel.com>
 email/aiaiai-email-sh-functions  |    1 +
 email/aiaiai-email-test-patchset |   43 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/email/aiaiai-email-sh-functions b/email/aiaiai-email-sh-functions
index 48f61e6..9fa9eaf 100644
--- a/email/aiaiai-email-sh-functions
+++ b/email/aiaiai-email-sh-functions
@@ -183,6 +183,7 @@ parse_prj_config()
 	cfg_unwanted_keywords="$(ini_config_get "$cfgfile" ""prj_$prj"" "unwanted_keywords")"
 	cfg_checkpatch="$(ini_config_get "$cfgfile" "prj_$prj" "checkpatch")"
 	cfg_make_options="$(ini_config_get "$cfgfile" "prj_$prj" "make_options")"
+	cfg_branch_base="$(ini_config_get "$cfgfile" "prj_$prj" "base")"
 # Compose (but not send) e-mail reply. This function assumes that the following
diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset
index 94b50cb..0ca9f05 100755
--- a/email/aiaiai-email-test-patchset
+++ b/email/aiaiai-email-test-patchset
@@ -258,10 +258,51 @@ has been scheduled for testing.
+# Find the most recent commit which the patch series will apply on top of. The
+# assumption is that a new spin of a patch already in the queue will have an
+# identical subject. Otherwise this check fails. The process for determining
+# this is outlined here
+# 1. Obtain the subject (patch title) using git-mailinfo
+# 2. create --grep options for git log
+# 3. Use git log on the master git dir using the base and branch to limit scope
+# 4. Take the oldest commit which shows up, using tail -1
+# 5. Append a "^" so git uses this commit's parent
+# 6. Fall back to using the branch name if this fails
+while read -r subject; do
+	greplog+=" --grep=\"$subject\""
+done <<< "$(cat "$mbox" | formail -s git mailinfo /dev/null /dev/null | sed -n 's/^Subject: //p')"
+if [[ -n $greplog ]]; then
+	#
+	# We have to use a nasty eval here because otherwise bash eats the
+	# quotes around git-dir and pretty. In addition, bash also "protects"
+	# the quotes in the greplog array by puting '' around non-whitespace
+	# segments which contain a ". However, this royally screws up git,
+	# which does not want those single quotes at all. The fix is to create
+	# the string and \quote the double-quotes and then use eval to process
+	# the command. It is ugly, but it works.
+	#
+	commit=$(eval "git --git-dir=\"$(git_dir "$cfg_path")\" log --pretty=\"format:%H\" -F ${greplog[@]} ${cfg_branch_base:+$cfg_branch_base..}$cfg_branch | tail -1")
+if [[ -z $commit ]]; then
+	commit=$cfg_branch
+	verbose "Found patch with same subject already on queue:"
+	verbose "$(git --git-dir="$(git_dir "$cfg_path")" log -1 --pretty='%h ("%s")' $commit)"
+	# We need to cleanup the '^' using git-rev-parse
+	commit="$(git --git-dir="$(git_dir "$cfg_path")" rev-parse "$commit^")"
 # Test the path (or patch-set)
 message "Test configs \"$cfg_configs\" branch \"$cfg_branch\" of \"$cfg_path\""
 aiaiai-test-patchset $verbose $preserve $bisectability $sparse $smatch $cppcheck $coccinelle \
-	-i "$mbox" -j "$cfg_jobs" -c "$cfg_branch" -w "$tmpdir" \
+	-i "$mbox" -j "$cfg_jobs" -c "$commit" -w "$tmpdir" \
 	${confdir:+-C "$confdir"} \
 	${cfg_unwanted_keywords:+-K "$cfg_unwanted_keywords"} \
 	${cfg_make_options:+-M "$cfg_make_options"} \

Best Regards,
Artem Bityutskiy

More information about the aiaiai mailing list