--- /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 059E840B964\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Feb 2013 17:40:34 -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 k3uCdQE9nvVY for <notmuch@notmuchmail.org>;\r
+ Fri, 8 Feb 2013 17:40:33 -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 7A1B040B961\r
+ for <notmuch@notmuchmail.org>; Fri, 8 Feb 2013 17:40:33 -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 1U3zQa-0005pA-90; Fri, 08 Feb 2013 21:40:30 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1U3zQU-0005Tq-JK; Fri, 08 Feb 2013 21:40:22 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] contrib/nmbug: convert to use batch tagging.\r
+Date: Fri, 8 Feb 2013 21:40:19 -0400\r
+Message-Id: <1360374019-20988-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\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: Sat, 09 Feb 2013 01:40:34 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+In the case of large changes to the database from git, one of main\r
+current bottlenecks is the large number of execs of notmuch tag. This\r
+avoids that by using use the batch tagging facilities as of notmuch\r
+0.15.\r
+\r
+We use "spawn" directly rather than inventing a "notmuch_pipe", since\r
+it seems the only place we need to pipe to notmuch so far.\r
+---\r
+\r
+This is only lightly tested; please make sure you have backups of your\r
+database.\r
+\r
+I'm not 100% sure about the indentation. No doubt Tomi will let me\r
+know if it can be improved.\r
+\r
+ contrib/nmbug/nmbug | 15 ++++++++++-----\r
+ 1 file changed, 10 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/contrib/nmbug/nmbug b/contrib/nmbug/nmbug\r
+index f003ef9..c66c526 100755\r
+--- a/contrib/nmbug/nmbug\r
++++ b/contrib/nmbug/nmbug\r
+@@ -270,17 +270,22 @@ 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 $A_action.$TAGPREFIX.$pair->{tag}, " -- ",\r
++ 'id:'.$pair->{id};\r
+ }\r
+ \r
+ foreach my $pair (@{$status->{deleted}}) {\r
+- notmuch ('tag', $D_action.$TAGPREFIX.$pair->{tag},\r
+- 'id:'.$pair->{id});\r
++ print $notmuch $D_action.$TAGPREFIX.$pair->{tag},\r
++ 'id:'.$pair->{id};\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