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