Re: [RFC PATCH] cli: add --remove-all option to "notmuch tag"
authorJani Nikula <jani@nikula.org>
Sun, 16 Dec 2012 21:48:14 +0000 (23:48 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:26 +0000 (09:52 -0800)
f0/4eacfc61d2c00caf51e2e58051cc0352bb1ec5 [new file with mode: 0644]

diff --git a/f0/4eacfc61d2c00caf51e2e58051cc0352bb1ec5 b/f0/4eacfc61d2c00caf51e2e58051cc0352bb1ec5
new file mode 100644 (file)
index 0000000..f8cde60
--- /dev/null
@@ -0,0 +1,223 @@
+Return-Path: <jani@nikula.org>\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 795CC431FBD\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48: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 ZlZWMFG1c0Cb for <notmuch@notmuchmail.org>;\r
+       Sun, 16 Dec 2012 13:48:19 -0800 (PST)\r
+Received: from mail-la0-f53.google.com (mail-la0-f53.google.com\r
+       [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 6F5FF431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48:19 -0800 (PST)\r
+Received: by mail-la0-f53.google.com with SMTP id w12so4059950lag.26\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 13:48:18 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type:x-gm-message-state;\r
+       bh=eyJai2mtLLAKnWyPMdxZJxsMfADnx7mTUnasHYdQ1lU=;\r
+       b=ewzpzCYAsBHWXNxmprsRC6+xgR5sLuyH1+9a2X0bGRZtU+zCwNwTqMAuOKyRCOEulo\r
+       eYpiWxtW7wgzu0lZ7CsZQQt34fOvtAtm8eKQ+h5k+JLHgiLfrOQ8TbRMsl+fNJzGfPHv\r
+       g8aDJx0WtLiZH/l7R0swkBY03517b1vujr9tpAC/YrdEZ83reg1F8gmrJqTY5b1KR/lX\r
+       iVks08nWI8epJ5Zru1vlbG1T/gkmIGvoVDrx9Fftl8KAdqCsvQUnI1iGC3238Zg8eyc4\r
+       cu99wkl43sjTYfNrx8y6kaXD5YYDqbehJVWKRjm8pJCHXpLpghxqFjH1pnG1BbV6R+Uc\r
+       ecxw==\r
+Received: by 10.112.29.229 with SMTP id n5mr5150374lbh.130.1355694497595;\r
+       Sun, 16 Dec 2012 13:48:17 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id lr20sm4100098lab.17.2012.12.16.13.48.15\r
+       (version=SSLv3 cipher=OTHER); Sun, 16 Dec 2012 13:48:16 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [RFC PATCH] cli: add --remove-all option to "notmuch tag"\r
+In-Reply-To: <87fw35enmv.fsf@qmul.ac.uk>\r
+References: <1354572764-28701-1-git-send-email-jani@nikula.org>\r
+       <87fw35enmv.fsf@qmul.ac.uk>\r
+User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sun, 16 Dec 2012 23:48:14 +0200\r
+Message-ID: <87licxpt29.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQmCOxZYtcZKI2tUdMbHHxWVeCbd+HpmyrlID6OcwTHz71hyTWqIHAoP2m+BJuz0CUBHdOKV\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: Sun, 16 Dec 2012 21:48:20 -0000\r
+\r
+On Sun, 16 Dec 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> On Mon, 03 Dec 2012, Jani Nikula <jani@nikula.org> wrote:\r
+>> Add --remove-all option to "notmuch tag" to remove all tags matching\r
+>> query before applying the tag changes. This allows removal and\r
+>> unconditional setting of the tags of a message:\r
+>>\r
+>> $ notmuch tag --remove-all id:foo@example.com\r
+>> $ notmuch tag --remove-all +foo +bar id:foo@example.com\r
+>>\r
+>> without having to resort to the complicated (and still quoting broken):\r
+>>\r
+>> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') id:foo@example.com\r
+>> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') +foo +bar id:foo@example.com\r
+>>\r
+>> ---\r
+>>\r
+>> It's completely untested...\r
+>>\r
+>> This is on top of David's batch tagging branch new-tagging at\r
+>> git://pivot.cs.unb.ca/notmuch.git\r
+>>\r
+>> If there's interest, I'll spin a new version with tests and man page\r
+>> changes after David's stuff has been merged.\r
+>\r
+> I like this: the possibility of setting the tags to something seems\r
+> nice. \r
+\r
+Thanks for the feedback; I'll rebase once we're done with the batch\r
+tagging stuff.\r
+\r
+> I am not very keen on the option name but don't have anything much\r
+> better: maybe --remove-all-first or --set-to? \r
+\r
+I still like --remove-all, and, like you say, those aren't much\r
+better. But we can bikeshed this later. ;)\r
+\r
+> Incidentally, does this (or should this) give an error if the user calls\r
+> --remove-all with -some_tag (as opposed to +some_tag)?\r
+\r
+I think not. There are no errors if you do -foo -foo, or remove a tag\r
+that isn't in any of the messages matching query.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+>\r
+> Best wishes\r
+>\r
+> Mark\r
+>\r
+>\r
+>> ---\r
+>>  notmuch-tag.c |   32 ++++++++++++++++++++------------\r
+>>  1 file changed, 20 insertions(+), 12 deletions(-)\r
+>>\r
+>> diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+>> index e4fca67..67624cc 100644\r
+>> --- a/notmuch-tag.c\r
+>> +++ b/notmuch-tag.c\r
+>> @@ -119,12 +119,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+>>      notmuch_messages_t *messages;\r
+>>      notmuch_message_t *message;\r
+>>  \r
+>> -    /* Optimize the query so it excludes messages that already have\r
+>> -     * the specified set of tags. */\r
+>> -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
+>> -    if (query_string == NULL) {\r
+>> -   fprintf (stderr, "Out of memory.\n");\r
+>> -   return 1;\r
+>> +    if (! (flags & TAG_FLAG_REMOVE_ALL)) {\r
+>> +   /* Optimize the query so it excludes messages that already\r
+>> +    * have the specified set of tags. */\r
+>> +   query_string = _optimize_tag_query (ctx, query_string, tag_ops);\r
+>> +   if (query_string == NULL) {\r
+>> +       fprintf (stderr, "Out of memory.\n");\r
+>> +       return 1;\r
+>> +   }\r
+>> +   flags |= TAG_FLAG_PRE_OPTIMIZED;\r
+>>      }\r
+>>  \r
+>>      query = notmuch_query_create (notmuch, query_string);\r
+>> @@ -140,7 +143,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+>>      notmuch_messages_valid (messages) && ! interrupted;\r
+>>      notmuch_messages_move_to_next (messages)) {\r
+>>     message = notmuch_messages_get (messages);\r
+>> -   tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED);\r
+>> +   tag_op_list_apply (message, tag_ops, flags);\r
+>>     notmuch_message_destroy (message);\r
+>>      }\r
+>>  \r
+>> @@ -157,8 +160,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>>      notmuch_config_t *config;\r
+>>      notmuch_database_t *notmuch;\r
+>>      struct sigaction action;\r
+>> -    tag_op_flag_t synchronize_flags = TAG_FLAG_NONE;\r
+>> +    tag_op_flag_t flags = TAG_FLAG_NONE;\r
+>>      notmuch_bool_t batch = FALSE;\r
+>> +    notmuch_bool_t remove_all = FALSE;\r
+>>      FILE *input = stdin;\r
+>>      char *input_file_name = NULL;\r
+>>      int i, opt_index;\r
+>> @@ -174,6 +178,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>>      notmuch_opt_desc_t options[] = {\r
+>>     { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
+>>     { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+>> +   { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },\r
+>>     { 0, 0, 0, 0, 0 }\r
+>>      };\r
+>>  \r
+>> @@ -230,7 +235,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>>         }\r
+>>     }\r
+>>  \r
+>> -   if (tag_op_list_size (tag_ops) == 0) {\r
+>> +   if (tag_op_list_size (tag_ops) == 0 && !remove_all) {\r
+>>         fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
+>>         return 1;\r
+>>     }\r
+>> @@ -252,7 +257,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>>     return 1;\r
+>>  \r
+>>      if (notmuch_config_get_maildir_synchronize_flags (config))\r
+>> -   synchronize_flags = TAG_FLAG_MAILDIR_SYNC;\r
+>> +   flags |= TAG_FLAG_MAILDIR_SYNC;\r
+>> +\r
+>> +    if (remove_all)\r
+>> +   flags |= TAG_FLAG_REMOVE_ALL;\r
+>>  \r
+>>      if (batch) {\r
+>>  \r
+>> @@ -280,14 +288,14 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>>             continue;\r
+>>  \r
+>>         if (ret < 0 || tag_query (ctx, notmuch, query_string,\r
+>> -                                 tag_ops, synchronize_flags))\r
+>> +                                 tag_ops, flags))\r
+>>             break;\r
+>>     }\r
+>>  \r
+>>     if (line)\r
+>>         free (line);\r
+>>      } else\r
+>> -   ret = tag_query (ctx, notmuch, query_string, tag_ops, synchronize_flags);\r
+>> +   ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);\r
+>>  \r
+>>      notmuch_database_destroy (notmuch);\r
+>>  \r
+>> -- \r
+>> 1.7.10.4\r
+>>\r
+>> _______________________________________________\r
+>> notmuch mailing list\r
+>> notmuch@notmuchmail.org\r
+>> http://notmuchmail.org/mailman/listinfo/notmuch\r