Re: [PATCH 3/5] cli: add --batch option to notmuch count
authorTomi Ollila <tomi.ollila@iki.fi>
Wed, 23 Jan 2013 13:36:45 +0000 (15:36 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:19 +0000 (09:53 -0800)
33/4abd3b8465364e467fa5a5287f03fbba6fe7c7 [new file with mode: 0644]

diff --git a/33/4abd3b8465364e467fa5a5287f03fbba6fe7c7 b/33/4abd3b8465364e467fa5a5287f03fbba6fe7c7
new file mode 100644 (file)
index 0000000..1d4806d
--- /dev/null
@@ -0,0 +1,175 @@
+Return-Path: <tomi.ollila@iki.fi>\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 CD5CE431FAF\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Jan 2013 05:36:58 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 OX5so3CoWSCh for <notmuch@notmuchmail.org>;\r
+       Wed, 23 Jan 2013 05:36:57 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9B834431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 23 Jan 2013 05:36:57 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+       by guru.guru-group.fi (Postfix) with ESMTP id B7B1A100086;\r
+       Wed, 23 Jan 2013 15:36:45 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 3/5] cli: add --batch option to notmuch count\r
+In-Reply-To:\r
+ <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org>\r
+References: <cover.1358273133.git.jani@nikula.org>\r
+       <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org>\r
+User-Agent: Notmuch/0.15+11~ge1e719d (http://notmuchmail.org) Emacs/24.2.1\r
+       (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Wed, 23 Jan 2013 15:36:45 +0200\r
+Message-ID: <m2a9s0hvgy.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Wed, 23 Jan 2013 13:36:58 -0000\r
+\r
+On Tue, Jan 15 2013, Jani Nikula <jani@nikula.org> wrote:\r
+\r
+> Add support for reading queries from stdin, one per line, and writing\r
+> results to stdin, one per line.\r
+\r
+Jani's parts LGTM, except one IMPORTANT part -- results are written\r
+to STDOUT! (hopefully...yes) instead of STDIN! ;)\r
+\r
+I don't see a reason why this particular way to get counts could\r
+not be supported in notmuch into foreseeable future; the implementation\r
+is simple and clean.\r
+\r
+Next to look Mark's changes...\r
+\r
+Tomi\r
+\r
+>\r
+> This will bring considerable performance improvements when utilized in\r
+> Emacs notmuch-hello, especially so when running remote notmuch.\r
+> ---\r
+>  notmuch-count.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++--\r
+>  1 file changed, 50 insertions(+), 2 deletions(-)\r
+>\r
+> diff --git a/notmuch-count.c b/notmuch-count.c\r
+> index 0e14b48..4bc4215 100644\r
+> --- a/notmuch-count.c\r
+> +++ b/notmuch-count.c\r
+> @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
+>      return 0;\r
+>  }\r
+>  \r
+> +static int\r
+> +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,\r
+> +        size_t exclude_tags_length, int output)\r
+> +{\r
+> +    char *line = NULL;\r
+> +    ssize_t line_len;\r
+> +    size_t line_size;\r
+> +    int ret = 0;\r
+> +\r
+> +    while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {\r
+> +    chomp_newline (line);\r
+> +    ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,\r
+> +                       output);\r
+> +    }\r
+> +\r
+> +    if (line)\r
+> +    free (line);\r
+> +\r
+> +    return ret;\r
+> +}\r
+> +\r
+>  int\r
+>  notmuch_count_command (void *ctx, int argc, char *argv[])\r
+>  {\r
+> @@ -73,6 +94,9 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+>      int exclude = EXCLUDE_TRUE;\r
+>      const char **search_exclude_tags = NULL;\r
+>      size_t search_exclude_tags_length = 0;\r
+> +    notmuch_bool_t batch = FALSE;\r
+> +    FILE *input = stdin;\r
+> +    char *input_file_name = NULL;\r
+>      int ret;\r
+>  \r
+>      notmuch_opt_desc_t options[] = {\r
+> @@ -84,6 +108,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+>        (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
+>                                { "false", EXCLUDE_FALSE },\r
+>                                { 0, 0 } } },\r
+> +    { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
+> +    { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
+>      { 0, 0, 0, 0, 0 }\r
+>      };\r
+>  \r
+> @@ -93,6 +119,21 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+>      return 1;\r
+>      }\r
+>  \r
+> +    if (input_file_name) {\r
+> +    batch = TRUE;\r
+> +    input = fopen (input_file_name, "r");\r
+> +    if (input == NULL) {\r
+> +        fprintf (stderr, "Error opening %s for reading: %s\n",\r
+> +                 input_file_name, strerror (errno));\r
+> +        return 1;\r
+> +    }\r
+> +    }\r
+> +\r
+> +    if (batch && opt_index != argc) {\r
+> +    fprintf (stderr, "--batch and query string are not compatible\n");\r
+> +    return 1;\r
+> +    }\r
+> +\r
+>      config = notmuch_config_open (ctx, NULL, NULL);\r
+>      if (config == NULL)\r
+>      return 1;\r
+> @@ -112,10 +153,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+>          (config, &search_exclude_tags_length);\r
+>      }\r
+>  \r
+> -    ret = print_count (notmuch, query_str, search_exclude_tags,\r
+> -                   search_exclude_tags_length, output);\r
+> +    if (batch)\r
+> +    ret = count_file (notmuch, input, search_exclude_tags,\r
+> +                      search_exclude_tags_length, output);\r
+> +    else\r
+> +    ret = print_count (notmuch, query_str, search_exclude_tags,\r
+> +                       search_exclude_tags_length, output);\r
+>  \r
+>      notmuch_database_destroy (notmuch);\r
+>  \r
+> +    if (input != stdin)\r
+> +    fclose (input);\r
+> +\r
+>      return ret;\r
+>  }\r
+> -- \r
+> 1.7.10.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r