1 Return-Path: <amdragon@mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1A3EE431FAE
\r
6 for <notmuch@notmuchmail.org>; Mon, 7 Oct 2013 15:33:43 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id tXKnVsMWEPcU for <notmuch@notmuchmail.org>;
\r
16 Mon, 7 Oct 2013 15:33:38 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu
\r
19 by olra.theworths.org (Postfix) with ESMTP id 8FCF4431FBF
\r
20 for <notmuch@notmuchmail.org>; Mon, 7 Oct 2013 15:33:30 -0700 (PDT)
\r
21 X-AuditID: 1209190e-b7f828e0000009cf-7c-525336b9adcc
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id AE.6E.02511.9B633525; Mon, 7 Oct 2013 18:33:29 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id r97MXPjm008283;
\r
27 Mon, 7 Oct 2013 18:33:26 -0400
\r
28 Received: from drake.dyndns.org (26-4-172.dynamic.csail.mit.edu [18.26.4.172])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r97MXNU8028511
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Mon, 7 Oct 2013 18:33:25 -0400
\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1VTJMh-0006by-Mg; Mon, 07 Oct 2013 18:33:23 -0400
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries
\r
40 Date: Mon, 7 Oct 2013 18:33:17 -0400
\r
41 Message-Id: <1381185201-25197-8-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.8.4.rc3
\r
43 In-Reply-To: <1381185201-25197-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1381185201-25197-1-git-send-email-amdragon@mit.edu>
\r
45 X-Brightmail-Tracker:
\r
46 H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrLvTLDjI4O4KfovrN2cyOzB6PFt1
\r
47 izmAMYrLJiU1J7MstUjfLoErY+mn3awFT6Qr7l1KbmDsE+9i5OSQEDCRWNB9nQnCFpO4cG89
\r
48 WxcjF4eQwD5GiZOzWplBEkICGxglZr5KgEgcZpL4e+wlE4Qzl1Hi+JdfrCBVbAIaEtv2L2cE
\r
49 sUUEpCV23p0NFOfgYBZQk/jTpQISFhbwllj9uZsFxGYRUJVo3feNDcTmFXCQWLP6LCvEFUoS
\r
50 C09tA7M5BRwllmy8yAZxhIPE3P2LWCcw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6yX
\r
51 m1mil5pSuokRHDKSfDsYvx5UOsQowMGoxMMrcDgoSIg1say4MvcQoyQHk5Io7xnT4CAhvqT8
\r
52 lMqMxOKM+KLSnNTiQ4wSHMxKIrwCRkA53pTEyqrUonyYlDQHi5I4700O+yAhgfTEktTs1NSC
\r
53 1CKYrAwHh5IEbxjIUMGi1PTUirTMnBKENBMHJ8hwHqDhYmYgw4sLEnOLM9Mh8qcYFaXEeRVA
\r
54 EgIgiYzSPLheWEy/YhQHekWY9zPICh5gOoDrfgU0mAlosC57IMjgkkSElFQDo6Jv+pWlEWem
\r
55 Zv/k1Iq7fCQjUGlJWVKliLZdou3R83z5a46u60i9qL+FwVqwSXbi3bgyob8zDmyq+9a0eEvw
\r
56 r07NlgV1iwKfmm0t4ZDSWOuzJFR0yeddGRy7TDf13FUyYRJ+v/jw9uj4M8w/zetLd01hLlDU
\r
57 jczcLxC12GBZ/qIFbvnxVb51SizFGYmGWsxFxYkAz7oh08QCAAA=
\r
58 X-BeenThere: notmuch@notmuchmail.org
\r
59 X-Mailman-Version: 2.1.13
\r
61 List-Id: "Use and development of the notmuch mail system."
\r
62 <notmuch.notmuchmail.org>
\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
66 List-Post: <mailto:notmuch@notmuchmail.org>
\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
70 X-List-Received-Date: Mon, 07 Oct 2013 22:33:43 -0000
\r
72 (Unfortunately, it's difficult to first demonstrate this problem with
\r
73 a known-broken test because modern Linux kernels have argument length
\r
74 limits in the megabytes, which makes Emacs really slow!)
\r
76 emacs/notmuch-lib.el | 8 ++++++++
\r
77 emacs/notmuch-tag.el | 12 ++++++++++--
\r
78 test/emacs | 8 ++++++++
\r
79 3 files changed, 26 insertions(+), 2 deletions(-)
\r
81 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
82 index 22156f1..348112b 100644
\r
83 --- a/emacs/notmuch-lib.el
\r
84 +++ b/emacs/notmuch-lib.el
\r
85 @@ -261,6 +261,14 @@ user-friendly queries."
\r
86 "Return a query that matches the message with id ID."
\r
87 (concat "id:" (notmuch-escape-boolean-term id)))
\r
89 +(defun notmuch-hex-encode (str)
\r
90 + "Hex-encode STR (e.g., as used by batch tagging).
\r
92 +This replaces spaces, percents, and double quotes in STR with
\r
93 +%NN where NN is the hexadecimal value of the character."
\r
94 + (replace-regexp-in-string
\r
95 + "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str))
\r
99 (defun notmuch-common-do-stash (text)
\r
100 diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
\r
101 index 064cfa8..a4eec14 100644
\r
102 --- a/emacs/notmuch-tag.el
\r
103 +++ b/emacs/notmuch-tag.el
\r
104 @@ -242,6 +242,8 @@ from TAGS if present."
\r
105 (error "Changed tag must be of the form `+this_tag' or `-that_tag'")))))
\r
106 (sort result-tags 'string<)))
\r
108 +(defconst notmuch-tag-argument-limit 1000)
\r
110 (defun notmuch-tag (query &optional tag-changes)
\r
111 "Add/remove tags in TAG-CHANGES to messages matching QUERY.
\r
113 @@ -268,8 +270,14 @@ notmuch-after-tag-hook will be run."
\r
115 (unless (null tag-changes)
\r
116 (run-hooks 'notmuch-before-tag-hook)
\r
117 - (apply 'notmuch-call-notmuch-process "tag"
\r
118 - (append tag-changes (list "--" query)))
\r
119 + (if (<= (length query) notmuch-tag-argument-limit)
\r
120 + (apply 'notmuch-call-notmuch-process "tag"
\r
121 + (append tag-changes (list "--" query)))
\r
122 + ;; Use batch tag mode to avoid argument length limitations
\r
123 + (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ")
\r
125 + (message "Batch tagging with %s" batch-op)
\r
126 + (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch")))
\r
127 (run-hooks 'notmuch-after-tag-hook))
\r
128 ;; in all cases we return tag-changes as a list
\r
130 diff --git a/test/emacs b/test/emacs
\r
131 index 05295af..2917189 100755
\r
134 @@ -122,6 +122,14 @@ test_emacs "(notmuch-search \"$os_x_darwin_thread\")
\r
135 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
\r
136 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
138 +test_begin_subtest "Add tag (large query)"
\r
139 +# We use a long query to force us into batch mode and use a funny tag
\r
140 +# that requires escaping for batch tagging.
\r
141 +test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (make-string notmuch-tag-argument-limit ?x)) \"+tag-from-%-large-query\")"
\r
142 +output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
\r
143 +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
144 +notmuch tag -tag-from-%-large-query $os_x_darwin_thread
\r
146 test_begin_subtest "notmuch-show: add single tag to single message"
\r
147 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
\r
148 (execute-kbd-macro \"+tag-from-show-view\")"
\r