Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 28 / 5b4537b26fbe8b518a6f6e8f0ae1eb7f66716f
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 A6B66431FAF\r
6         for <notmuch@notmuchmail.org>; Tue, 25 Dec 2012 19:49:25 -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 WPQBA1HJ2oWd for <notmuch@notmuchmail.org>;\r
16         Tue, 25 Dec 2012 19:49:21 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id C2BE9431FBD\r
20         for <notmuch@notmuchmail.org>; Tue, 25 Dec 2012 19:49:07 -0800 (PST)\r
21 X-AuditID: 12074422-b7f616d000000e7c-22-50da73b3d3f3\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 62.4B.03708.3B37AD05; Tue, 25 Dec 2012 22:49:07 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qBQ3muuc025519; \r
27         Tue, 25 Dec 2012 22:48:56 -0500\r
28 Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
29         [76.21.105.205]) (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBQ3mrI6013184\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Tue, 25 Dec 2012 22:48:55 -0500 (EST)\r
34 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1Tnhz8-0002z2-Us; Tue, 25 Dec 2012 22:48:50 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v2 4/5] dump/restore: Use Xapian queries for batch-tag format\r
40 Date: Tue, 25 Dec 2012 22:48:42 -0500\r
41 Message-Id: <1356493723-11085-5-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.10.4\r
43 In-Reply-To: <1356493723-11085-1-git-send-email-amdragon@mit.edu>\r
44 References: <1356493723-11085-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsUixCmqrbu5+FaAweXt4hY3WrsZLZqmO1us\r
47         nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DKmDRrEWvB\r
48         RPWKg/e+MTcw7pTrYuTkkBAwkbi8rYUFwhaTuHBvPVsXIxeHkMA+RonVU+ezQjgbGCX+H57P\r
49         BOFcZJJY3bKJGcKZyyhxeM0JsH42AQ2JbfuXM4LYIgLSEjvvzmYFsZkF8iQePtrKDmILC/hK\r
50         PL3QC2azCKhKtHYcAKvhFXCQ+PfiLzPEHYoS3c8mAN3BwcEp4Cix80EdSFgIqGTiw/NMExj5\r
51         FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI11cvNLNFLTSndxAgKN3YXpR2MPw8qHWIU4GBU\r
52         4uHd8P1mgBBrYllxZe4hRkkOJiVR3u0FtwKE+JLyUyozEosz4otKc1KLDzFKcDArifA6fwQq\r
53         501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh4FCS4N1cBDRUsCg1PbUiLTOn\r
54         BCHNxMEJMpwHaPhNkBre4oLE3OLMdIj8KUZFKXHeCyAJAZBERmkeXC8sHbxiFAd6RZh3D0gV\r
55         DzCVwHW/AhrMBDQ4lu8GyOCSRISUVAOj1OTMWT9naDyan2DG3npbSWCClK+LwuGphhFcDWoB\r
56         tWkvjV+f2usvtvL34/eu6RveLFoT3VByitFxRY6N2Z7NWaWNqVvWT+E8xZUrPn91yJRX63bP\r
57         tTMpNfOYNPOc2DeHg7k8GVvvPOJ81MtxUu5+/q2e7VNi1ZdPZVhfJ3Pt+oud7N836vvfUWIp\r
58         zkg01GIuKk4EABGJrjriAgAA\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: Wed, 26 Dec 2012 03:49:26 -0000\r
72 \r
73 This switches the new batch-tag format away from using a home-grown\r
74 hex-encoding scheme for message IDs in the dump to simply using Xapian\r
75 queries with Xapian quoting syntax.\r
76 \r
77 This has a variety of advantages beyond presenting a cleaner and more\r
78 consistent interface.  Foremost is that it will dramatically simplify\r
79 the quoting for batch tagging, which shares the same input format.\r
80 While the hex-encoding is no better or worse for the simple ID queries\r
81 used by dump/restore, it becomes onerous for general-purpose queries\r
82 used in batch tagging.  It also better handles strange cases like\r
83 "id:foo and bar", since this is no longer syntactically valid.\r
84 ---\r
85  notmuch-dump.c    |    9 +++++----\r
86  notmuch-restore.c |   22 ++++++++++------------\r
87  tag-util.c        |    6 ------\r
88  test/dump-restore |   14 ++++++++------\r
89  4 files changed, 23 insertions(+), 28 deletions(-)\r
90 \r
91 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
92 index 29d79da..bf01a39 100644\r
93 --- a/notmuch-dump.c\r
94 +++ b/notmuch-dump.c\r
95 @@ -20,6 +20,7 @@\r
96  \r
97  #include "notmuch-client.h"\r
98  #include "dump-restore-private.h"\r
99 +#include "string-util.h"\r
100  \r
101  int\r
102  notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
103 @@ -141,13 +142,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
104                 fprintf (stderr, "Error: cannot dump message id containing line break: %s\n", message_id);\r
105                 return 1;\r
106             }\r
107 -           if (hex_encode (notmuch, message_id,\r
108 -                           &buffer, &buffer_size) != HEX_SUCCESS) {\r
109 -                   fprintf (stderr, "Error: failed to hex-encode msg-id %s\n",\r
110 +           if (make_boolean_term (notmuch, "id", message_id,\r
111 +                                  &buffer, &buffer_size)) {\r
112 +                   fprintf (stderr, "Error: failed to quote message id %s\n",\r
113                              message_id);\r
114                     return 1;\r
115             }\r
116 -           fprintf (output, " -- id:%s\n", buffer);\r
117 +           fprintf (output, " -- %s\n", buffer);\r
118         }\r
119  \r
120         notmuch_message_destroy (message);\r
121 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
122 index 9ed9b51..77a4c27 100644\r
123 --- a/notmuch-restore.c\r
124 +++ b/notmuch-restore.c\r
125 @@ -207,7 +207,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
126             INTERNAL_ERROR ("compile time constant regex failed.");\r
127  \r
128      do {\r
129 -       char *query_string;\r
130 +       char *query_string, *prefix, *term;\r
131  \r
132         if (line_ctx != NULL)\r
133             talloc_free (line_ctx);\r
134 @@ -220,19 +220,17 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
135                                   &query_string, tag_ops);\r
136  \r
137             if (ret == 0) {\r
138 -               if (strncmp ("id:", query_string, 3) != 0) {\r
139 -                   fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
140 +               ret = parse_boolean_term (line_ctx, query_string,\r
141 +                                         &prefix, &term);\r
142 +               if (ret) {\r
143 +                   fprintf (stderr, "Warning: cannot parse query: %s\n",\r
144 +                            query_string);\r
145 +                   continue;\r
146 +               } else if (strcmp ("id", prefix) != 0) {\r
147 +                   fprintf (stderr, "Warning: not an id query: %s\n", query_string);\r
148                     continue;\r
149                 }\r
150 -               /* delete id: from front of string; tag_message\r
151 -                * expects a raw message-id.\r
152 -                *\r
153 -                * XXX: Note that query string id:foo and bar will be\r
154 -                * interpreted as a message id "foo and bar". This\r
155 -                * should eventually be fixed to give a better error\r
156 -                * message.\r
157 -                */\r
158 -               query_string = query_string + 3;\r
159 +               query_string = term;\r
160             }\r
161         }\r
162  \r
163 diff --git a/tag-util.c b/tag-util.c\r
164 index 705b7ba..e4e5dda 100644\r
165 --- a/tag-util.c\r
166 +++ b/tag-util.c\r
167 @@ -124,12 +124,6 @@ parse_tag_line (void *ctx, char *line,\r
168      }\r
169  \r
170      /* tok now points to the query string */\r
171 -    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
172 -       ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
173 -                         "hex decoding of query %s failed", tok);\r
174 -       goto DONE;\r
175 -    }\r
176 -\r
177      *query_string = tok;\r
178  \r
179    DONE:\r
180 diff --git a/test/dump-restore b/test/dump-restore\r
181 index 6a989b6..f9ae5b3 100755\r
182 --- a/test/dump-restore\r
183 +++ b/test/dump-restore\r
184 @@ -195,23 +195,25 @@ a\r
185  \r
186  # the previous line was blank; also no yelling please\r
187  +%zz -- id:whatever\r
188 -+e +f id:%yy\r
189 ++e +f id:"\r
190 ++e +f tag:abc\r
191  # the next non-comment line should report an an empty tag error for\r
192  # batch tagging, but not for restore\r
193  + +e -- id:20091117232137.GA7669@griffis1.net\r
194 -# highlight the sketchy id parsing; this should be last\r
195 -+g -- id:foo and bar\r
196 +# valid id, but warning about missing message\r
197 ++e id:missing_message_id\r
198  EOF\r
199  \r
200  cat <<EOF > EXPECTED\r
201 -Warning: unsupported query: a\r
202 +Warning: cannot parse query: a\r
203  Warning: no query string [+0]\r
204  Warning: no query string [+a +b]\r
205  Warning: missing query string [+a +b ]\r
206  Warning: no query string after -- [+c +d --]\r
207  Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
208 -Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
209 -Warning: cannot apply tags to missing message: foo and bar\r
210 +Warning: cannot parse query: id:"\r
211 +Warning: not an id query: tag:abc\r
212 +Warning: cannot apply tags to missing message: missing_message_id\r
213  EOF\r
214  \r
215  test_expect_equal_file EXPECTED OUTPUT\r
216 -- \r
217 1.7.10.4\r
218 \r