Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / c7 / 55cf35d681fb6b0c23484fd4723eb33a506935
1 Return-Path: <jani@nikula.org>\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 3CDDD431FBD\r
6         for <notmuch@notmuchmail.org>; Sun,  9 Mar 2014 00:46:06 -0800 (PST)\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 LKBuHo11PT2G for <notmuch@notmuchmail.org>;\r
16         Sun,  9 Mar 2014 00:45:58 -0800 (PST)\r
17 Received: from mail-la0-f47.google.com (mail-la0-f47.google.com\r
18         [209.85.215.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id C6412431FB6\r
21         for <notmuch@notmuchmail.org>; Sun,  9 Mar 2014 00:45:57 -0800 (PST)\r
22 Received: by mail-la0-f47.google.com with SMTP id y1so3897885lam.34\r
23         for <notmuch@notmuchmail.org>; Sun, 09 Mar 2014 00:45:55 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=1e100.net; s=20130820;\r
26         h=x-gm-message-state:from:to:cc:subject:in-reply-to:references\r
27         :user-agent:date:message-id:mime-version:content-type;\r
28         bh=RpDpnYnLLdbiwFqf+TVYQZKJggLeETc8U6hUqV5qZ48=;\r
29         b=WHsRfJPDoGfYpIKbl+GRRPiWWown1051C2B1m2UOfQo9mQbcsN9tpLCrGYHlDbK1Ro\r
30         3GeloiaRAVzetCQOsXrEjZzW6zTGA/SAe2UWoqx6tmizxRZ/1dw6xBHHradI/rdcWgGR\r
31         /EG0wfuc3CFJYP6egisL6B1IrxMzBsURFCLL3zxiFq1PVx3xjXDaobCDTapcnfr+0LtA\r
32         6wiDbBvwYmrjzODPDX4f1b1Mt/D04+M8cojAG5TQN/NAL6i1VeIbhT239rcI7/OT/h7i\r
33         G9bktMoSQxEvjPnKozEJAWrWOwfxzRu9ETFWBGqPnwQEf3Y09YHGXZ20MeZcdDOVlLii\r
34         fqkA==\r
35 X-Gm-Message-State:\r
36  ALoCoQm73A9LRbFSFsMKNEaCcSVBxiXshfCJqOfA4MJS6mfzMfXB0DqKi3IFcO1nxNTJyMRSQjtx\r
37 X-Received: by 10.112.46.225 with SMTP id y1mr17697584lbm.12.1394354754057;\r
38         Sun, 09 Mar 2014 00:45:54 -0800 (PST)\r
39 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
40         [88.195.111.91])\r
41         by mx.google.com with ESMTPSA id q6sm23951687lal.3.2014.03.09.00.45.52\r
42         for <multiple recipients>\r
43         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
44         Sun, 09 Mar 2014 00:45:53 -0800 (PST)\r
45 From: Jani Nikula <jani@nikula.org>\r
46 To: Austin Clements <amdragon@MIT.EDU>, David Bremner <david@tethera.net>\r
47 Subject: Re: [Patch v3 04/15] lib: make folder: prefix literal\r
48 In-Reply-To: <20140308235127.GL4709@mit.edu>\r
49 References: <1394313585-28422-1-git-send-email-david@tethera.net>\r
50         <1394313585-28422-5-git-send-email-david@tethera.net>\r
51         <20140308235127.GL4709@mit.edu>\r
52 User-Agent: Notmuch/0.17+101~g2c5a6ae9e6e9 (http://notmuchmail.org)\r
53         Emacs/24.3.1 (x86_64-pc-linux-gnu)\r
54 Date: Sun, 09 Mar 2014 10:45:51 +0200\r
55 Message-ID: <87pplv69q8.fsf@nikula.org>\r
56 MIME-Version: 1.0\r
57 Content-Type: text/plain\r
58 Cc: notmuch@notmuchmail.org\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Sun, 09 Mar 2014 08:46:06 -0000\r
72 \r
73 On Sun, 09 Mar 2014, Austin Clements <amdragon@MIT.EDU> wrote:\r
74 > Quoth David Bremner on Mar 08 at  5:19 pm:\r
75 >> From: Jani Nikula <jani@nikula.org>\r
76 >> \r
77 >> In xapian terms, convert folder: prefix from probabilistic to boolean\r
78 >> prefix, matching the paths, relative form the maildir root, of the\r
79 >\r
80 > s/form/from/\r
81 >\r
82 >> message files, ignoring the maildir new and cur leaf directories.\r
83 >> \r
84 >> folder:foo matches all message files in foo, foo/new, and foo/cur.\r
85 >> \r
86 >> folder:foo/new does *not* match message files in foo/new.\r
87 >> \r
88 >> folder:"" matches all message files in the top level maildir and its\r
89 >> new and cur subdirectories.\r
90 >> \r
91 >> This change constitutes a database change: bump the database version\r
92 >> and add database upgrade support for folder: terms. The upgrade also\r
93 >> adds path: terms.\r
94 >> ---\r
95 >>  lib/database.cc       | 38 ++++++++++++++++++++++--\r
96 >>  lib/message.cc        | 80 ++++++++++++++++++++++++++++++++++++++++++++-------\r
97 >>  lib/notmuch-private.h |  3 ++\r
98 >>  3 files changed, 108 insertions(+), 13 deletions(-)\r
99 >> \r
100 >> diff --git a/lib/database.cc b/lib/database.cc\r
101 >> index 93cc7f5..186e3a7 100644\r
102 >> --- a/lib/database.cc\r
103 >> +++ b/lib/database.cc\r
104 >> @@ -42,7 +42,7 @@ typedef struct {\r
105 >>      const char *prefix;\r
106 >>  } prefix_t;\r
107 >>  \r
108 >> -#define NOTMUCH_DATABASE_VERSION 1\r
109 >> +#define NOTMUCH_DATABASE_VERSION 2\r
110 >>  \r
111 >>  #define STRINGIFY(s) _SUB_STRINGIFY(s)\r
112 >>  #define _SUB_STRINGIFY(s) #s\r
113 >> @@ -210,6 +210,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
114 >>      { "is",                 "K" },\r
115 >>      { "id",                 "Q" },\r
116 >>      { "path",                       "P" },\r
117 >> +    { "folder",                     "XFOLDER:" },\r
118 >\r
119 > It took me a while to figure out that the ":" here means that Xapian\r
120 > will unconditionally use a ":" after the prefix, instead of only using\r
121 > a ":" when the first letter following the prefix is upper-case ASCII.\r
122 > Maybe I was only confused by this because I simultaneously knew too\r
123 > much and not enough about Xapian, but it might be worth a comment.\r
124 > Something like,\r
125 >\r
126 >     /* Without the ":", since this is a multi-letter prefix, Xapian\r
127 >      * will add a colon itself if the first letter of the path is\r
128 >      * upper-case ASCII.  Including the ":" forces there to always be\r
129 >      * a colon, which keeps our own logic simpler. */\r
130 \r
131 Do you mean "... first letter of the _prefix_ is ..."?\r
132 \r
133 Jani.\r
134 \r
135 >\r
136 >>  };\r
137 >>  \r
138 >>  static prefix_t PROBABILISTIC_PREFIX[]= {\r
139 >> @@ -217,7 +218,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
140 >>      { "to",                 "XTO" },\r
141 >>      { "attachment",         "XATTACHMENT" },\r
142 >>      { "subject",            "XSUBJECT"},\r
143 >> -    { "folder",                     "XFOLDER"}\r
144 >>  };\r
145 >>  \r
146 >>  const char *\r
147 >> @@ -1168,6 +1168,40 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
148 >>      }\r
149 >>      }\r
150 >>  \r
151 >> +    /*\r
152 >> +     * Prior to version 2, the "folder:" prefix was probabilistic and\r
153 >> +     * stemmed. Change it to the current boolean prefix. Add "path:"\r
154 >> +     * prefixes while at it.\r
155 >> +     */\r
156 >> +    if (version < 2) {\r
157 >> +       notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
158 >\r
159 > Three space indentation and no tabs?  (It looks like this was in\r
160 > Jani's v2, also.  I'm guessing at some point there was a copy-paste\r
161 > from a diff with tabs converted to spaces?)\r
162 >\r
163 >> +       notmuch_messages_t *messages;\r
164 >> +       notmuch_message_t *message;\r
165 >> +\r
166 >> +       count = 0;\r
167 >> +       total = notmuch_query_count_messages (query);\r
168 >> +\r
169 >> +       for (messages = notmuch_query_search_messages (query);\r
170 >> +            notmuch_messages_valid (messages);\r
171 >> +            notmuch_messages_move_to_next (messages)) {\r
172 >> +           if (do_progress_notify) {\r
173 >> +               progress_notify (closure, (double) count / total);\r
174 >> +               do_progress_notify = 0;\r
175 >> +           }\r
176 >> +\r
177 >> +           message = notmuch_messages_get (messages);\r
178 >> +\r
179 >> +           _notmuch_message_upgrade_folder (message);\r
180 >> +           _notmuch_message_sync (message);\r
181 >> +\r
182 >> +           notmuch_message_destroy (message);\r
183 >> +\r
184 >> +           count++;\r
185 >> +       }\r
186 >> +\r
187 >> +       notmuch_query_destroy (query);\r
188 >> +    }\r
189 >> +\r
190 >>      db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
191 >>      db->flush ();\r
192 >>  \r
193 >> diff --git a/lib/message.cc b/lib/message.cc\r
194 >> index 21abe8e..31cb9f1 100644\r
195 >> --- a/lib/message.cc\r
196 >> +++ b/lib/message.cc\r
197 >> @@ -504,6 +504,56 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
198 >>      }\r
199 >>  }\r
200 >>  \r
201 >> +/* Return true if p points at "new" or "cur". */\r
202 >> +static bool is_maildir (const char *p)\r
203 >> +{\r
204 >> +    return strcmp (p, "cur") == 0 || strcmp (p, "new") == 0;\r
205 >> +}\r
206 >> +\r
207 >> +/* Add "folder:" term for directory. */\r
208 >> +static notmuch_status_t\r
209 >> +_notmuch_message_add_folder_terms (notmuch_message_t *message,\r
210 >> +                               const char *directory)\r
211 >> +{\r
212 >> +    char *folder, *last;\r
213 >> +\r
214 >> +    folder = talloc_strdup (NULL, directory);\r
215 >> +    if (! folder)\r
216 >> +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
217 >\r
218 > Same formatting problem in this chunk.\r
219 >\r
220 >> +\r
221 >> +    /*\r
222 >> +     * If the message file is in a leaf directory named "new" or\r
223 >> +     * "cur", presume maildir and index the parent directory. Thus a\r
224 >> +     * "folder:" prefix search matches messages in the specified\r
225 >> +     * maildir folder, i.e. in the specified directory and its "new"\r
226 >> +     * and "cur" subdirectories.\r
227 >> +     *\r
228 >> +     * Note that this means the "folder:" prefix can't be used for\r
229 >> +     * distinguishing between message files in "new" or "cur". The\r
230 >> +     * "path:" prefix needs to be used for that.\r
231 >> +     *\r
232 >> +     * Note the deliberate difference to _filename_is_in_maildir(). We\r
233 >> +     * don't want to index different things depending on the existence\r
234 >> +     * or non-existence of all maildir sibling directories "new",\r
235 >> +     * "cur", and "tmp". Doing so would be surprising, and difficult\r
236 >> +     * for the user to fix in case all subdirectories were not in\r
237 >> +     * place during indexing.\r
238 >> +     */\r
239 >> +    last = strrchr (folder, '/');\r
240 >> +    if (last) {\r
241 >> +       if (is_maildir (last + 1))\r
242 >> +           *last = '\0';\r
243 >> +    } else if (is_maildir (folder)) {\r
244 >> +       *folder = '\0';\r
245 >> +    }\r
246 >> +\r
247 >> +    _notmuch_message_add_term (message, "folder", folder);\r
248 >> +\r
249 >> +    talloc_free (folder);\r
250 >> +\r
251 >> +    return NOTMUCH_STATUS_SUCCESS;\r
252 >> +}\r
253 >> +\r
254 >>  #define RECURSIVE_SUFFIX "/**"\r
255 >>  \r
256 >>  /* Add "path:" terms for directory. */\r
257 >> @@ -570,9 +620,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)\r
258 >>      directory = _notmuch_database_get_directory_path (ctx,\r
259 >>                                                        message->notmuch,\r
260 >>                                                        directory_id);\r
261 >> -    if (strlen (directory))\r
262 >> -        _notmuch_message_gen_terms (message, "folder", directory);\r
263 >>  \r
264 >> +    _notmuch_message_add_folder_terms (message, directory);\r
265 >>      _notmuch_message_add_path_terms (message, directory);\r
266 >>      }\r
267 >>  \r
268 >> @@ -610,9 +659,7 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
269 >>       * notmuch_directory_get_child_files() . */\r
270 >>      _notmuch_message_add_term (message, "file-direntry", direntry);\r
271 >>  \r
272 >> -    /* New terms allow user to search with folder: specification. */\r
273 >> -    _notmuch_message_gen_terms (message, "folder", directory);\r
274 >> -\r
275 >> +    _notmuch_message_add_folder_terms (message, directory);\r
276 >>      _notmuch_message_add_path_terms (message, directory);\r
277 >>  \r
278 >>      talloc_free (local);\r
279 >> @@ -637,8 +684,6 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
280 >>                                const char *filename)\r
281 >>  {\r
282 >>      void *local = talloc_new (message);\r
283 >> -    const char *folder_prefix = _find_prefix ("folder");\r
284 >> -    char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix);\r
285 >>      char *direntry;\r
286 >>      notmuch_private_status_t private_status;\r
287 >>      notmuch_status_t status;\r
288 >> @@ -659,10 +704,7 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
289 >>      /* Re-synchronize "folder:" and "path:" terms for this message. */\r
290 >>  \r
291 >>      /* Remove all "folder:" terms. */\r
292 >> -    _notmuch_message_remove_terms (message, folder_prefix);\r
293 >> -\r
294 >> -    /* Remove all "folder:" stemmed terms. */\r
295 >> -    _notmuch_message_remove_terms (message, zfolder_prefix);\r
296 >> +    _notmuch_message_remove_terms (message, _find_prefix ("folder"));\r
297 >>  \r
298 >>      /* Remove all "path:" terms. */\r
299 >>      _notmuch_message_remove_terms (message, _find_prefix ("path"));\r
300 >> @@ -675,6 +717,22 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
301 >>      return status;\r
302 >>  }\r
303 >>  \r
304 >> +/* Upgrade the "folder:" prefix from V1 to V2. */\r
305 >> +#define FOLDER_PREFIX_V1       "XFOLDER"\r
306 >> +#define ZFOLDER_PREFIX_V1      "Z" FOLDER_PREFIX_V1\r
307 >> +void\r
308 >> +_notmuch_message_upgrade_folder (notmuch_message_t *message)\r
309 >> +{\r
310 >> +    /* Remove all old "folder:" terms. */\r
311 >> +    _notmuch_message_remove_terms (message, FOLDER_PREFIX_V1);\r
312 >> +\r
313 >> +    /* Remove all old "folder:" stemmed terms. */\r
314 >> +    _notmuch_message_remove_terms (message, ZFOLDER_PREFIX_V1);\r
315 >> +\r
316 >> +    /* Add new boolean "folder:" and "path:" terms. */\r
317 >> +    _notmuch_message_add_directory_terms (message, message);\r
318 >> +}\r
319 >> +\r
320 >>  char *\r
321 >>  _notmuch_message_talloc_copy_data (notmuch_message_t *message)\r
322 >>  {\r
323 >> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
324 >> index af185c7..59eb2bc 100644\r
325 >> --- a/lib/notmuch-private.h\r
326 >> +++ b/lib/notmuch-private.h\r
327 >> @@ -263,6 +263,9 @@ _notmuch_message_gen_terms (notmuch_message_t *message,\r
328 >>  void\r
329 >>  _notmuch_message_upgrade_filename_storage (notmuch_message_t *message);\r
330 >>  \r
331 >> +void\r
332 >> +_notmuch_message_upgrade_folder (notmuch_message_t *message);\r
333 >> +\r
334 >>  notmuch_status_t\r
335 >>  _notmuch_message_add_filename (notmuch_message_t *message,\r
336 >>                             const char *filename);\r