--- /dev/null
+Return-Path: <jani@nikula.org>\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 B2697431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 9 Oct 2013 00:18:32 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 K0+fiH6TNxx7 for <notmuch@notmuchmail.org>;\r
+ Wed, 9 Oct 2013 00:18:26 -0700 (PDT)\r
+Received: from mail-ea0-f177.google.com (mail-ea0-f177.google.com\r
+ [209.85.215.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 561A6431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 9 Oct 2013 00:18:26 -0700 (PDT)\r
+Received: by mail-ea0-f177.google.com with SMTP id f15so169830eak.8\r
+ for <notmuch@notmuchmail.org>; Wed, 09 Oct 2013 00:18:23 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=4g+JpanAUiJWXCSMx/gDQYyGsUSocD7Fis+IhjYPD8Q=;\r
+ b=TpGFRxiL5OZ1BWZZZ6Sm1hjf+X6uz3ZcalUXD77DPXgT1sV0bn7RivD61b4h6thwWU\r
+ L/mHqVxY9s0GDjMQYnqZbT51fzr1m0zG98mIeiY1EhZhQsG+HsOjr5k8eJVt1SJ0oR75\r
+ bxBqnwTC2s8R2cOxUTNmhKUZcDqQz+PQICfQzqLehBphXM9ujP8hxMbuzHP6QSXXzB4f\r
+ jy9NkLzYnjZ9FSvXCJ7ZhqrfA/gaFNfLlET1KkGh5rmLxRHMQjpjwwCjXGT32cUjwrYM\r
+ bTmGz05VE6X0Jv/jWt/1TSL9BDtjkcBnCgsbRT4yRgMKy0oY8yuRdRSuYidx64ryX5ew\r
+ d1Iw==\r
+X-Gm-Message-State:\r
+ ALoCoQn89ARCUMmpEfYvAbUDl6SqNYiRxogPYe3LA3C8w7Hl+eW5AceyHEgvyIx7YvGB7pMPDioJ\r
+X-Received: by 10.15.32.136 with SMTP id a8mr631431eev.71.1381303103805;\r
+ Wed, 09 Oct 2013 00:18:23 -0700 (PDT)\r
+Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
+ by mx.google.com with ESMTPSA id\r
+ x47sm85326121eea.16.1969.12.31.16.00.00\r
+ (version=TLSv1.1 cipher=RC4-SHA bits=128/128);\r
+ Wed, 09 Oct 2013 00:18:22 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag\r
+ queries\r
+In-Reply-To: <1381185201-25197-8-git-send-email-amdragon@mit.edu>\r
+References: <1381185201-25197-1-git-send-email-amdragon@mit.edu>\r
+ <1381185201-25197-8-git-send-email-amdragon@mit.edu>\r
+User-Agent: Notmuch/0.16+62~g9f2ae2e (http://notmuchmail.org) Emacs/23.2.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Wed, 09 Oct 2013 09:18:11 +0200\r
+Message-ID: <87iox6ap58.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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, 09 Oct 2013 07:18:32 -0000\r
+\r
+On Tue, 08 Oct 2013, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> (Unfortunately, it's difficult to first demonstrate this problem with\r
+> a known-broken test because modern Linux kernels have argument length\r
+> limits in the megabytes, which makes Emacs really slow!)\r
+> ---\r
+> emacs/notmuch-lib.el | 8 ++++++++\r
+> emacs/notmuch-tag.el | 12 ++++++++++--\r
+> test/emacs | 8 ++++++++\r
+> 3 files changed, 26 insertions(+), 2 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+> index 22156f1..348112b 100644\r
+> --- a/emacs/notmuch-lib.el\r
+> +++ b/emacs/notmuch-lib.el\r
+> @@ -261,6 +261,14 @@ user-friendly queries."\r
+> "Return a query that matches the message with id ID."\r
+> (concat "id:" (notmuch-escape-boolean-term id)))\r
+> \r
+> +(defun notmuch-hex-encode (str)\r
+> + "Hex-encode STR (e.g., as used by batch tagging).\r
+> +\r
+> +This replaces spaces, percents, and double quotes in STR with\r
+> +%NN where NN is the hexadecimal value of the character."\r
+> + (replace-regexp-in-string\r
+> + "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str))\r
+> +\r
+> ;;\r
+> \r
+> (defun notmuch-common-do-stash (text)\r
+> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
+> index 064cfa8..a4eec14 100644\r
+> --- a/emacs/notmuch-tag.el\r
+> +++ b/emacs/notmuch-tag.el\r
+> @@ -242,6 +242,8 @@ from TAGS if present."\r
+> (error "Changed tag must be of the form `+this_tag' or `-that_tag'")))))\r
+> (sort result-tags 'string<)))\r
+> \r
+> +(defconst notmuch-tag-argument-limit 1000)\r
+> +\r
+> (defun notmuch-tag (query &optional tag-changes)\r
+> "Add/remove tags in TAG-CHANGES to messages matching QUERY.\r
+> \r
+> @@ -268,8 +270,14 @@ notmuch-after-tag-hook will be run."\r
+> tag-changes)\r
+> (unless (null tag-changes)\r
+> (run-hooks 'notmuch-before-tag-hook)\r
+> - (apply 'notmuch-call-notmuch-process "tag"\r
+> - (append tag-changes (list "--" query)))\r
+> + (if (<= (length query) notmuch-tag-argument-limit)\r
+> + (apply 'notmuch-call-notmuch-process "tag"\r
+> + (append tag-changes (list "--" query)))\r
+> + ;; Use batch tag mode to avoid argument length limitations\r
+> + (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ")\r
+> + " -- " query)))\r
+> + (message "Batch tagging with %s" batch-op)\r
+\r
+Why the message?\r
+\r
+Jani.\r
+\r
+> + (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch")))\r
+> (run-hooks 'notmuch-after-tag-hook))\r
+> ;; in all cases we return tag-changes as a list\r
+> tag-changes)\r
+> diff --git a/test/emacs b/test/emacs\r
+> index 05295af..2917189 100755\r
+> --- a/test/emacs\r
+> +++ b/test/emacs\r
+> @@ -122,6 +122,14 @@ test_emacs "(notmuch-search \"$os_x_darwin_thread\")\r
+> output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)\r
+> test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"\r
+> \r
+> +test_begin_subtest "Add tag (large query)"\r
+> +# We use a long query to force us into batch mode and use a funny tag\r
+> +# that requires escaping for batch tagging.\r
+> +test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (make-string notmuch-tag-argument-limit ?x)) \"+tag-from-%-large-query\")"\r
+> +output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)\r
+> +test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-%-large-query unread)"\r
+> +notmuch tag -tag-from-%-large-query $os_x_darwin_thread\r
+> +\r
+> test_begin_subtest "notmuch-show: add single tag to single message"\r
+> test_emacs "(notmuch-show \"$os_x_darwin_thread\")\r
+> (execute-kbd-macro \"+tag-from-show-view\")"\r
+> -- \r
+> 1.8.4.rc3\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r