1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1E64B431FCB
\r
6 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 14:45:00 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id W9e1c-guwEsW for <notmuch@notmuchmail.org>;
\r
16 Thu, 30 Oct 2014 14:44:54 -0700 (PDT)
\r
17 Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com
\r
18 [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 7117A431FC2
\r
21 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 14:44:54 -0700 (PDT)
\r
22 Received: by mail-wi0-f169.google.com with SMTP id n3so2272309wiv.0
\r
23 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 14:44:53 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=1e100.net; s=20130820;
\r
26 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 bh=rGi9ycrqvPf8RS14xxuXc12EDY2C/sfKEdCfLC2VhUA=;
\r
29 b=BIV6cqz4Hyi+DtpacKOswgqV46vcn5q/yIL+UqxMDNuojKsDKsWniWkHN3kJ6szqsk
\r
30 oxZYMh1MuxIbeLhmrVMrYn9EQiQDssVxoR3W9tJryFQ236d5F0gNzVw4fwW/SfH/TRtx
\r
31 rYnJYp0rNZXZd8eGumLJGZe5CykPgE0FImDTztfrtPC1Aw0/sNz2x2qj/22vxTBEpjtl
\r
32 Y3Vjf/OB3dJsVqX3rdqqZ7pjZJwI9sn6x0oyx8YY6TrTooJwwePjJEvNeUWgllS+t2aW
\r
33 kDvq+gp8mItnhBBpt/XnUwLAHE7ee9TmUCKW15MRoVVgsMvyOSwBtT3ve/DgO4SUljXE
\r
36 ALoCoQnavuTXMKmOOKjzh+gAtdUm9jxFM7pdsKCXJ+3ldhGJXIwbEWt+OGmaF9lj+wgij3UUTIFW
\r
37 X-Received: by 10.180.207.72 with SMTP id lu8mr45292742wic.2.1414705492760;
\r
38 Thu, 30 Oct 2014 14:44:52 -0700 (PDT)
\r
39 Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi.
\r
41 by mx.google.com with ESMTPSA id bf6sm6254375wjb.13.2014.10.30.14.44.51
\r
42 for <multiple recipients>
\r
43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
44 Thu, 30 Oct 2014 14:44:52 -0700 (PDT)
\r
45 From: Jani Nikula <jani@nikula.org>
\r
46 To: notmuch@notmuchmail.org
\r
47 Subject: [PATCH] cli: add support for notmuch search --duplicate=N with
\r
49 Date: Thu, 30 Oct 2014 23:44:49 +0200
\r
50 Message-Id: <1414705489-30771-1-git-send-email-jani@nikula.org>
\r
51 X-Mailer: git-send-email 2.1.1
\r
52 In-Reply-To: <m28ujy6kba.fsf@dme.org>
\r
53 References: <m28ujy6kba.fsf@dme.org>
\r
54 X-BeenThere: notmuch@notmuchmail.org
\r
55 X-Mailman-Version: 2.1.13
\r
57 List-Id: "Use and development of the notmuch mail system."
\r
58 <notmuch.notmuchmail.org>
\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
62 List-Post: <mailto:notmuch@notmuchmail.org>
\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
66 X-List-Received-Date: Thu, 30 Oct 2014 21:45:00 -0000
\r
68 Print the message IDs of all messages matching the search terms that
\r
69 have at least N files associated with them.
\r
71 doc/man1/notmuch-search.rst | 12 ++++++++----
\r
72 notmuch-search.c | 34 ++++++++++++++++++++++++++++++----
\r
73 2 files changed, 38 insertions(+), 8 deletions(-)
\r
75 diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst
\r
76 index 90160f21e23c..aeba4bf604f6 100644
\r
77 --- a/doc/man1/notmuch-search.rst
\r
78 +++ b/doc/man1/notmuch-search.rst
\r
79 @@ -122,10 +122,14 @@ Supported options for **search** include
\r
80 rather than the number of matching messages.
\r
83 - Effective with ``--output=files``, output the Nth filename
\r
84 - associated with each message matching the query (N is 1-based).
\r
85 - If N is greater than the number of files associated with the
\r
86 - message, don't print anything.
\r
87 + For ``--output=files``, output the Nth filename associated
\r
88 + with each message matching the query (N is 1-based). If N is
\r
89 + greater than the number of files associated with the message,
\r
90 + don't print anything.
\r
92 + For ``--output=messages``, only output message IDs of messages
\r
93 + matching the search terms that have at least N filenames
\r
94 + associated with them.
\r
96 Note that this option is orthogonal with the **folder:** search
\r
97 prefix. The prefix matches messages based on filenames. This
\r
98 diff --git a/notmuch-search.c b/notmuch-search.c
\r
99 index bc9be4593ecc..2bf876fd5abf 100644
\r
100 --- a/notmuch-search.c
\r
101 +++ b/notmuch-search.c
\r
102 @@ -215,6 +215,24 @@ do_search_threads (sprinter_t *format,
\r
106 +_count_filenames (notmuch_message_t *message)
\r
108 + notmuch_filenames_t *filenames;
\r
111 + filenames = notmuch_message_get_filenames (message);
\r
113 + while (notmuch_filenames_valid (filenames)) {
\r
114 + notmuch_filenames_move_to_next (filenames);
\r
118 + notmuch_filenames_destroy (filenames);
\r
124 do_search_messages (sprinter_t *format,
\r
125 notmuch_query_t *query,
\r
127 @@ -265,10 +283,13 @@ do_search_messages (sprinter_t *format,
\r
128 notmuch_filenames_destroy( filenames );
\r
130 } else { /* output == OUTPUT_MESSAGES */
\r
131 - format->set_prefix (format, "id");
\r
132 - format->string (format,
\r
133 - notmuch_message_get_message_id (message));
\r
134 - format->separator (format);
\r
135 + /* special case 1 for speed */
\r
136 + if (dupe <= 1 || dupe <= _count_filenames (message)) {
\r
137 + format->set_prefix (format, "id");
\r
138 + format->string (format,
\r
139 + notmuch_message_get_message_id (message));
\r
140 + format->separator (format);
\r
144 notmuch_message_destroy (message);
\r
145 @@ -387,6 +408,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
147 return EXIT_FAILURE;
\r
149 + if (output != OUTPUT_FILES && output != OUTPUT_MESSAGES && dupe != -1) {
\r
150 + fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
\r
151 + return EXIT_FAILURE;
\r
154 switch (format_sel) {
\r
155 case NOTMUCH_FORMAT_TEXT:
\r
156 format = sprinter_text_create (config, stdout);
\r