From: David Edmondson Date: Fri, 31 Oct 2014 07:14:19 +0000 (+0000) Subject: Re: [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=07ddb313cf3445bf5c173cc450c1194fe2dc6bdc;p=notmuch-archives.git Re: [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages --- diff --git a/8f/9c5483a08ce285eaffc600623bd05512671805 b/8f/9c5483a08ce285eaffc600623bd05512671805 new file mode 100644 index 000000000..c778bf4ac --- /dev/null +++ b/8f/9c5483a08ce285eaffc600623bd05512671805 @@ -0,0 +1,172 @@ +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 F17DA431FC9 + for ; Fri, 31 Oct 2014 00:14:27 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.699 +X-Spam-Level: +X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001] + 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 k2rIsqwhffje for ; + Fri, 31 Oct 2014 00:14:23 -0700 (PDT) +Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com + [74.125.82.50]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 04C56431FC2 for ; Fri, 31 Oct 2014 00:14:22 -0700 + (PDT) +Received: by mail-wg0-f50.google.com with SMTP id z12so5843488wgg.37 + for ; Fri, 31 Oct 2014 00:14:21 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:to:cc:subject:in-reply-to:references:user-agent + :from:date:message-id:mime-version:content-type; + bh=hiwImRarpvFxXOWeS2hEoAFdCUA1y6KBdcJBqNRqylc=; + b=Fr5KCKN8D15tz/AAFdvwFpS6jMsR2wVyK3435zr4GcRgnZwl8u6XQcuPJ9xYKIpm1t + k9bNJxxKubhQkSEs5RrfdimU0FAG3IMgAakFohh1JsM6enGSLNS7yR2pgZ6z2o0LEMsp + y2xUDL3w2sECmVpDxNpLNphE6Ee3E8D7Ay9NnDSmHo00Y3uC0+Wy+mtKm4jQY6T5k26N + bKjVuEDwA+lwgmW9g+EdaGJIdHw4aSuhWPcmqzPyb66wPKVUe50wtBHKxXFrWgRuRQ7Q + dmqTawqqj0/52qNuXZZ334M8ctm+FzC0Rj+852qVvJaTGf1UExuXsUkXcSqGMCFhliPs + FPLQ== +X-Gm-Message-State: + ALoCoQnEFcyed5LDey0yX8vCqBXsto7qjHfgtsuNkIkncPBcYTTgCVBls74vrS+Q/P3IkCtn0goT +X-Received: by 10.180.39.106 with SMTP id o10mr1934064wik.54.1414739661654; + Fri, 31 Oct 2014 00:14:21 -0700 (PDT) +Received: from disaster-area.hh.sledj.net + ([2a01:348:1a2:1:ea39:35ff:fe2c:a227]) + by mx.google.com with ESMTPSA id cu9sm11101834wjc.3.2014.10.31.00.14.20 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Fri, 31 Oct 2014 00:14:20 -0700 (PDT) +Received: from localhost (30000@localhost [local]); + by localhost (OpenSMTPD) with ESMTPA id 850adb90; + Fri, 31 Oct 2014 07:14:19 +0000 (UTC) +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH] cli: add support for notmuch search --duplicate=N with + --output=messages +In-Reply-To: <1414705489-30771-1-git-send-email-jani@nikula.org> +References: + <1414705489-30771-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.18.1 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-apple-darwin14.0.0) +From: David Edmondson +Date: Fri, 31 Oct 2014 07:14:19 +0000 +Message-ID: +MIME-Version: 1.0 +Content-Type: text/plain +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: Fri, 31 Oct 2014 07:14:28 -0000 + +On Thu, Oct 30 2014, Jani Nikula wrote: +> Print the message IDs of all messages matching the search terms that +> have at least N files associated with them. + +Briefly tested as working. I commend this patch to the masters of push. + +Thanks Jani! + +> --- +> doc/man1/notmuch-search.rst | 12 ++++++++---- +> notmuch-search.c | 34 ++++++++++++++++++++++++++++++---- +> 2 files changed, 38 insertions(+), 8 deletions(-) +> +> diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst +> index 90160f21e23c..aeba4bf604f6 100644 +> --- a/doc/man1/notmuch-search.rst +> +++ b/doc/man1/notmuch-search.rst +> @@ -122,10 +122,14 @@ Supported options for **search** include +> rather than the number of matching messages. +> +> ``--duplicate=N`` +> - Effective with ``--output=files``, output the Nth filename +> - associated with each message matching the query (N is 1-based). +> - If N is greater than the number of files associated with the +> - message, don't print anything. +> + For ``--output=files``, output the Nth filename associated +> + with each message matching the query (N is 1-based). If N is +> + greater than the number of files associated with the message, +> + don't print anything. +> + +> + For ``--output=messages``, only output message IDs of messages +> + matching the search terms that have at least N filenames +> + associated with them. +> +> Note that this option is orthogonal with the **folder:** search +> prefix. The prefix matches messages based on filenames. This +> diff --git a/notmuch-search.c b/notmuch-search.c +> index bc9be4593ecc..2bf876fd5abf 100644 +> --- a/notmuch-search.c +> +++ b/notmuch-search.c +> @@ -215,6 +215,24 @@ do_search_threads (sprinter_t *format, +> } +> +> static int +> +_count_filenames (notmuch_message_t *message) +> +{ +> + notmuch_filenames_t *filenames; +> + int i = 0; +> + +> + filenames = notmuch_message_get_filenames (message); +> + +> + while (notmuch_filenames_valid (filenames)) { +> + notmuch_filenames_move_to_next (filenames); +> + i++; +> + } +> + +> + notmuch_filenames_destroy (filenames); +> + +> + return i; +> +} +> + +> +static int +> do_search_messages (sprinter_t *format, +> notmuch_query_t *query, +> output_t output, +> @@ -265,10 +283,13 @@ do_search_messages (sprinter_t *format, +> notmuch_filenames_destroy( filenames ); +> +> } else { /* output == OUTPUT_MESSAGES */ +> - format->set_prefix (format, "id"); +> - format->string (format, +> - notmuch_message_get_message_id (message)); +> - format->separator (format); +> + /* special case 1 for speed */ +> + if (dupe <= 1 || dupe <= _count_filenames (message)) { +> + format->set_prefix (format, "id"); +> + format->string (format, +> + notmuch_message_get_message_id (message)); +> + format->separator (format); +> + } +> } +> +> notmuch_message_destroy (message); +> @@ -387,6 +408,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +> if (opt_index < 0) +> return EXIT_FAILURE; +> +> + if (output != OUTPUT_FILES && output != OUTPUT_MESSAGES && dupe != -1) { +> + fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n"); +> + return EXIT_FAILURE; +> + } +> + +> switch (format_sel) { +> case NOTMUCH_FORMAT_TEXT: +> format = sprinter_text_create (config, stdout); +> -- +> 2.1.1