[PATCH 06/10] cli: Introduce "notmuch address" command
[notmuch-archives.git] / a4 / 65eb6ef81823baebb55a39d4943aaf9dc2d877
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 3D7B9431FDD\r
6         for <notmuch@notmuchmail.org>; Mon,  7 Oct 2013 15:33:47 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 X7UnGBxXchRP for <notmuch@notmuchmail.org>;\r
16         Mon,  7 Oct 2013 15:33:43 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
18         [18.7.68.35])\r
19         by olra.theworths.org (Postfix) with ESMTP id E6F3A431FC2\r
20         for <notmuch@notmuchmail.org>; Mon,  7 Oct 2013 15:33:32 -0700 (PDT)\r
21 X-AuditID: 12074423-b7fc98e0000009a2-02-525336bc1925\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 45.7B.02466.CB633525; Mon,  7 Oct 2013 18:33:32 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id r97MXTQ8024748; \r
27         Mon, 7 Oct 2013 18:33:30 -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 r97MXShI028593\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 7 Oct 2013 18:33:29 -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 1VTJMm-0006c9-P5; Mon, 07 Oct 2013 18:33:28 -0400\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 11/11] emacs: Fix search tagging races\r
40 Date: Mon,  7 Oct 2013 18:33:21 -0400\r
41 Message-Id: <1381185201-25197-12-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+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrrvHLDjI4PF6WYvrN2cyOzB6PFt1\r
47         izmAMYrLJiU1J7MstUjfLoEr40vrIZaCZ3oVOxu+sTQwPlbrYuTkkBAwkfjy5yErhC0mceHe\r
48         erYuRi4OIYF9jBLn/s9nh3A2MEpM3NvGDOEcZpKY2zGTFcKZyyix++4MZpB+NgENiW37lzOC\r
49         2CIC0hI7784GKuLgYBZQk/jTpQISFhYwk/j9tAOsnEVAVeLHthNgNq+Ao8T+ZV+hzlCSWHhq\r
50         G5jNCRRfsvEiG4gtJOAgMXf/ItYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Zrp5WaW\r
51         6KWmlG5iBIeNi/IOxj8HlQ4xCnAwKvHwZhwNChJiTSwrrsw9xCjJwaQkyvvAODhIiC8pP6Uy\r
52         I7E4I76oNCe1+BCjBAezkgivgBFQjjclsbIqtSgfJiXNwaIkznuLwz5ISCA9sSQ1OzW1ILUI\r
53         JivDwaEkwRtmCtQoWJSanlqRlplTgpBm4uAEGc4DNDwZpIa3uCAxtzgzHSJ/ilFRSpx3NkhC\r
54         ACSRUZoH1wuL61eM4kCvCPNuBaniAaYEuO5XQIOZgAbrsgeCDC5JREhJNTDWbumZ+0Lo4Ryv\r
55         9XM/PPwyW6X4ZGVuv/qbI96yl6vPhnwUXLVkgefUh1IzCtxDX25yWeC2ZY/HtlRL76QTry5v\r
56         7H+cvPml97GkiA0/Ll7oWHbnx4ubB1VmMkZ9to5etbdi+0RXc8VFDZ9+5a2LYFdqOWmQ2Lc6\r
57         Xi1586ftH5REbsy08PE4cvzpLSWW4oxEQy3mouJEAJSzu07GAgAA\r
58 X-BeenThere: notmuch@notmuchmail.org\r
59 X-Mailman-Version: 2.1.13\r
60 Precedence: list\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:47 -0000\r
71 \r
72 This fixes races in thread-local and global tagging in notmuch-search\r
73 (e.g., "+", "-", "a", "*", etc.).  Previously, these would modify tags\r
74 of new messages that arrived after the search.  Now they only operate\r
75 on the messages that were in the threads when the search was\r
76 performed.  This prevents surprises like archiving messages that\r
77 arrived in a thread after the search results were shown.\r
78 \r
79 This eliminates `notmuch-search-find-thread-id-region(-search)'\r
80 because these functions strongly encouraged racy usage.\r
81 \r
82 This fixes the two broken tests added by the previous patch.\r
83 ---\r
84  devel/TODO       |  5 -----\r
85  emacs/notmuch.el | 40 +++++++++++++++++++++++++++-------------\r
86  test/emacs       |  4 +---\r
87  3 files changed, 28 insertions(+), 21 deletions(-)\r
88 \r
89 diff --git a/devel/TODO b/devel/TODO\r
90 index f212483..1cf4089 100644\r
91 --- a/devel/TODO\r
92 +++ b/devel/TODO\r
93 @@ -14,11 +14,6 @@ sender's name containing ';' which causes emacs to drop a search\r
94  result.) This may require removing the outer array from the current\r
95  "notmuch search --format=json" results.\r
96  \r
97 -Fix '*' to work by simply calling '+' or '-' on a region consisting of\r
98 -the entire buffer, (this would avoid one race condition---while still\r
99 -leaving other race conditions---but could also potentially make '*' a\r
100 -very expensive operation).\r
101 -\r
102  Add a global keybinding table for notmuch, and then view-specific\r
103  tables that add to it.\r
104         \r
105 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
106 index 2c7678d..1c64745 100644\r
107 --- a/emacs/notmuch.el\r
108 +++ b/emacs/notmuch.el\r
109 @@ -461,14 +461,25 @@ If BARE is set then do not prefix with \"thread:\""\r
110    (let ((thread (plist-get (notmuch-search-get-result) :thread)))\r
111      (when thread (concat (unless bare "thread:") thread))))\r
112  \r
113 -(defun notmuch-search-find-thread-id-region (beg end)\r
114 -  "Return a list of threads for the current region"\r
115 -  (mapcar (lambda (thread) (concat "thread:" thread))\r
116 -         (notmuch-search-properties-in-region :thread beg end)))\r
117 -\r
118 -(defun notmuch-search-find-thread-id-region-search (beg end)\r
119 -  "Return a search string for threads for the current region"\r
120 -  (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))\r
121 +(defun notmuch-search-find-stable-query ()\r
122 +  "Return the stable queries for the current thread.\r
123 +\r
124 +This returns a list (MATCHED-QUERY UNMATCHED-QUERY) for the\r
125 +matched and unmatched messages in the current thread."\r
126 +  (plist-get (notmuch-search-get-result) :query))\r
127 +\r
128 +(defun notmuch-search-find-stable-query-region (beg end &optional only-matched)\r
129 +  "Return the stable query for the current region.\r
130 +\r
131 +If ONLY-MATCHED is non-nil, include only matched messages.  If it\r
132 +is nil, include both matched and unmatched messages."\r
133 +  (let ((query-list nil) (all (not only-matched)))\r
134 +    (dolist (queries (notmuch-search-properties-in-region :query beg end))\r
135 +      (when (first queries)\r
136 +       (push (first queries) query-list))\r
137 +      (when (and all (second queries))\r
138 +       (push (second queries) query-list)))\r
139 +    (concat "(" (mapconcat 'identity query-list ") or (") ")")))\r
140  \r
141  (defun notmuch-search-find-authors ()\r
142    "Return the authors for the current thread"\r
143 @@ -525,9 +536,12 @@ If BARE is set then do not prefix with \"thread:\""\r
144         (setq output (append output (notmuch-search-get-tags pos)))))\r
145      output))\r
146  \r
147 -(defun notmuch-search-tag-region (beg end &optional tag-changes)\r
148 -  "Change tags for threads in the given region."\r
149 -  (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
150 +(defun notmuch-search-tag-region (beg end &optional tag-changes only-matched)\r
151 +  "Change tags for threads in the given region.\r
152 +\r
153 +If ONLY-MATCHED is non-nil, only tag matched messages."\r
154 +  (let ((search-string (notmuch-search-find-stable-query-region\r
155 +                       beg end only-matched)))\r
156      (setq tag-changes (notmuch-tag search-string tag-changes))\r
157      (notmuch-search-foreach-result beg end\r
158        (lambda (pos)\r
159 @@ -796,7 +810,7 @@ non-authors is found, assume that all of the authors match."\r
160  \r
161  See `notmuch-tag' for information on the format of TAG-CHANGES."\r
162    (interactive)\r
163 -  (apply 'notmuch-tag notmuch-search-query-string tag-changes))\r
164 +  (notmuch-search-tag-region (point-min) (point-max) tag-changes t))\r
165  \r
166  (defun notmuch-search-buffer-title (query)\r
167    "Returns the title for a buffer with notmuch search results."\r
168 @@ -899,7 +913,7 @@ the configured default sort order."\r
169        (save-excursion\r
170         (let ((proc (notmuch-start-notmuch\r
171                      "notmuch-search" buffer #'notmuch-search-process-sentinel\r
172 -                    "search" "--format=sexp" "--format-version=1"\r
173 +                    "search" "--format=sexp" "--format-version=2"\r
174                      (if oldest-first\r
175                          "--sort=oldest-first"\r
176                        "--sort=newest-first")\r
177 diff --git a/test/emacs b/test/emacs\r
178 index e0dcd3c..88eb1e5 100755\r
179 --- a/test/emacs\r
180 +++ b/test/emacs\r
181 @@ -889,7 +889,7 @@ $PWD/notmuch_fail exited with status 1 (see *Notmuch errors* for more details)\r
182  ---\r
183  [XXX]\r
184  $PWD/notmuch_fail exited with status 1\r
185 -command: $PWD/notmuch_fail search --format\=sexp --format-version\=1 --sort\=newest-first tag\:inbox\r
186 +command: $PWD/notmuch_fail search --format\=sexp --format-version\=2 --sort\=newest-first tag\:inbox\r
187  exit status: 1"\r
188  \r
189  test_begin_subtest "Search handles subprocess warnings"\r
190 @@ -923,7 +923,6 @@ This is a warning\r
191  This is another warning"\r
192  \r
193  test_begin_subtest "Search thread tag operations are race-free"\r
194 -test_subtest_known_broken\r
195  add_message '[subject]="Search race test"'\r
196  gen_msg_id_1=$gen_msg_id\r
197  generate_message '[in-reply-to]="<'$gen_msg_id_1'>"' \\r
198 @@ -937,7 +936,6 @@ output=$(notmuch search --output=messages 'tag:search-thread-race-tag')\r
199  test_expect_equal "$output" "id:$gen_msg_id_1"\r
200  \r
201  test_begin_subtest "Search global tag operations are race-free"\r
202 -test_subtest_known_broken\r
203  generate_message '[in-reply-to]="<'$gen_msg_id_1'>"' \\r
204             '[references]="<'$gen_msg_id_1'>"' \\r
205             '[subject]="Re: Search race test"'\r
206 -- \r
207 1.8.4.rc3\r
208 \r