Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 374B4431FBC for ; Fri, 14 Dec 2012 05:34:39 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VVX6iSdW25BS for ; Fri, 14 Dec 2012 05:34:35 -0800 (PST) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B506D431FB6 for ; Fri, 14 Dec 2012 05:34:35 -0800 (PST) Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net ([142.167.90.129] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1TjVPM-0004ya-F6 for notmuch@notmuchmail.org; Fri, 14 Dec 2012 09:34:35 -0400 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1TjVPG-00021h-Uk for notmuch@notmuchmail.org; Fri, 14 Dec 2012 09:34:26 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Subject: v7 batch tagging series Date: Fri, 14 Dec 2012 09:34:08 -0400 Message-Id: <1355492062-7546-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.10.4 X-Spam_bar: - X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2012 13:34:39 -0000 This obsoletes id:1355096008-4544-1-git-send-email-david@tethera.net There are some fixups according to previous reviews, detailed in a diff at the end. I have just read id:871uettxln.fsf@qmul.ac.uk; this series doesn't respond to that. There are some new trivial cosmetic patches; except for conflicts these don't really need to be part of this series. [Patch v7 01/14] parse_tag_line: use enum for return value. [Patch v7 13/14] notmuch-tag.1: tidy synopsis formatting This version includes a bunch of test patches (patches 8-12). The other reason for the increase in the number of patches is that I discovered a bug in the previous version (when I implement patch 11/14), and I had to add some internal quoting for queries: [Patch v7 04/14] notmuch-tag: factor out double quoting routine [Patch v7 05/14] quote_and_decode_query: new function to quote [Patch v7 06/14] notmuch-restore: move query handling for batch commit 6f4a8ac5fb90b301bc905c4ea90cdf33456eb06e Author: David Bremner Date: Tue Dec 11 22:12:50 2012 -0400 formatting fixup for illegal_tag diff --git a/tag-util.c b/tag-util.c index 2214f34..091e1ec 100644 --- a/tag-util.c +++ b/tag-util.c @@ -39,17 +39,18 @@ line_error (tag_parse_status_t status, */ static const char * -illegal_tag (const char *tag, notmuch_bool_t remove) { +illegal_tag (const char *tag, notmuch_bool_t remove) +{ - if (*tag == '\0' && !remove) + if (*tag == '\0' && ! remove) return "adding empty tag"; /* This disallows adding the non-removable tag "-" and * enables notmuch tag to take long options more easily. */ - if (*tag == '-' && !remove) - return "adding tag starting with -"; + if (*tag == '-' && ! remove) + return "adding tag starting with -"; return NULL; } commit 60ca31c81adfb3b9c2ca6e2d2eaee6fcc483ea97 Author: David Bremner Date: Tue Dec 11 22:17:48 2012 -0400 uncrustify fixup for parse_tag_command_line diff --git a/tag-util.c b/tag-util.c index 091e1ec..30d856d 100644 --- a/tag-util.c +++ b/tag-util.c @@ -45,8 +45,9 @@ illegal_tag (const char *tag, notmuch_bool_t remove) if (*tag == '\0' && ! remove) return "adding empty tag"; - /* This disallows adding the non-removable tag "-" and - * enables notmuch tag to take long options more easily. + /* This disallows adding tags starting with "-", in particular the + * non-removable tag "-" and enables notmuch tag to take long + * options more easily. */ if (*tag == '-' && ! remove) @@ -165,12 +166,13 @@ parse_tag_line (void *ctx, char *line, int parse_tag_command_line (void *ctx, int argc, char **argv, - unused(tag_op_flag_t flags), - char **query_str, tag_op_list_t *tag_ops){ + unused (tag_op_flag_t flags), + char **query_str, tag_op_list_t *tag_ops) +{ int i; - tag_op_list_reset(tag_ops); + tag_op_list_reset (tag_ops); for (i = 0; i < argc; i++) { if (strcmp (argv[i], "--") == 0) { @@ -182,7 +184,7 @@ parse_tag_command_line (void *ctx, int argc, char **argv, notmuch_bool_t is_remove = argv[i][0] == '-'; const char *msg; - msg = illegal_tag(argv[i]+1, is_remove); + msg = illegal_tag (argv[i] + 1, is_remove); if (msg) { fprintf (stderr, "Error: %s", msg); return 1; commit f3ae405abda331558affedf52391a067acc7b7df Author: David Bremner Date: Tue Dec 11 22:21:46 2012 -0400 remove unused flags diff --git a/notmuch-tag.c b/notmuch-tag.c index 2665037..a5e8715 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -242,7 +242,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) } if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index, - 0, &query_string, tag_ops)) + &query_string, tag_ops)) return 1; } diff --git a/tag-util.c b/tag-util.c index 30d856d..e7ee182 100644 --- a/tag-util.c +++ b/tag-util.c @@ -166,7 +166,6 @@ parse_tag_line (void *ctx, char *line, int parse_tag_command_line (void *ctx, int argc, char **argv, - unused (tag_op_flag_t flags), char **query_str, tag_op_list_t *tag_ops) { diff --git a/tag-util.h b/tag-util.h index 4956725..2889736 100644 --- a/tag-util.h +++ b/tag-util.h @@ -85,7 +85,6 @@ parse_tag_line (void *ctx, char *line, tag_parse_status_t parse_tag_command_line (void *ctx, int argc, char **argv, - tag_op_flag_t flags, char **query_str, tag_op_list_t *ops); /* commit c1aa36573bb991a1d06dd2e234a2377e2a32bd66 Author: David Bremner Date: Tue Dec 11 22:25:40 2012 -0400 use enum values in parse_tag_command_line diff --git a/tag-util.c b/tag-util.c index e7ee182..102adcc 100644 --- a/tag-util.c +++ b/tag-util.c @@ -164,7 +164,7 @@ parse_tag_line (void *ctx, char *line, return ret; } -int +tag_parse_status_t parse_tag_command_line (void *ctx, int argc, char **argv, char **query_str, tag_op_list_t *tag_ops) { @@ -186,7 +186,7 @@ parse_tag_command_line (void *ctx, int argc, char **argv, msg = illegal_tag (argv[i] + 1, is_remove); if (msg) { fprintf (stderr, "Error: %s", msg); - return 1; + return TAG_PARSE_INVALID; } tag_op_list_append (ctx, tag_ops, @@ -198,17 +198,17 @@ parse_tag_command_line (void *ctx, int argc, char **argv, if (tag_op_list_size (tag_ops) == 0) { fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); - return 1; + return TAG_PARSE_INVALID; } *query_str = query_string_from_args (ctx, argc - i, &argv[i]); if (**query_str == '\0') { fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); - return 1; + return TAG_PARSE_INVALID; } - return 0; + return TAG_PARSE_SUCCESS; } commit 562200240098238211d2ea0299b2ae03f4dbe919 Author: David Bremner Date: Tue Dec 11 22:32:31 2012 -0400 remaining changes for id:87k3spa9nk.fsf@nikula.org diff --git a/tag-util.c b/tag-util.c index 102adcc..43d19e1 100644 --- a/tag-util.c +++ b/tag-util.c @@ -179,21 +179,19 @@ parse_tag_command_line (void *ctx, int argc, char **argv, break; } - if (argv[i][0] == '+' || argv[i][0] == '-') { - notmuch_bool_t is_remove = argv[i][0] == '-'; - const char *msg; + if (argv[i][0] != '+' && argv[i][0] != '-') + break; - msg = illegal_tag (argv[i] + 1, is_remove); - if (msg) { - fprintf (stderr, "Error: %s", msg); - return TAG_PARSE_INVALID; - } + notmuch_bool_t is_remove = argv[i][0] == '-'; + const char *msg; - tag_op_list_append (ctx, tag_ops, - argv[i] + 1, (argv[i][0] == '-')); - } else { - break; + msg = illegal_tag (argv[i] + 1, is_remove); + if (msg) { + fprintf (stderr, "Error: %s", msg); + return TAG_PARSE_INVALID; } + + tag_op_list_append (ctx, tag_ops, argv[i] + 1, is_remove); } if (tag_op_list_size (tag_ops) == 0) { @@ -203,7 +201,7 @@ parse_tag_command_line (void *ctx, int argc, char **argv, *query_str = query_string_from_args (ctx, argc - i, &argv[i]); - if (**query_str == '\0') { + if (*query_str == NULL || **query_str == '\0') { fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); return TAG_PARSE_INVALID; } commit c991402c6571003b79e855965fe1e3b6ae2dde35 Author: David Bremner Date: Tue Dec 11 22:35:52 2012 -0400 "fix" comment about tag_op_list; assume tag-utils.h docs are sufficient. diff --git a/notmuch-tag.c b/notmuch-tag.c index a5e8715..508f04d 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -108,9 +108,8 @@ _optimize_tag_query (void *ctx, const char *orig_query_string, return query_string; } -/* Tag messages matching 'query_string' according to 'tag_ops', which - * must be an array of tagging operations terminated with an empty - * element. */ +/* Tag messages matching 'query_string' according to 'tag_ops' + */ static int tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string, tag_op_list_t *tag_ops, tag_op_flag_t flags) commit 80628aceff38cad5f48e0ec7f381bbf8cec85cb2 Author: David Bremner Date: Tue Dec 11 22:44:17 2012 -0400 slightly longwindedly make sure we return non-zero if tag_query fails diff --git a/notmuch-tag.c b/notmuch-tag.c index 508f04d..8f700b0 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -174,8 +174,11 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags, if (ret > 0) continue; - if (ret < 0 || tag_query (ctx, notmuch, query_string, - tag_ops, flags)) + if (ret < 0) + break; + + ret = tag_query (ctx, notmuch, query_string, tag_ops, flags); + if (ret) break; } commit d1be30ed7eab8a1e9e0a492c0f024880f63236bb Author: David Bremner Date: Tue Dec 11 22:44:30 2012 -0400 close an input file if we opened it diff --git a/notmuch-tag.c b/notmuch-tag.c index 8f700b0..b707c25 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -264,6 +264,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]) else ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags); + if (input != stdin) + fclose (input); + notmuch_database_destroy (notmuch); return ret || interrupted; commit 702a2b11d43616f9b2ad74fb772ad080c228ab0a Author: David Bremner Date: Tue Dec 11 23:37:51 2012 -0400 fixup for illegal_tag error messages diff --git a/tag-util.c b/tag-util.c index 43d19e1..f89669a 100644 --- a/tag-util.c +++ b/tag-util.c @@ -43,7 +43,7 @@ illegal_tag (const char *tag, notmuch_bool_t remove) { if (*tag == '\0' && ! remove) - return "adding empty tag"; + return "empty tag forbidden"; /* This disallows adding tags starting with "-", in particular the * non-removable tag "-" and enables notmuch tag to take long @@ -51,7 +51,7 @@ illegal_tag (const char *tag, notmuch_bool_t remove) */ if (*tag == '-' && ! remove) - return "adding tag starting with -"; + return "tag starting with '-' forbidden"; return NULL; }