[PATCH 4/5] dump/restore: Use Xapian queries for batch-tag format
authorAustin Clements <amdragon@MIT.EDU>
Tue, 25 Dec 2012 05:57:55 +0000 (00:57 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:44 +0000 (09:52 -0800)
90/f306841772634191534a31f513d1d6a0e56927 [new file with mode: 0644]

diff --git a/90/f306841772634191534a31f513d1d6a0e56927 b/90/f306841772634191534a31f513d1d6a0e56927
new file mode 100644 (file)
index 0000000..380b23b
--- /dev/null
@@ -0,0 +1,215 @@
+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 18F26431FD2\r
+       for <notmuch@notmuchmail.org>; Mon, 24 Dec 2012 21:58:20 -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 VjhCfDf3T6RL for <notmuch@notmuchmail.org>;\r
+       Mon, 24 Dec 2012 21:58:18 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+       [18.7.68.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 61E96431FC0\r
+       for <notmuch@notmuchmail.org>; Mon, 24 Dec 2012 21:58:14 -0800 (PST)\r
+X-AuditID: 12074424-b7f4e6d0000004ca-2a-50d94076303e\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 80.FE.01226.67049D05; Tue, 25 Dec 2012 00:58:14 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id qBP5wCKx008906; \r
+       Tue, 25 Dec 2012 00:58:12 -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 qBP5w7WY011707\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 25 Dec 2012 00:58:10 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TnNWg-0001Xu-RP; Tue, 25 Dec 2012 00:58:06 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/5] dump/restore: Use Xapian queries for batch-tag format\r
+Date: Tue, 25 Dec 2012 00:57:55 -0500\r
+Message-Id: <1356415076-5692-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1356415076-5692-1-git-send-email-amdragon@mit.edu>\r
+References: <1356415076-5692-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrHIsWRmVeSWpSXmKPExsUixG6nrlvmcDPAYO4/bosbrd2MFk3TnS1W\r
+       z+WxuH5zJrMDi8fOWXfZPW7df83u8WzVLWaPLYfeMwewRHHZpKTmZJalFunbJXBlrJ5wl7Hg\r
+       v2rF91sfmRsY98h2MXJwSAiYSJyamdrFyAlkiklcuLeerYuRi0NIYB+jxKXzl6GcDYwS654f\r
+       YodwLjJJHD84GSozl1Hi8Y+3LCD9bAIaEtv2L2cEsUUEpCV23p3NCmIzC+RJPHy0lR1knbCA\r
+       l8T1GUkgYRYBVYkdp86DtfIK2Eu0/PzCBnGGokT3swlgNqeAg8TcPyvBaoSAar7O3cwygZF/\r
+       ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl1zvdzMEr3UlNJNjOBgc1HZwdh8SOkQowAHoxIP\r
+       b8HkGwFCrIllxZW5hxglOZiURHlf290MEOJLyk+pzEgszogvKs1JLT7EKMHBrCTCa8IDlONN\r
+       SaysSi3Kh0lJc7AoifNeT7npLySQnliSmp2aWpBaBJOV4eBQkuAttQdqFCxKTU+tSMvMKUFI\r
+       M3FwggznARoeClLDW1yQmFucmQ6RP8WoKCXOWwmSEABJZJTmwfXCksErRnGgV4R5T4NU8QAT\r
+       CVz3K6DBTECDY/lugAwuSURISTUwsgUJpFv4xp1yuMukcFHqRfGf7/4L2KQ3sh6vevDIxrxk\r
+       W8SvxPO7ZyYpZnKdOFnWrOS4eHHrqxs+9z2StvisTvruuYzfKOmf9pQp5j2SYkd1bPeEvpso\r
+       29r1qXNfbfD+s7uqOuMX5mlya6nL/TZPXFIiGLznZNQtNq/Kff/nmRfEu0zs9f6ixFKckWio\r
+       xVxUnAgArX5+tuECAAA=\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: Tue, 25 Dec 2012 05:58:20 -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 |   11 +++++------\r
+ 4 files changed, 20 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..aecc393 100755\r
+--- a/test/dump-restore\r
++++ b/test/dump-restore\r
+@@ -195,23 +195,22 @@ 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
+ 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
+ EOF\r
\r
+ test_expect_equal_file EXPECTED OUTPUT\r
+-- \r
+1.7.10.4\r
+\r