--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id B950A431FC0\r
+ for <notmuch@notmuchmail.org>; Wed, 20 Feb 2013 14:24:54 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id N8JYgTnVVb0v for <notmuch@notmuchmail.org>;\r
+ Wed, 20 Feb 2013 14:24:54 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+ (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 05862431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 20 Feb 2013 14:24:53 -0800 (PST)\r
+Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+ ([156.34.82.78] helo=zancas.localnet)\r
+ by tesseract.cs.unb.ca with esmtpsa\r
+ (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1U8I5r-00086T-0j; Wed, 20 Feb 2013 18:24:51 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1U8I5l-00028H-AF; Wed, 20 Feb 2013 18:24:45 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 2/4] nmbug: use 'notmuch tag --batch'\r
+Date: Wed, 20 Feb 2013 18:24:35 -0400\r
+Message-Id: <1361399077-7737-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1361399077-7737-1-git-send-email-david@tethera.net>\r
+References: <1361399077-7737-1-git-send-email-david@tethera.net>\r
+X-Spam_bar: -\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 20 Feb 2013 22:24:55 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+This should be more robust with respect to tags with whitespace and\r
+and other special characters. It also (hopefully) fixes a remaining\r
+bug handling message-ids with whitespace. It should also be\r
+noticeably faster for large sets of changes since it does one exec per\r
+change set as opposed to one exec per tag changed.\r
+---\r
+ devel/nmbug/nmbug | 27 ++++++++++++++++++++++-----\r
+ 1 file changed, 22 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug\r
+index befc3d9..73d64fe 100755\r
+--- a/devel/nmbug/nmbug\r
++++ b/devel/nmbug/nmbug\r
+@@ -267,6 +267,20 @@ sub do_checkout {\r
+ do_sync (action => 'checkout');\r
+ }\r
+ \r
++sub quote_for_xapian {\r
++ my $str = shift;\r
++ $str =~ s/"/""/g;\r
++ return '"' . $str . '"';\r
++}\r
++\r
++sub pair_to_batch_line {\r
++ my ($action, $pair) = @_;\r
++\r
++ # the tag should already be suitably encoded\r
++\r
++ return $action . $ENCPREFIX . $pair->{tag} .\r
++ ' -- id:' . quote_for_xapian ($pair->{id})."\n";\r
++}\r
+ \r
+ sub do_sync {\r
+ \r
+@@ -283,17 +297,20 @@ sub do_sync {\r
+ $D_action = '-';\r
+ }\r
+ \r
+- foreach my $pair (@{$status->{added}}) {\r
++ my $notmuch = spawn ({}, '|-', qw/notmuch tag --batch/)\r
++ or die 'notmuch tag --batch';\r
+ \r
+- notmuch ('tag', $A_action.$TAGPREFIX.$pair->{tag},\r
+- 'id:'.$pair->{id});\r
++ foreach my $pair (@{$status->{added}}) {\r
++ print $notmuch pair_to_batch_line ($A_action, $pair);\r
+ }\r
+ \r
+ foreach my $pair (@{$status->{deleted}}) {\r
+- notmuch ('tag', $D_action.$TAGPREFIX.$pair->{tag},\r
+- 'id:'.$pair->{id});\r
++ print $notmuch pair_to_batch_line ($D_action, $pair);\r
+ }\r
+ \r
++ unless (close $notmuch) {\r
++ die "'notmuch tag --batch' exited with nonzero value\n";\r
++ }\r
+ }\r
+ \r
+ \r
+-- \r
+1.7.10.4\r
+\r