Re: [Patch v7 07/14] cli: add support for batch tagging operations to "notmuch tag"
authorJani Nikula <jani@nikula.org>
Sat, 15 Dec 2012 23:14:07 +0000 (01:14 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:21 +0000 (09:52 -0800)
4a/ff81571baa737cded4d8fa147d6f6b96f1c60a [new file with mode: 0644]

diff --git a/4a/ff81571baa737cded4d8fa147d6f6b96f1c60a b/4a/ff81571baa737cded4d8fa147d6f6b96f1c60a
new file mode 100644 (file)
index 0000000..de679b3
--- /dev/null
@@ -0,0 +1,230 @@
+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 A521B431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:17 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 RL+MdqzoNBZC for <notmuch@notmuchmail.org>;\r
+       Sat, 15 Dec 2012 15:14:17 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A57DE431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:16 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so3675627lbb.26\r
+       for <notmuch@notmuchmail.org>; Sat, 15 Dec 2012 15:14:15 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+       :mime-version:content-type:x-gm-message-state;\r
+       bh=PhiNTEsdr4naal0JV8ExT3nNl7g6gnMPKbDojI8wv7c=;\r
+       b=KDmMeVMDHTyaNVM04V4s13ImiE8ZBxA4Z7C/1aQULQNeOGlkehAkB+GOjA9jLl6o19\r
+       7ix1Mp8u0eX0J4idC2XYly4SgcjLcT8oZ4T9aLsP2NI0Y397qPr7oYDCz+imLyfvszyC\r
+       eAN+ZKXcHGVCbV4SfWTsVnC2ejSo8zxElrN//+Xq/dwwY4+SYD9Q+uKradGhIdylj/8B\r
+       Qtmqm8EuUYGACaI/CN37ISkOChQT6Xtd34l5Y9wGKm3Ax5s1lz411wakxH2TGZfXyhEo\r
+       LGqKNUsZJTccOinBeqrdZ136blev8HxQQ1AOSX2QeIL0GwPYLQXgS63iyLw+UB4d99Ot\r
+       vRBQ==\r
+Received: by 10.152.114.65 with SMTP id je1mr6630159lab.33.1355613255147;\r
+       Sat, 15 Dec 2012 15:14:15 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id lr20sm3225480lab.17.2012.12.15.15.14.13\r
+       (version=SSLv3 cipher=OTHER); Sat, 15 Dec 2012 15:14:14 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: david@tethera.net, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v7 07/14] cli: add support for batch tagging operations to\r
+       "notmuch tag"\r
+In-Reply-To: <1355492062-7546-8-git-send-email-david@tethera.net>\r
+References: <1355492062-7546-1-git-send-email-david@tethera.net>\r
+       <1355492062-7546-8-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1\r
+       (i686-pc-linux-gnu)\r
+Date: Sun, 16 Dec 2012 01:14:07 +0200\r
+Message-ID: <87pq2aq56o.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Gm-Message-State:\r
+ ALoCoQnEbHTUS7B7ijZOL03mGMXk9vQtvw0xvZDKQ34XtdejnlG2hO7IiPnGbqrY+xJb3wLuvdQ5\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: Sat, 15 Dec 2012 23:14:17 -0000\r
+\r
+On Fri, 14 Dec 2012, david@tethera.net wrote:\r
+> From: Jani Nikula <jani@nikula.org>\r
+>\r
+> Add support for batch tagging operations through stdin to "notmuch\r
+> tag". This can be enabled with the new --batch command line option to\r
+> "notmuch tag". The input must consist of lines of the format:\r
+>\r
+> +<tag>|-<tag> [...] [--] <search-term> [...]\r
+>\r
+> Each line is interpreted similarly to "notmuch tag" command line\r
+> arguments. The delimiter is one or more spaces ' '. Any characters in\r
+> <tag> and <search-term> MAY be hex encoded with %NN where NN is the\r
+> hexadecimal value of the character. Any ' ' and '%' characters in\r
+> <tag> and <search-term> MUST be hex encoded (using %20 and %25,\r
+> respectively). Any characters that are not part of <tag> or\r
+> <search-term> MUST NOT be hex encoded.\r
+>\r
+> Leading and trailing space ' ' is ignored. Empty lines and lines\r
+> beginning with '#' are ignored.\r
+>\r
+> Signed-off-by: Jani Nikula <jani@nikula.org>\r
+>\r
+> Hacked-like-crazy-by: David Bremner <david@tethera.net>\r
+> ---\r
+>  notmuch-tag.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++------\r
+>  1 file changed, 80 insertions(+), 8 deletions(-)\r
+>\r
+> diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+> index 13f2268..a81d911 100644\r
+> --- a/notmuch-tag.c\r
+> +++ b/notmuch-tag.c\r
+> @@ -130,6 +130,43 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,\r
+>      return interrupted;\r
+>  }\r
+>  \r
+> +static int\r
+> +tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,\r
+> +      FILE *input)\r
+> +{\r
+> +    char *line = NULL;\r
+> +    char *query_string = NULL;\r
+> +    size_t line_size = 0;\r
+> +    ssize_t line_len;\r
+> +    int ret = 0;\r
+> +    tag_op_list_t *tag_ops;\r
+> +\r
+> +    tag_ops = tag_op_list_create (ctx);\r
+> +    if (tag_ops == NULL) {\r
+> +    fprintf (stderr, "Out of memory.\n");\r
+> +    return 1;\r
+> +    }\r
+> +\r
+> +    while ((line_len = getline (&line, &line_size, input)) != -1 &&\r
+> +       ! interrupted) {\r
+> +\r
+> +    ret = parse_tag_line (ctx, line, TAG_FLAG_NONE,\r
+> +                          &query_string, tag_ops);\r
+> +\r
+> +    if (ret > 0)\r
+> +        continue;\r
+> +\r
+> +    if (ret < 0 || tag_query (ctx, notmuch, query_string,\r
+> +                              tag_ops, flags))\r
+> +        break;\r
+\r
+Hey, your changelog in the cover letter says you fixed the tag_query\r
+return value propagation, but it's not here?\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+> +    }\r
+> +\r
+> +    if (line)\r
+> +    free (line);\r
+> +\r
+> +    return ret;\r
+> +}\r
+> +\r
+>  int\r
+>  notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>  {\r
+> @@ -139,6 +176,10 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>      notmuch_database_t *notmuch;\r
+>      struct sigaction action;\r
+>      tag_op_flag_t tag_flags = TAG_FLAG_NONE;\r
+> +    notmuch_bool_t batch = FALSE;\r
+> +    FILE *input = stdin;\r
+> +    char *input_file_name = NULL;\r
+> +    int opt_index;\r
+>      int ret = 0;\r
+>  \r
+>      /* Setup our handler for SIGINT */\r
+> @@ -148,15 +189,43 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>      action.sa_flags = SA_RESTART;\r
+>      sigaction (SIGINT, &action, NULL);\r
+>  \r
+> -    tag_ops = tag_op_list_create (ctx);\r
+> -    if (tag_ops == NULL) {\r
+> -    fprintf (stderr, "Out of memory.\n");\r
+> +    notmuch_opt_desc_t options[] = {\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
+> +    opt_index = parse_arguments (argc, argv, options, 1);\r
+> +    if (opt_index < 0)\r
+>      return 1;\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 (parse_tag_command_line (ctx, argc - 1, argv + 1,\r
+> -                            &query_string, tag_ops))\r
+> -    return 1;\r
+> +    if (batch) {\r
+> +    if (opt_index != argc) {\r
+> +        fprintf (stderr, "Can't specify both cmdline and stdin!\n");\r
+> +        return 1;\r
+> +    }\r
+> +    } else {\r
+> +\r
+> +    tag_ops = tag_op_list_create (ctx);\r
+> +    if (tag_ops == NULL) {\r
+> +        fprintf (stderr, "Out of memory.\n");\r
+> +        return 1;\r
+> +    }\r
+> +\r
+> +    if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,\r
+> +                                &query_string, tag_ops))\r
+> +        return 1;\r
+> +    }\r
+>  \r
+>      config = notmuch_config_open (ctx, NULL, NULL);\r
+>      if (config == NULL)\r
+> @@ -169,9 +238,12 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+>      if (notmuch_config_get_maildir_synchronize_flags (config))\r
+>      tag_flags |= TAG_FLAG_MAILDIR_SYNC;\r
+>  \r
+> -    ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);\r
+> +    if (batch)\r
+> +    ret = tag_file (ctx, notmuch, tag_flags, input);\r
+> +    else\r
+> +    ret = tag_query (ctx, notmuch, query_string, tag_ops, tag_flags);\r
+>  \r
+>      notmuch_database_destroy (notmuch);\r
+>  \r
+> -    return ret;\r
+> +    return ret || interrupted;\r
+>  }\r
+> -- \r
+> 1.7.10.4\r