database error
[notmuch-archives.git] / 41 / d0c3f323973df22b7ba0da23b9a2924bc2e057
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 13A2C431FDB\r
6         for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 13:55:08 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 52FcCmIE2UvQ for <notmuch@notmuchmail.org>;\r
17         Tue, 15 Jan 2013 13:55:07 -0800 (PST)\r
18 Received: from mail-la0-f48.google.com (mail-la0-f48.google.com\r
19         [209.85.215.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id C6A07431FBF\r
22         for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 13:55:00 -0800 (PST)\r
23 Received: by mail-la0-f48.google.com with SMTP id ej20so689676lab.21\r
24         for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 13:54:59 -0800 (PST)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
28         :references:in-reply-to:references:x-gm-message-state;\r
29         bh=2uOCZyRVwKX5DvUydJ9hY+ddoNCeY3RjNhTdgBXUWys=;\r
30         b=KKnRk67PCrhbcPhBi9b8PfMc1HKBxZGb86jtlJxff8JvSqM7K4KvWJ7cmKhfodiXlh\r
31         UrNpMpqDkn9RNcPHrBVmXorLdfSoTc/6/lOMRiV5BQWooVZg/T5QpeMiyU/RqKxTiG+S\r
32         MRGRzmGz7q4id+An/Yeg5GbG+sfQ/ti/AtRNXXr+pNP+yUnodsIspDHKjBKWj31ZPCtH\r
33         qMM123JBbbXeKcIZ68cPPxSwJztryLjoPsLStYPeOA8lwrPgj06G8ed+oCT44BdlHOqQ\r
34         lj2oZBwx0dxfbRrCR61PHl9JVoU2Bh+8ec7XqzOi9/5ZeizPg0hbCPE8r7YBmfxBO8B3\r
35         1FfA==\r
36 X-Received: by 10.112.26.70 with SMTP id j6mr35911127lbg.55.1358286899054;\r
37         Tue, 15 Jan 2013 13:54:59 -0800 (PST)\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
39         [80.223.81.27])\r
40         by mx.google.com with ESMTPS id if8sm7212190lab.1.2013.01.15.13.54.57\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Tue, 15 Jan 2013 13:54:58 -0800 (PST)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org\r
45 Subject: [PATCH 3/5] cli: add --batch option to notmuch count\r
46 Date: Tue, 15 Jan 2013 23:54:45 +0200\r
47 Message-Id:\r
48  <9465478105bbda3d21921906b7abf24dbbaa7ec9.1358273133.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.10.4\r
50 In-Reply-To: <cover.1358273133.git.jani@nikula.org>\r
51 References: <cover.1358273133.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1358273133.git.jani@nikula.org>\r
53 References: <cover.1358273133.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQmKqlZWhu/5W8JpYvA4aqHjSp0VRm4RnwXknA6XD8618N5rg55TbvhqEvvjg4feDM1gbOfR\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Tue, 15 Jan 2013 21:55:08 -0000\r
69 \r
70 Add support for reading queries from stdin, one per line, and writing\r
71 results to stdin, one per line.\r
72 \r
73 This will bring considerable performance improvements when utilized in\r
74 Emacs notmuch-hello, especially so when running remote notmuch.\r
75 ---\r
76  notmuch-count.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++--\r
77  1 file changed, 50 insertions(+), 2 deletions(-)\r
78 \r
79 diff --git a/notmuch-count.c b/notmuch-count.c\r
80 index 0e14b48..4bc4215 100644\r
81 --- a/notmuch-count.c\r
82 +++ b/notmuch-count.c\r
83 @@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char *query_str,\r
84      return 0;\r
85  }\r
86  \r
87 +static int\r
88 +count_file (notmuch_database_t *notmuch, FILE *input, const char **exclude_tags,\r
89 +           size_t exclude_tags_length, int output)\r
90 +{\r
91 +    char *line = NULL;\r
92 +    ssize_t line_len;\r
93 +    size_t line_size;\r
94 +    int ret = 0;\r
95 +\r
96 +    while (!ret && (line_len = getline (&line, &line_size, input)) != -1) {\r
97 +       chomp_newline (line);\r
98 +       ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,\r
99 +                          output);\r
100 +    }\r
101 +\r
102 +    if (line)\r
103 +       free (line);\r
104 +\r
105 +    return ret;\r
106 +}\r
107 +\r
108  int\r
109  notmuch_count_command (void *ctx, int argc, char *argv[])\r
110  {\r
111 @@ -73,6 +94,9 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
112      int exclude = EXCLUDE_TRUE;\r
113      const char **search_exclude_tags = NULL;\r
114      size_t search_exclude_tags_length = 0;\r
115 +    notmuch_bool_t batch = FALSE;\r
116 +    FILE *input = stdin;\r
117 +    char *input_file_name = NULL;\r
118      int ret;\r
119  \r
120      notmuch_opt_desc_t options[] = {\r
121 @@ -84,6 +108,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
122           (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },\r
123                                   { "false", EXCLUDE_FALSE },\r
124                                   { 0, 0 } } },\r
125 +       { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
126 +       { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
127         { 0, 0, 0, 0, 0 }\r
128      };\r
129  \r
130 @@ -93,6 +119,21 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
131         return 1;\r
132      }\r
133  \r
134 +    if (input_file_name) {\r
135 +       batch = TRUE;\r
136 +       input = fopen (input_file_name, "r");\r
137 +       if (input == NULL) {\r
138 +           fprintf (stderr, "Error opening %s for reading: %s\n",\r
139 +                    input_file_name, strerror (errno));\r
140 +           return 1;\r
141 +       }\r
142 +    }\r
143 +\r
144 +    if (batch && opt_index != argc) {\r
145 +       fprintf (stderr, "--batch and query string are not compatible\n");\r
146 +       return 1;\r
147 +    }\r
148 +\r
149      config = notmuch_config_open (ctx, NULL, NULL);\r
150      if (config == NULL)\r
151         return 1;\r
152 @@ -112,10 +153,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
153             (config, &search_exclude_tags_length);\r
154      }\r
155  \r
156 -    ret = print_count (notmuch, query_str, search_exclude_tags,\r
157 -                      search_exclude_tags_length, output);\r
158 +    if (batch)\r
159 +       ret = count_file (notmuch, input, search_exclude_tags,\r
160 +                         search_exclude_tags_length, output);\r
161 +    else\r
162 +       ret = print_count (notmuch, query_str, search_exclude_tags,\r
163 +                          search_exclude_tags_length, output);\r
164  \r
165      notmuch_database_destroy (notmuch);\r
166  \r
167 +    if (input != stdin)\r
168 +       fclose (input);\r
169 +\r
170      return ret;\r
171  }\r
172 -- \r
173 1.7.10.4\r
174 \r