[PATCH v4 01/12] tag-util: move out 'tag' command-line checks
authorPeter Wang <novalazy@gmail.com>
Thu, 24 Jan 2013 12:07:57 +0000 (23:07 +1100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:21 +0000 (09:53 -0800)
8e/cd7b927f20161d1c56c61e560f807def234ddd [new file with mode: 0644]

diff --git a/8e/cd7b927f20161d1c56c61e560f807def234ddd b/8e/cd7b927f20161d1c56c61e560f807def234ddd
new file mode 100644 (file)
index 0000000..c4582f0
--- /dev/null
@@ -0,0 +1,118 @@
+Return-Path: <novalazy@gmail.com>\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 74824431FD6\r
+       for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:09:26 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, 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 lSVwp4Wmo950 for <notmuch@notmuchmail.org>;\r
+       Thu, 24 Jan 2013 04:09:25 -0800 (PST)\r
+Received: from mail-da0-f54.google.com (mail-da0-f54.google.com\r
+       [209.85.210.54]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 63318431FCF\r
+       for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:09:20 -0800 (PST)\r
+Received: by mail-da0-f54.google.com with SMTP id n2so4258646dad.41\r
+       for <notmuch@notmuchmail.org>; Thu, 24 Jan 2013 04:09:19 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references; bh=VP7cZ2RmGU8gvZ3Iw4FhGlvKPM5YnlMkTxsxbZt0fQo=;\r
+       b=sfA0Yuvf0qiH7JLtAAnjL1faOZaTKVxSWg+01HRaJ6aszRet7hgKEOg3eELhYzHLtl\r
+       wLO3a+I9AA5HPaJ4rBzsWE3SUYQRX7XczL6EchO2y95EkTLME9ZcfB0Dp0dUwX/WIGgz\r
+       sDU9WkuF3RFMf3ULY7dQsOPjlclTpqQJoJbQEmR+RBhH2KVd0YDR62jMzqEuTHEYvKRC\r
+       H3dppbVoTnDOps5xnDQ/OWDJilHcorxjjyJCqYim+6ctsbQ/W84PO3bR0aLR473BA0TR\r
+       8R7kOSGTpFejVfboij418pakOledYn2qhYdgKJSFOi7/GhyutD1LOs9q0rAXpR4v75Ci\r
+       1TpQ==\r
+X-Received: by 10.68.220.6 with SMTP id ps6mr4191667pbc.80.1359029359643;\r
+       Thu, 24 Jan 2013 04:09:19 -0800 (PST)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id o6sm15590382paw.37.2013.01.24.04.09.17\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Thu, 24 Jan 2013 04:09:18 -0800 (PST)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 01/12] tag-util: move out 'tag' command-line checks\r
+Date: Thu, 24 Jan 2013 23:07:57 +1100\r
+Message-Id: <1359029288-12132-2-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.12.1\r
+In-Reply-To: <1359029288-12132-1-git-send-email-novalazy@gmail.com>\r
+References: <1359029288-12132-1-git-send-email-novalazy@gmail.com>\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: Thu, 24 Jan 2013 12:09:26 -0000\r
+\r
+parse_tag_command_line checked for two error conditions which are\r
+specific to the 'tag' command.  It can be reused for the forthcoming\r
+notmuch 'insert' command if we move the checks out, into notmuch-tag.c.\r
+---\r
+ notmuch-tag.c | 10 ++++++++++\r
+ tag-util.c    | 11 +++--------\r
+ 2 files changed, 13 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index d9daf8f..a901dad 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -234,6 +234,16 @@ notmuch_tag_command (void *ctx, int argc, char *argv[])\r
+       if (parse_tag_command_line (ctx, argc - opt_index, argv + opt_index,\r
+                                   &query_string, tag_ops))\r
+           return 1;\r
++\r
++      if (tag_op_list_size (tag_ops) == 0) {\r
++          fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
++          return 1;\r
++      }\r
++\r
++      if (*query_string == '\0') {\r
++          fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");\r
++          return 1;\r
++      }\r
+     }\r
\r
+     config = notmuch_config_open (ctx, NULL, NULL);\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 701d329..743d591 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -188,16 +188,11 @@ parse_tag_command_line (void *ctx, int argc, char **argv,\r
+       tag_op_list_append (tag_ops, argv[i] + 1, is_remove);\r
+     }\r
\r
+-    if (tag_op_list_size (tag_ops) == 0) {\r
+-      fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n");\r
+-      return TAG_PARSE_INVALID;\r
+-    }\r
+-\r
+     *query_str = query_string_from_args (ctx, argc - i, &argv[i]);\r
\r
+-    if (*query_str == NULL || **query_str == '\0') {\r
+-      fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");\r
+-      return TAG_PARSE_INVALID;\r
++    if (*query_str == NULL) {\r
++       fprintf (stderr, "Out of memory.\n");\r
++       return TAG_PARSE_OUT_OF_MEMORY;\r
+     }\r
\r
+     return TAG_PARSE_SUCCESS;\r
+-- \r
+1.7.12.1\r
+\r