From: Austin Clements Date: Mon, 7 Oct 2013 22:33:17 +0000 (+2000) Subject: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8a01c8ee84603cab39f96175ecbf4d79a9691850;p=notmuch-archives.git [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries --- diff --git a/bc/edaa04cf8c3d2c4e7f808f493523085bc57e0c b/bc/edaa04cf8c3d2c4e7f808f493523085bc57e0c new file mode 100644 index 000000000..e1d3c0ab2 --- /dev/null +++ b/bc/edaa04cf8c3d2c4e7f808f493523085bc57e0c @@ -0,0 +1,151 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1A3EE431FAE + for ; Mon, 7 Oct 2013 15:33:43 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id tXKnVsMWEPcU for ; + Mon, 7 Oct 2013 15:33:38 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id 8FCF4431FBF + for ; Mon, 7 Oct 2013 15:33:30 -0700 (PDT) +X-AuditID: 1209190e-b7f828e0000009cf-7c-525336b9adcc +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id AE.6E.02511.9B633525; Mon, 7 Oct 2013 18:33:29 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r97MXPjm008283; + Mon, 7 Oct 2013 18:33:26 -0400 +Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r97MXNU8028511 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Mon, 7 Oct 2013 18:33:25 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1VTJMh-0006by-Mg; Mon, 07 Oct 2013 18:33:23 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries +Date: Mon, 7 Oct 2013 18:33:17 -0400 +Message-Id: <1381185201-25197-8-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.8.4.rc3 +In-Reply-To: <1381185201-25197-1-git-send-email-amdragon@mit.edu> +References: <1381185201-25197-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrLvTLDjI4O4KfovrN2cyOzB6PFt1 + izmAMYrLJiU1J7MstUjfLoErY+mn3awFT6Qr7l1KbmDsE+9i5OSQEDCRWNB9nQnCFpO4cG89 + WxcjF4eQwD5GiZOzWplBEkICGxglZr5KgEgcZpL4e+wlE4Qzl1Hi+JdfrCBVbAIaEtv2L2cE + sUUEpCV23p0NFOfgYBZQk/jTpQISFhbwllj9uZsFxGYRUJVo3feNDcTmFXCQWLP6LCvEFUoS + C09tA7M5BRwllmy8yAZxhIPE3P2LWCcw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6yX + m1mil5pSuokRHDKSfDsYvx5UOsQowMGoxMMrcDgoSIg1say4MvcQoyQHk5Io7xnT4CAhvqT8 + lMqMxOKM+KLSnNTiQ4wSHMxKIrwCRkA53pTEyqrUonyYlDQHi5I4700O+yAhgfTEktTs1NSC + 1CKYrAwHh5IEbxjIUMGi1PTUirTMnBKENBMHJ8hwHqDhYmYgw4sLEnOLM9Mh8qcYFaXEeRVA + EgIgiYzSPLheWEy/YhQHekWY9zPICh5gOoDrfgU0mAlosC57IMjgkkSElFQDo6Jv+pWlEWem + Zv/k1Iq7fCQjUGlJWVKliLZdou3R83z5a46u60i9qL+FwVqwSXbi3bgyob8zDmyq+9a0eEvw + r07NlgV1iwKfmm0t4ZDSWOuzJFR0yeddGRy7TDf13FUyYRJ+v/jw9uj4M8w/zetLd01hLlDU + jczcLxC12GBZ/qIFbvnxVb51SizFGYmGWsxFxYkAz7oh08QCAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 07 Oct 2013 22:33:43 -0000 + +(Unfortunately, it's difficult to first demonstrate this problem with +a known-broken test because modern Linux kernels have argument length +limits in the megabytes, which makes Emacs really slow!) +--- + emacs/notmuch-lib.el | 8 ++++++++ + emacs/notmuch-tag.el | 12 ++++++++++-- + test/emacs | 8 ++++++++ + 3 files changed, 26 insertions(+), 2 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 22156f1..348112b 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -261,6 +261,14 @@ user-friendly queries." + "Return a query that matches the message with id ID." + (concat "id:" (notmuch-escape-boolean-term id))) + ++(defun notmuch-hex-encode (str) ++ "Hex-encode STR (e.g., as used by batch tagging). ++ ++This replaces spaces, percents, and double quotes in STR with ++%NN where NN is the hexadecimal value of the character." ++ (replace-regexp-in-string ++ "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str)) ++ + ;; + + (defun notmuch-common-do-stash (text) +diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el +index 064cfa8..a4eec14 100644 +--- a/emacs/notmuch-tag.el ++++ b/emacs/notmuch-tag.el +@@ -242,6 +242,8 @@ from TAGS if present." + (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))) + (sort result-tags 'string<))) + ++(defconst notmuch-tag-argument-limit 1000) ++ + (defun notmuch-tag (query &optional tag-changes) + "Add/remove tags in TAG-CHANGES to messages matching QUERY. + +@@ -268,8 +270,14 @@ notmuch-after-tag-hook will be run." + tag-changes) + (unless (null tag-changes) + (run-hooks 'notmuch-before-tag-hook) +- (apply 'notmuch-call-notmuch-process "tag" +- (append tag-changes (list "--" query))) ++ (if (<= (length query) notmuch-tag-argument-limit) ++ (apply 'notmuch-call-notmuch-process "tag" ++ (append tag-changes (list "--" query))) ++ ;; Use batch tag mode to avoid argument length limitations ++ (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ") ++ " -- " query))) ++ (message "Batch tagging with %s" batch-op) ++ (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch"))) + (run-hooks 'notmuch-after-tag-hook)) + ;; in all cases we return tag-changes as a list + tag-changes) +diff --git a/test/emacs b/test/emacs +index 05295af..2917189 100755 +--- a/test/emacs ++++ b/test/emacs +@@ -122,6 +122,14 @@ test_emacs "(notmuch-search \"$os_x_darwin_thread\") + output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) + 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)" + ++test_begin_subtest "Add tag (large query)" ++# We use a long query to force us into batch mode and use a funny tag ++# that requires escaping for batch tagging. ++test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (make-string notmuch-tag-argument-limit ?x)) \"+tag-from-%-large-query\")" ++output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) ++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)" ++notmuch tag -tag-from-%-large-query $os_x_darwin_thread ++ + test_begin_subtest "notmuch-show: add single tag to single message" + test_emacs "(notmuch-show \"$os_x_darwin_thread\") + (execute-kbd-macro \"+tag-from-show-view\")" +-- +1.8.4.rc3 +