[PATCH v2 4/5] dump/restore: Use Xapian queries for batch-tag format
authorAustin Clements <amdragon@MIT.EDU>
Wed, 26 Dec 2012 03:48:42 +0000 (22:48 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:48 +0000 (09:52 -0800)
28/5b4537b26fbe8b518a6f6e8f0ae1eb7f66716f [new file with mode: 0644]

diff --git a/28/5b4537b26fbe8b518a6f6e8f0ae1eb7f66716f b/28/5b4537b26fbe8b518a6f6e8f0ae1eb7f66716f
new file mode 100644 (file)
index 0000000..038eff4
--- /dev/null
@@ -0,0 +1,218 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A6B66431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 25 Dec 2012 19:49:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id WPQBA1HJ2oWd for <notmuch@notmuchmail.org>;\r
+       Tue, 25 Dec 2012 19:49:21 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+       [18.7.68.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id C2BE9431FBD\r
+       for <notmuch@notmuchmail.org>; Tue, 25 Dec 2012 19:49:07 -0800 (PST)\r
+X-AuditID: 12074422-b7f616d000000e7c-22-50da73b3d3f3\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 62.4B.03708.3B37AD05; Tue, 25 Dec 2012 22:49:07 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qBQ3muuc025519; \r
+       Tue, 25 Dec 2012 22:48:56 -0500\r
+Received: from drake.dyndns.org (c-76-21-105-205.hsd1.ca.comcast.net\r
+       [76.21.105.205]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBQ3mrI6013184\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 25 Dec 2012 22:48:55 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Tnhz8-0002z2-Us; Tue, 25 Dec 2012 22:48:50 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 4/5] dump/restore: Use Xapian queries for batch-tag format\r
+Date: Tue, 25 Dec 2012 22:48:42 -0500\r
+Message-Id: <1356493723-11085-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1356493723-11085-1-git-send-email-amdragon@mit.edu>\r
+References: <1356493723-11085-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsUixCmqrbu5+FaAweXt4hY3WrsZLZqmO1us\r
+       nstjcf3mTGYHFo+ds+6ye9y6/5rd49mqW8weWw69Zw5gieKySUnNySxLLdK3S+DKmDRrEWvB\r
+       RPWKg/e+MTcw7pTrYuTkkBAwkbi8rYUFwhaTuHBvPVsXIxeHkMA+RonVU+ezQjgbGCX+H57P\r
+       BOFcZJJY3bKJGcKZyyhxeM0JsH42AQ2JbfuXM4LYIgLSEjvvzmYFsZkF8iQePtrKDmILC/hK\r
+       PL3QC2azCKhKtHYcAKvhFXCQ+PfiLzPEHYoS3c8mAN3BwcEp4Cix80EdSFgIqGTiw/NMExj5\r
+       FzAyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI11cvNLNFLTSndxAgKN3YXpR2MPw8qHWIU4GBU\r
+       4uHd8P1mgBBrYllxZe4hRkkOJiVR3u0FtwKE+JLyUyozEosz4otKc1KLDzFKcDArifA6fwQq\r
+       501JrKxKLcqHSUlzsCiJ815LuekvJJCeWJKanZpakFoEk5Xh4FCS4N1cBDRUsCg1PbUiLTOn\r
+       BCHNxMEJMpwHaPhNkBre4oLE3OLMdIj8KUZFKXHeCyAJAZBERmkeXC8sHbxiFAd6RZh3D0gV\r
+       DzCVwHW/AhrMBDQ4lu8GyOCSRISUVAOj1OTMWT9naDyan2DG3npbSWCClK+LwuGphhFcDWoB\r
+       tWkvjV+f2usvtvL34/eu6RveLFoT3VByitFxRY6N2Z7NWaWNqVvWT+E8xZUrPn91yJRX63bP\r
+       tTMpNfOYNPOc2DeHg7k8GVvvPOJ81MtxUu5+/q2e7VNi1ZdPZVhfJ3Pt+oud7N836vvfUWIp\r
+       zkg01GIuKk4EABGJrjriAgAA\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 26 Dec 2012 03:49:26 -0000\r
+\r
+This switches the new batch-tag format away from using a home-grown\r
+hex-encoding scheme for message IDs in the dump to simply using Xapian\r
+queries with Xapian quoting syntax.\r
+\r
+This has a variety of advantages beyond presenting a cleaner and more\r
+consistent interface.  Foremost is that it will dramatically simplify\r
+the quoting for batch tagging, which shares the same input format.\r
+While the hex-encoding is no better or worse for the simple ID queries\r
+used by dump/restore, it becomes onerous for general-purpose queries\r
+used in batch tagging.  It also better handles strange cases like\r
+"id:foo and bar", since this is no longer syntactically valid.\r
+---\r
+ notmuch-dump.c    |    9 +++++----\r
+ notmuch-restore.c |   22 ++++++++++------------\r
+ tag-util.c        |    6 ------\r
+ test/dump-restore |   14 ++++++++------\r
+ 4 files changed, 23 insertions(+), 28 deletions(-)\r
+\r
+diff --git a/notmuch-dump.c b/notmuch-dump.c\r
+index 29d79da..bf01a39 100644\r
+--- a/notmuch-dump.c\r
++++ b/notmuch-dump.c\r
+@@ -20,6 +20,7 @@\r
\r
+ #include "notmuch-client.h"\r
+ #include "dump-restore-private.h"\r
++#include "string-util.h"\r
\r
+ int\r
+ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+@@ -141,13 +142,13 @@ notmuch_dump_command (unused (void *ctx), int argc, char *argv[])\r
+               fprintf (stderr, "Error: cannot dump message id containing line break: %s\n", message_id);\r
+               return 1;\r
+           }\r
+-          if (hex_encode (notmuch, message_id,\r
+-                          &buffer, &buffer_size) != HEX_SUCCESS) {\r
+-                  fprintf (stderr, "Error: failed to hex-encode msg-id %s\n",\r
++          if (make_boolean_term (notmuch, "id", message_id,\r
++                                 &buffer, &buffer_size)) {\r
++                  fprintf (stderr, "Error: failed to quote message id %s\n",\r
+                            message_id);\r
+                   return 1;\r
+           }\r
+-          fprintf (output, " -- id:%s\n", buffer);\r
++          fprintf (output, " -- %s\n", buffer);\r
+       }\r
\r
+       notmuch_message_destroy (message);\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index 9ed9b51..77a4c27 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -207,7 +207,7 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+           INTERNAL_ERROR ("compile time constant regex failed.");\r
\r
+     do {\r
+-      char *query_string;\r
++      char *query_string, *prefix, *term;\r
\r
+       if (line_ctx != NULL)\r
+           talloc_free (line_ctx);\r
+@@ -220,19 +220,17 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+                                 &query_string, tag_ops);\r
\r
+           if (ret == 0) {\r
+-              if (strncmp ("id:", query_string, 3) != 0) {\r
+-                  fprintf (stderr, "Warning: unsupported query: %s\n", query_string);\r
++              ret = parse_boolean_term (line_ctx, query_string,\r
++                                        &prefix, &term);\r
++              if (ret) {\r
++                  fprintf (stderr, "Warning: cannot parse query: %s\n",\r
++                           query_string);\r
++                  continue;\r
++              } else if (strcmp ("id", prefix) != 0) {\r
++                  fprintf (stderr, "Warning: not an id query: %s\n", query_string);\r
+                   continue;\r
+               }\r
+-              /* delete id: from front of string; tag_message\r
+-               * expects a raw message-id.\r
+-               *\r
+-               * XXX: Note that query string id:foo and bar will be\r
+-               * interpreted as a message id "foo and bar". This\r
+-               * should eventually be fixed to give a better error\r
+-               * message.\r
+-               */\r
+-              query_string = query_string + 3;\r
++              query_string = term;\r
+           }\r
+       }\r
\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 705b7ba..e4e5dda 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -124,12 +124,6 @@ parse_tag_line (void *ctx, char *line,\r
+     }\r
\r
+     /* tok now points to the query string */\r
+-    if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
+-      ret = line_error (TAG_PARSE_INVALID, line_for_error,\r
+-                        "hex decoding of query %s failed", tok);\r
+-      goto DONE;\r
+-    }\r
+-\r
+     *query_string = tok;\r
\r
+   DONE:\r
+diff --git a/test/dump-restore b/test/dump-restore\r
+index 6a989b6..f9ae5b3 100755\r
+--- a/test/dump-restore\r
++++ b/test/dump-restore\r
+@@ -195,23 +195,25 @@ a\r
\r
+ # the previous line was blank; also no yelling please\r
+ +%zz -- id:whatever\r
+-+e +f id:%yy\r
+++e +f id:"\r
+++e +f tag:abc\r
+ # the next non-comment line should report an an empty tag error for\r
+ # batch tagging, but not for restore\r
+ + +e -- id:20091117232137.GA7669@griffis1.net\r
+-# highlight the sketchy id parsing; this should be last\r
+-+g -- id:foo and bar\r
++# valid id, but warning about missing message\r
+++e id:missing_message_id\r
+ EOF\r
\r
+ cat <<EOF > EXPECTED\r
+-Warning: unsupported query: a\r
++Warning: cannot parse query: a\r
+ Warning: no query string [+0]\r
+ Warning: no query string [+a +b]\r
+ Warning: missing query string [+a +b ]\r
+ Warning: no query string after -- [+c +d --]\r
+ Warning: hex decoding of tag %zz failed [+%zz -- id:whatever]\r
+-Warning: hex decoding of query id:%yy failed [+e +f id:%yy]\r
+-Warning: cannot apply tags to missing message: foo and bar\r
++Warning: cannot parse query: id:"\r
++Warning: not an id query: tag:abc\r
++Warning: cannot apply tags to missing message: missing_message_id\r
+ EOF\r
\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+-- \r
+1.7.10.4\r
+\r