From: Jani Nikula Date: Thu, 30 Oct 2014 21:44:49 +0000 (+0200) Subject: [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cbbd7acfc733ab644ed66b1c41bc2de97be18bb6;p=notmuch-archives.git [PATCH] cli: add support for notmuch search --duplicate=N with --output=messages --- diff --git a/f1/738f2e9d66e7185aea01068c17f27746058b03 b/f1/738f2e9d66e7185aea01068c17f27746058b03 new file mode 100644 index 000000000..1ccb747de --- /dev/null +++ b/f1/738f2e9d66e7185aea01068c17f27746058b03 @@ -0,0 +1,159 @@ +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 1E64B431FCB + for ; Thu, 30 Oct 2014 14:45:00 -0700 (PDT) +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 W9e1c-guwEsW for ; + Thu, 30 Oct 2014 14:44:54 -0700 (PDT) +Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com + [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7117A431FC2 + for ; Thu, 30 Oct 2014 14:44:54 -0700 (PDT) +Received: by mail-wi0-f169.google.com with SMTP id n3so2272309wiv.0 + for ; Thu, 30 Oct 2014 14:44:53 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references; + bh=rGi9ycrqvPf8RS14xxuXc12EDY2C/sfKEdCfLC2VhUA=; + b=BIV6cqz4Hyi+DtpacKOswgqV46vcn5q/yIL+UqxMDNuojKsDKsWniWkHN3kJ6szqsk + oxZYMh1MuxIbeLhmrVMrYn9EQiQDssVxoR3W9tJryFQ236d5F0gNzVw4fwW/SfH/TRtx + rYnJYp0rNZXZd8eGumLJGZe5CykPgE0FImDTztfrtPC1Aw0/sNz2x2qj/22vxTBEpjtl + Y3Vjf/OB3dJsVqX3rdqqZ7pjZJwI9sn6x0oyx8YY6TrTooJwwePjJEvNeUWgllS+t2aW + kDvq+gp8mItnhBBpt/XnUwLAHE7ee9TmUCKW15MRoVVgsMvyOSwBtT3ve/DgO4SUljXE + v3yg== +X-Gm-Message-State: + ALoCoQnavuTXMKmOOKjzh+gAtdUm9jxFM7pdsKCXJ+3ldhGJXIwbEWt+OGmaF9lj+wgij3UUTIFW +X-Received: by 10.180.207.72 with SMTP id lu8mr45292742wic.2.1414705492760; + Thu, 30 Oct 2014 14:44:52 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi. + [88.195.109.48]) + by mx.google.com with ESMTPSA id bf6sm6254375wjb.13.2014.10.30.14.44.51 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Thu, 30 Oct 2014 14:44:52 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH] cli: add support for notmuch search --duplicate=N with + --output=messages +Date: Thu, 30 Oct 2014 23:44:49 +0200 +Message-Id: <1414705489-30771-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: +References: +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: Thu, 30 Oct 2014 21:45:00 -0000 + +Print the message IDs of all messages matching the search terms that +have at least N files associated with them. +--- + 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 +