v4 of Hex Dump/Restore patches
authordavid <david@tethera.net>
Sat, 8 Dec 2012 15:07:46 +0000 (11:07 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:47 +0000 (09:51 -0800)
48/21c33247378c00bbb4c5db425f2886974acfae [new file with mode: 0644]

diff --git a/48/21c33247378c00bbb4c5db425f2886974acfae b/48/21c33247378c00bbb4c5db425f2886974acfae
new file mode 100644 (file)
index 0000000..8edb0dd
--- /dev/null
@@ -0,0 +1,374 @@
+Return-Path: <bremner@tethera.net>\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 01AC3431FBF\r
+       for <notmuch@notmuchmail.org>; Sat,  8 Dec 2012 07:08:13 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 sR+Ca-s+JqAZ for <notmuch@notmuchmail.org>;\r
+       Sat,  8 Dec 2012 07:08:11 -0800 (PST)\r
+Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
+       (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 2117F431FAE\r
+       for <notmuch@notmuchmail.org>; Sat,  8 Dec 2012 07:08:11 -0800 (PST)\r
+Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
+       ([142.167.90.129] helo=zancas.localnet)\r
+       by tesseract.cs.unb.ca with esmtpsa\r
+       (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
+       (envelope-from <bremner@tethera.net>) id 1ThM0f-0005dJ-AC\r
+       for notmuch@notmuchmail.org; Sat, 08 Dec 2012 11:08:10 -0400\r
+Received: from bremner by zancas.localnet with local (Exim 4.80)\r
+       (envelope-from <bremner@tethera.net>) id 1ThM0Z-0005GY-Nn\r
+       for notmuch@notmuchmail.org; Sat, 08 Dec 2012 11:08:03 -0400\r
+From: david@tethera.net\r
+To: notmuch@notmuchmail.org\r
+Subject: v4 of Hex Dump/Restore patches\r
+Date: Sat,  8 Dec 2012 11:07:46 -0400\r
+Message-Id: <1354979276-20099-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.10.4\r
+X-Spam_bar: -\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: Sat, 08 Dec 2012 15:08:13 -0000\r
+\r
+This obsoletes the series at\r
+     \r
+     id:1354843607-17980-1-git-send-email-david@tethera.net\r
+\r
+One new patch:\r
+\r
+[Patch v4 08/10] test/dump-restore: add test for warning/error\r
+\r
+Other changes since the last series are as follows:\r
+\r
+commit 16ca0f8126fafd49266ffa02534f2e9b73c03027\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Fri Dec 7 20:19:21 2012 -0400\r
+\r
+    fixup for test/dump-restore\r
+\r
+diff --git a/test/dump-restore b/test/dump-restore\r
+index 2532cbb..b267792 100755\r
+--- a/test/dump-restore\r
++++ b/test/dump-restore\r
+@@ -212,7 +212,7 @@ test_expect_equal_file EXPECTED OUTPUT\r
\r
+ test_begin_subtest 'roundtripping random message-ids and tags'\r
\r
+-    ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG}\r
++    ${TEST_DIRECTORY}/random-corpus --config-path=${NOTMUCH_CONFIG} \\r
+                       --num-messages=100\r
\r
+      notmuch dump --format=batch-tag| \\r
+\r
+commit 9d864bd724bd2d2b26b5d52e3e2f28b4fff2046f\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Fri Dec 7 20:32:50 2012 -0400\r
+\r
+    fixup for tag-util.c: put * in right palce\r
+\r
+diff --git a/tag-util.h b/tag-util.h\r
+index df05d72..6674674 100644\r
+--- a/tag-util.h\r
++++ b/tag-util.h\r
+@@ -62,8 +62,8 @@ parse_tag_line (void *ctx, char *line,\r
+  * ctx is passed to talloc\r
+  */\r
\r
+-tag_op_list_t\r
+-*tag_op_list_create (void *ctx);\r
++tag_op_list_t *\r
++tag_op_list_create (void *ctx);\r
\r
+ /*\r
+  * Add a tag operation (delete iff remove == TRUE) to a list.\r
+\r
+commit d2cead797981e8992849e1d96ad95177b42290e2\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Fri Dec 7 20:57:52 2012 -0400\r
+\r
+    fixup for id:87txrxxyzp.fsf@nikula.org\r
+\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 3d54e9e..a927363 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -24,9 +24,15 @@ parse_tag_line (void *ctx, char *line,\r
+ {\r
+     char *tok = line;\r
+     size_t tok_len = 0;\r
+-    char *line_for_error = talloc_strdup (ctx, line);\r
++    char *line_for_error;\r
+     int ret = 0;\r
\r
++    line_for_error = talloc_strdup (ctx, line);\r
++    if (line_for_error == NULL) {\r
++      fprintf (stderr, "Error: out of memory\n");\r
++      return -1;\r
++    }\r
++\r
+     chomp_newline (line);\r
\r
+     /* remove leading space */\r
+@@ -58,7 +64,7 @@ parse_tag_line (void *ctx, char *line,\r
\r
+       /* If tag is terminated by NUL, there's no query string. */\r
+       if (*(tok + tok_len) == '\0') {\r
+-          fprintf (stderr, "no query string: %s\n", line_for_error);\r
++          fprintf (stderr, "Warning: no query string: %s\n", line_for_error);\r
+           ret = 1;\r
+           goto DONE;\r
+       }\r
+@@ -71,19 +77,21 @@ parse_tag_line (void *ctx, char *line,\r
\r
+       /* Maybe refuse empty tags. */\r
+       if (! (flags & TAG_FLAG_BE_GENEROUS) && *tag == '\0') {\r
+-          fprintf (stderr, "Error: empty tag: %s\n", line_for_error);\r
++          fprintf (stderr, "Warning: empty tag: %s\n", line_for_error);\r
++          ret = 1;\r
+           goto DONE;\r
+       }\r
\r
+       /* Decode tag. */\r
+       if (hex_decode_inplace (tag) != HEX_SUCCESS) {\r
+-          fprintf (stderr, "Hex decoding of tag %s failed\n",\r
++          fprintf (stderr, "Warning: Hex decoding of tag %s failed\n",\r
+                    tag);\r
+           ret = 1;\r
+           goto DONE;\r
+       }\r
\r
+       if (tag_op_list_append (ctx, tag_ops, tag, remove)) {\r
++          /* diagnostics already printed */\r
+           ret = -1;\r
+           goto DONE;\r
+       }\r
+@@ -98,7 +106,7 @@ parse_tag_line (void *ctx, char *line,\r
\r
+     /* tok now points to the query string */\r
+     if (hex_decode_inplace (tok) != HEX_SUCCESS) {\r
+-      fprintf (stderr, "Hex decoding of query %s failed\n",\r
++      fprintf (stderr, "Warning: Hex decoding of query %s failed\n",\r
+                tok);\r
+       ret = 1;\r
+       goto DONE;\r
+\r
+commit 162c20ab6d9b9eef56cb2b966a7144a61557eade\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 07:29:56 2012 -0400\r
+\r
+    fixup for id:87624chmfw.fsf@qmul.ac.uk\r
+    \r
+    update comment\r
+\r
+diff --git a/util/string-util.h b/util/string-util.h\r
+index 696da40..ac7676c 100644\r
+--- a/util/string-util.h\r
++++ b/util/string-util.h\r
+@@ -3,7 +3,10 @@\r
\r
+ #include <string.h>\r
\r
+-/* like strtok(3), but without state, and doesn't modify s. usage pattern:\r
++/* like strtok(3), but without state, and doesn't modify s.  Return\r
++ * value is indicated by pointer and length, not null terminator.\r
++ *\r
++ * Usage pattern:\r
+  *\r
+  * const char *tok = input;\r
+  * const char *delim = " \t";\r
+\r
+commit 590adeec072f235861154b930bfb10bedbe37e8a\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 07:42:44 2012 -0400\r
+\r
+    fixup for id:8738zghl6d.fsf@qmul.ac.uk\r
+\r
+diff --git a/tag-util.c b/tag-util.c\r
+index a927363..c97d240 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -98,8 +98,6 @@ parse_tag_line (void *ctx, char *line,\r
+     }\r
\r
+     if (tok == NULL) {\r
+-      fprintf (stderr, "Warning: Ignoring invalid input line: %s\n",\r
+-               line_for_error);\r
+       ret = 1;\r
+       goto DONE;\r
+     }\r
+@@ -113,7 +111,13 @@ parse_tag_line (void *ctx, char *line,\r
+     }\r
\r
+     *query_string = tok;\r
++\r
+   DONE:\r
++    if (ret != 0)\r
++      fprintf (stderr, "% invalid input line %s\n",\r
++               ret == 1 ? "Warning: Ignoring" : "Error: Failing at",\r
++               line_for_error);\r
++\r
+     talloc_free (line_for_error);\r
+     return ret;\r
+ }\r
+\r
+commit 6002e08eb048612f5ef4eab3205a2887e1ab3f02\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 07:46:39 2012 -0400\r
+\r
+    fixup: chomp line before copy\r
+\r
+diff --git a/tag-util.c b/tag-util.c\r
+index c97d240..8e6b1ef 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -27,14 +27,14 @@ parse_tag_line (void *ctx, char *line,\r
+     char *line_for_error;\r
+     int ret = 0;\r
\r
++    chomp_newline (line);\r
++\r
+     line_for_error = talloc_strdup (ctx, line);\r
+     if (line_for_error == NULL) {\r
+       fprintf (stderr, "Error: out of memory\n");\r
+       return -1;\r
+     }\r
\r
+-    chomp_newline (line);\r
+-\r
+     /* remove leading space */\r
+     while (*tok == ' ' || *tok == '\t')\r
+       tok++;\r
+\r
+commit 9c4878bf0ad0e1f60a45c963998a20635fc234af\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 08:36:48 2012 -0400\r
+\r
+    further fixup for error messages\r
+\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 8e6b1ef..6018d49 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -41,7 +41,7 @@ parse_tag_line (void *ctx, char *line,\r
\r
+     /* Skip empty and comment lines. */\r
+     if (*tok == '\0' || *tok == '#') {\r
+-      ret = 1;\r
++      ret = 2;\r
+       goto DONE;\r
+     }\r
\r
+@@ -55,6 +55,8 @@ parse_tag_line (void *ctx, char *line,\r
+       /* Optional explicit end of tags marker. */\r
+       if (tok_len == 2 && strncmp (tok, "--", tok_len) == 0) {\r
+           tok = strtok_len (tok + tok_len, " ", &tok_len);\r
++          if (tok == NULL)\r
++              fprintf (stderr, "Warning: no query string: %s\n", line_for_error);\r
+           break;\r
+       }\r
\r
+@@ -113,8 +115,8 @@ parse_tag_line (void *ctx, char *line,\r
+     *query_string = tok;\r
\r
+   DONE:\r
+-    if (ret != 0)\r
+-      fprintf (stderr, "% invalid input line %s\n",\r
++    if ((ret % 2) != 0)\r
++      fprintf (stderr, "%s invalid input line %s\n",\r
+                ret == 1 ? "Warning: Ignoring" : "Error: Failing at",\r
+                line_for_error);\r
\r
+diff --git a/tag-util.h b/tag-util.h\r
+index 6674674..1d564f0 100644\r
+--- a/tag-util.h\r
++++ b/tag-util.h\r
+@@ -45,7 +45,10 @@ typedef enum {\r
+  * Leading and trailing space ' ' is ignored. Empty lines and lines\r
+  * beginning with '#' are ignored.\r
+  *\r
+- * Returns: 0 for OK, 1 for skipped line, -1 for fatal(ish) error.\r
++ * Returns:   0       OK,\r
++ *            1       skipped (invalid) line\r
++ *            2       skipped (valid)\r
++ *            -1      fatal(ish) error.\r
+  *\r
+  * Output Parameters:\r
+  *    ops     contains a list of tag operations\r
+\r
+commit 6e8a7b30e3980f77724d6005292265d49ad5241a\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 08:41:01 2012 -0400\r
+\r
+    fixup for id:87wqwsg46p.fsf@qmul.ac.uk\r
+\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index ceec2d3..44bf88d 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -56,6 +56,11 @@ tag_message (unused (void *ctx),\r
+     return ret;\r
+ }\r
\r
++/* Sup dump output is one line per message. We match a sequence of\r
++ * non-space characters for the message-id, then one or more\r
++ * spaces, then a list of space-separated tags as a sequence of\r
++ * characters within literal '(' and ')'. */\r
++\r
+ static int\r
+ parse_sup_line (void *ctx, char *line,\r
+               char **query_str, tag_op_list_t *tag_ops)\r
+@@ -172,11 +177,6 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+                argv[opt_index]);\r
+       return 1;\r
+     }\r
+-\r
+-    /* Dump output is one line per message. We match a sequence of\r
+-     * non-space characters for the message-id, then one or more\r
+-     * spaces, then a list of space-separated tags as a sequence of\r
+-     * characters within literal '(' and ')'. */\r
+     char *p;\r
\r
+     line_len = getline (&line, &line_size, input);\r
+\r
+commit ee198b0d388243f0f43fab1d7ef7acbea5bdb3e6\r
+Author: David Bremner <bremner@debian.org>\r
+Date:   Sat Dec 8 08:52:51 2012 -0400\r
+\r
+    fixup: rewrite confusing for loop as while.\r
+\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 6018d49..b68ea50 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -157,8 +157,10 @@ makes_changes (notmuch_message_t *message,\r
+       const char *cur_tag = notmuch_tags_get (tags);\r
+       int last_op =  (flags & TAG_FLAG_REMOVE_ALL) ? -1 : 0;\r
\r
+-      /* slight contortions to count down with an unsigned index */\r
+-      for (i = list->count; i-- > 0; /*nothing*/) {\r
++      /* scan backwards to get last operation */\r
++      i = list->count;\r
++      while (i > 0) {\r
++          i--;\r
+           if (strcmp (cur_tag, list->ops[i].tag) == 0) {\r
+               last_op = list->ops[i].remove ? -1 : 1;\r
+               break;\r