unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: Re: [PATCH 2/4] cli: add --remove-all option to "notmuch tag"
Date: Mon, 25 Feb 2013 21:34:09 +0200	[thread overview]
Message-ID: <87obf8ur0u.fsf@nikula.org> (raw)
In-Reply-To: <e9dd76463809998cdb68bb5078a8d679e98560c2.1358876448.git.jani@nikula.org>

On Tue, 22 Jan 2013, Jani Nikula <jani@nikula.org> wrote:
> Add --remove-all option to "notmuch tag" to remove all tags from the
> messages matching query before applying the tag changes. This allows
> removal of all tags and unconditional setting of the tags of a
> message:
>
> $ notmuch tag --remove-all id:foo@example.com
> $ notmuch tag --remove-all +foo +bar id:foo@example.com
>
> without having to resort to the complicated (and still quoting
> broken):
>
> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \
>   id:foo@example.com
> $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \
>   +foo +bar id:foo@example.com

Just today there was another question on IRC about removing all tags,
and the reply from amdragon was along the lines of the above. This
series would make things so much easier... reviews, anyone? ;)

BR,
Jani.


> ---
>  notmuch-tag.c |   28 ++++++++++++++++++++--------
>  1 file changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/notmuch-tag.c b/notmuch-tag.c
> index b2b22f7..e674215 100644
> --- a/notmuch-tag.c
> +++ b/notmuch-tag.c
> @@ -99,12 +99,15 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
>      notmuch_message_t *message;
>      int ret = NOTMUCH_STATUS_SUCCESS;
>  
> -    /* Optimize the query so it excludes messages that already have
> -     * the specified set of tags. */
> -    query_string = _optimize_tag_query (ctx, query_string, tag_ops);
> -    if (query_string == NULL) {
> -	fprintf (stderr, "Out of memory.\n");
> -	return 1;
> +    if (! (flags & TAG_FLAG_REMOVE_ALL)) {
> +	/* Optimize the query so it excludes messages that already
> +	 * have the specified set of tags. */
> +	query_string = _optimize_tag_query (ctx, query_string, tag_ops);
> +	if (query_string == NULL) {
> +	    fprintf (stderr, "Out of memory.\n");
> +	    return 1;
> +	}
> +	flags |= TAG_FLAG_PRE_OPTIMIZED;
>      }
>  
>      query = notmuch_query_create (notmuch, query_string);
> @@ -120,7 +123,7 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
>  	 notmuch_messages_valid (messages) && ! interrupted;
>  	 notmuch_messages_move_to_next (messages)) {
>  	message = notmuch_messages_get (messages);
> -	ret = tag_op_list_apply (message, tag_ops, flags | TAG_FLAG_PRE_OPTIMIZED);
> +	ret = tag_op_list_apply (message, tag_ops, flags);
>  	notmuch_message_destroy (message);
>  	if (ret != NOTMUCH_STATUS_SUCCESS)
>  	    break;
> @@ -187,6 +190,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>      struct sigaction action;
>      tag_op_flag_t tag_flags = TAG_FLAG_NONE;
>      notmuch_bool_t batch = FALSE;
> +    notmuch_bool_t remove_all = FALSE;
>      FILE *input = stdin;
>      char *input_file_name = NULL;
>      int opt_index;
> @@ -202,6 +206,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>      notmuch_opt_desc_t options[] = {
>  	{ NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },
>  	{ NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },
> +	{ NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },
>  	{ 0, 0, 0, 0, 0 }
>      };
>  
> @@ -224,6 +229,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>  	    fprintf (stderr, "Can't specify both cmdline and stdin!\n");
>  	    return 1;
>  	}
> +	if (remove_all) {
> +	    fprintf (stderr, "Can't specify both --remove-all and --batch\n");
> +	    return 1;
> +	}
>      } else {
>  	tag_ops = tag_op_list_create (ctx);
>  	if (tag_ops == NULL) {
> @@ -235,7 +244,7 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>  				    &query_string, tag_ops))
>  	    return 1;
>  
> -	if (tag_op_list_size (tag_ops) == 0) {
> +	if (tag_op_list_size (tag_ops) == 0 && ! remove_all) {
>  	    fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");
>  	    return 1;
>  	}
> @@ -252,6 +261,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])
>      if (notmuch_config_get_maildir_synchronize_flags (config))
>  	tag_flags |= TAG_FLAG_MAILDIR_SYNC;
>  
> +    if (remove_all)
> +	tag_flags |= TAG_FLAG_REMOVE_ALL;
> +
>      if (batch)
>  	ret = tag_file (ctx, notmuch, tag_flags, input);
>      else
> -- 
> 1.7.10.4

  reply	other threads:[~2013-02-25 19:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 17:41 [PATCH 1/4] cli: make caller check tag count in parse_tag_command_line Jani Nikula
2013-01-22 17:41 ` [PATCH 2/4] cli: add --remove-all option to "notmuch tag" Jani Nikula
2013-02-25 19:34   ` Jani Nikula [this message]
2013-02-25 21:53     ` David Bremner
2013-01-22 17:41 ` [PATCH 3/4] man: document notmuch tag --remove-all Jani Nikula
2013-01-22 17:41 ` [PATCH 4/4] test: " Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87obf8ur0u.fsf@nikula.org \
    --to=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).