unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* v7 batch tagging series
@ 2012-12-14 13:34 david
  2012-12-14 13:34 ` [Patch v7 01/14] parse_tag_line: use enum for return value david
                   ` (13 more replies)
  0 siblings, 14 replies; 29+ messages in thread
From: david @ 2012-12-14 13:34 UTC (permalink / raw)
  To: notmuch


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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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 <bremner@debian.org>
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;
 }

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2012-12-16  3:39 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-14 13:34 v7 batch tagging series david
2012-12-14 13:34 ` [Patch v7 01/14] parse_tag_line: use enum for return value david
2012-12-14 13:34 ` [Patch v7 02/14] tag-util: factor out rules for illegal tags, use in parse_tag_line david
2012-12-14 13:34 ` [Patch v7 03/14] notmuch-tag.c: convert to use tag-utils david
2012-12-14 13:34 ` [Patch v7 04/14] notmuch-tag: factor out double quoting routine david
2012-12-15 17:55   ` Mark Walters
2012-12-15 22:20   ` Jani Nikula
2012-12-14 13:34 ` [Patch v7 05/14] quote_and_decode_query: new function to quote hex-decoded queries david
2012-12-15 17:49   ` Mark Walters
2012-12-15 18:58     ` David Bremner
2012-12-15 20:09       ` [PATCH] fixup for hex encoding desription in notmuch-tag.1 david
2012-12-15 23:10         ` Jani Nikula
2012-12-15 23:21   ` [Patch v7 05/14] quote_and_decode_query: new function to quote hex-decoded queries Jani Nikula
2012-12-16  3:39     ` David Bremner
2012-12-14 13:34 ` [Patch v7 06/14] notmuch-restore: move query handling for batch restore to parser david
2012-12-15 17:54   ` Mark Walters
2012-12-15 18:18     ` David Bremner
2012-12-15 19:21     ` [PATCH] fixup: clarify TAG_FLAG_ID_ONLY comments and name david
2012-12-15 23:04   ` [Patch v7 06/14] notmuch-restore: move query handling for batch restore to parser Jani Nikula
2012-12-14 13:34 ` [Patch v7 07/14] cli: add support for batch tagging operations to "notmuch tag" david
2012-12-15 23:14   ` Jani Nikula
2012-12-16  0:23   ` [PATCH] " david
2012-12-14 13:34 ` [Patch v7 08/14] test/tagging: add test for error messages of tag --batch david
2012-12-14 13:34 ` [Patch v7 09/14] test/tagging: add basic tests for batch tagging functionality david
2012-12-14 13:34 ` [Patch v7 10/14] test/tagging: add tests for exotic tags david
2012-12-14 13:34 ` [Patch v7 11/14] test/tagging: add test for exotic message-ids and batch tagging david
2012-12-14 13:34 ` [Patch v7 12/14] test/tagging: add test for compound queries with " david
2012-12-14 13:34 ` [Patch v7 13/14] notmuch-tag.1: tidy synopsis formatting david
2012-12-14 13:34 ` [Patch v7 14/14] man: document notmuch tag --batch, --input options david

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).