From: David Bremner Date: Thu, 30 Jun 2016 08:40:27 +0000 (+0200) Subject: [PATCH 2/2] WIP: treat notmuch tag without operations as query X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8fa55258ea4a4aa229d55293061f31df42ead00b;p=notmuch-archives.git [PATCH 2/2] WIP: treat notmuch tag without operations as query --- diff --git a/4b/8a178a07bb9cc56b22069d1265b5015f761b79 b/4b/8a178a07bb9cc56b22069d1265b5015f761b79 new file mode 100644 index 000000000..a7dca3d06 --- /dev/null +++ b/4b/8a178a07bb9cc56b22069d1265b5015f761b79 @@ -0,0 +1,147 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id ACAAC6DE035F + for ; Thu, 30 Jun 2016 01:40:53 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.005 +X-Spam-Level: +X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 + tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001] + autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id s1Qjs-vxuQAP for ; + Thu, 30 Jun 2016 01:40:46 -0700 (PDT) +Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) + by arlo.cworth.org (Postfix) with ESMTPS id 5CE066DE014D + for ; Thu, 30 Jun 2016 01:40:43 -0700 (PDT) +Received: from remotemail by fethera.tethera.net with local (Exim 4.84) + (envelope-from ) + id 1bIXWK-0007eJ-3H; Thu, 30 Jun 2016 04:40:24 -0400 +Received: (nullmailer pid 30884 invoked by uid 1000); + Thu, 30 Jun 2016 08:40:30 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [PATCH 2/2] WIP: treat notmuch tag without operations as query +Date: Thu, 30 Jun 2016 10:40:27 +0200 +Message-Id: <1467276027-30633-3-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.8.1 +In-Reply-To: <1467276027-30633-1-git-send-email-david@tethera.net> +References: <87fustdsx9.fsf@zancas.localnet> + <1467276027-30633-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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: Thu, 30 Jun 2016 08:40:53 -0000 + +e.g. + +% notmuch tag # dump all tags +% notmuch tag subject:foo # all tags of messages with foo in the subject +--- + notmuch-tag.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ + 1 file changed, 52 insertions(+), 6 deletions(-) + +diff --git a/notmuch-tag.c b/notmuch-tag.c +index 18d78dd..941c653 100644 +--- a/notmuch-tag.c ++++ b/notmuch-tag.c +@@ -186,6 +186,50 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags, + return ret || warn; + } + ++static int ++_dump_tags (notmuch_config_t *config, const char *query_string) ++{ ++ notmuch_database_t *notmuch; ++ notmuch_tags_t *tags; ++ const char *tag; ++ char *status_string; ++ ++ notmuch_query_t *query; ++ ++ if (notmuch_database_open_verbose (notmuch_config_get_database_path (config), ++ NOTMUCH_DATABASE_MODE_READ_ONLY, ++ ¬much, &status_string)) { ++ if (status_string) { ++ fputs (status_string, stderr); ++ free (status_string); ++ } ++ return EXIT_FAILURE; ++ } ++ ++ query = notmuch_query_create (notmuch, query_string); ++ if (query == NULL) { ++ fprintf (stderr, "Out of memory\n"); ++ return EXIT_FAILURE; ++ } ++ ++ if (print_status_query ("notmuch tag", ++ query, ++ notmuch_query_search_tags (query, &tags))) ++ return 1; ++ ++ for (; ++ notmuch_tags_valid (tags); ++ notmuch_tags_move_to_next (tags)) ++ { ++ tag = notmuch_tags_get (tags); ++ ++ printf ("%s\n", tag); ++ } ++ ++ notmuch_tags_destroy (tags); ++ return EXIT_SUCCESS; ++} ++ + int + notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) + { +@@ -196,6 +240,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) + tag_op_flag_t tag_flags = TAG_FLAG_NONE; + notmuch_bool_t batch = FALSE; + notmuch_bool_t remove_all = FALSE; ++ notmuch_bool_t with_ops = FALSE; + FILE *input = stdin; + char *input_file_name = NULL; + int opt_index; +@@ -248,17 +293,18 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) + &query_string, tag_ops)) + return EXIT_FAILURE; + +- 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 EXIT_FAILURE; +- } ++ if (tag_op_list_size (tag_ops) == 0 && ! remove_all) ++ with_ops = FALSE; + +- if (*query_string == '\0') { +- fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); ++ if (with_ops && *query_string == '\0') { ++ fprintf (stderr, "Error: notmuch tag with operations requires at least one search term.\n"); + return EXIT_FAILURE; + } + } + ++ if (! with_ops) ++ return _dump_tags (config, query_string); ++ + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) + return EXIT_FAILURE; +-- +2.8.1 +