[RFC PATCH 2/3] cli: add support for limiting the number of search results
authorJani Nikula <jani@nikula.org>
Fri, 28 Oct 2011 20:59:30 +0000 (23:59 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:50 +0000 (09:39 -0800)
6b/331fde5db9f4b3b28f77f076d3632c18d42cc3 [new file with mode: 0644]

diff --git a/6b/331fde5db9f4b3b28f77f076d3632c18d42cc3 b/6b/331fde5db9f4b3b28f77f076d3632c18d42cc3
new file mode 100644 (file)
index 0000000..39cbbfb
--- /dev/null
@@ -0,0 +1,116 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 935FF429E32\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:50 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id KA0jZ0XY482X for <notmuch@notmuchmail.org>;\r
+       Fri, 28 Oct 2011 13:59:49 -0700 (PDT)\r
+Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
+       [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 5A918429E21\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
+Received: by mail-fx0-f53.google.com with SMTP id i28so4419077faa.26\r
+       for <notmuch@notmuchmail.org>; Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
+Received: by 10.223.92.135 with SMTP id r7mr8801871fam.35.1319835587101;\r
+       Fri, 28 Oct 2011 13:59:47 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id j5sm19444105faf.14.2011.10.28.13.59.45\r
+       (version=SSLv3 cipher=OTHER); Fri, 28 Oct 2011 13:59:46 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 2/3] cli: add support for limiting the number of search\r
+       results\r
+Date: Fri, 28 Oct 2011 23:59:30 +0300\r
+Message-Id:\r
+ <f16c7983a8a639ea2ed1178a3190afb9620153e2.1319833617.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
+References: <cover.1319833617.git.jani@nikula.org>\r
+In-Reply-To: <cover.1319833617.git.jani@nikula.org>\r
+References: <cover.1319833617.git.jani@nikula.org>\r
+Cc: amdragon@mit.edu\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 28 Oct 2011 20:59:51 -0000\r
+\r
+Add command line parameter --maxitems=N to notmuch search to limit the\r
+number of displayed messages to N.\r
+\r
+These two are equal:\r
+\r
+$ notmuch search --output=messages --sort=newest-first --maxitems=10 SEARCH\r
+$ notmuch search --output=messages --sort=newest-first SEARCH | head\r
+\r
+As are these:\r
+\r
+$ notmuch search --output=messages --sort=oldest-first --maxitems=10 SEARCH\r
+$ notmuch search --output=messages --sort=oldest-first SEARCH | tail\r
+\r
+Note that N refers to the maximum amount of messages, even for\r
+--output=threads.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-search.c |   10 ++++++++++\r
+ 1 files changed, 10 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 6f04d9a..a3a6475 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -394,6 +394,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+     const search_format_t *format = &format_text;\r
+     int i, ret;\r
+     output_t output = OUTPUT_SUMMARY;\r
++    unsigned int maxitems = 0;\r
\r
+     argc--; argv++; /* skip subcommand argument */\r
\r
+@@ -412,6 +413,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+               fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
+               return 1;\r
+           }\r
++      } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {\r
++          const char *p;\r
++          opt = argv[i] + sizeof ("--maxitems=") - 1;\r
++          maxitems = strtoul(opt, &p, 10);\r
++          if (*opt == '\0' || p == opt || *p != '\0') {\r
++              fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);\r
++              return 1;\r
++          }\r
+       } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
+           opt = argv[i] + sizeof ("--format=") - 1;\r
+           if (strcmp (opt, "text") == 0) {\r
+@@ -473,6 +482,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
+     }\r
\r
+     notmuch_query_set_sort (query, sort);\r
++    notmuch_query_set_maxitems (query, maxitems);\r
\r
+     switch (output) {\r
+     default:\r
+-- \r
+1.7.5.4\r
+\r