1 Return-Path: <sojkam1@fel.cvut.cz>
\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 0F520431FDA
\r
6 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:30 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id Zq9YJayObk05 for <notmuch@notmuchmail.org>;
\r
16 Tue, 4 Nov 2014 16:26:24 -0800 (PST)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id C73AC431FB6
\r
19 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:18 -0800 (PST)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 258A05CD1A9
\r
22 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:18 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
26 port 10044) with ESMTP id dsZSOgeJy6ee for <notmuch@notmuchmail.org>;
\r
27 Wed, 5 Nov 2014 01:26:13 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 4B3115CD1A8
\r
30 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:13 +0100 (CET)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1XloQI-0005Ck-P3; Wed, 05 Nov 2014 01:26:06 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v3 02/10] cli: search: Move more variables into
\r
38 Date: Wed, 5 Nov 2014 01:25:51 +0100
\r
39 Message-Id: <1415147159-19946-3-git-send-email-sojkam1@fel.cvut.cz>
\r
40 X-Mailer: git-send-email 2.1.1
\r
41 In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Wed, 05 Nov 2014 00:26:30 -0000
\r
57 In order to share some command line options between search and address
\r
58 subcommands we need to add corresponding variables to the context
\r
59 structure. While we are at it, we also add notmuch_database_t to unify
\r
60 parameters of all do_search_* functions and to simplify subsequent
\r
63 Otherwise, there are no functional changes.
\r
65 notmuch-search.c | 49 ++++++++++++++++++++++++++-----------------------
\r
66 1 file changed, 26 insertions(+), 23 deletions(-)
\r
68 diff --git a/notmuch-search.c b/notmuch-search.c
\r
69 index 2c47b80..3d2012b 100644
\r
70 --- a/notmuch-search.c
\r
71 +++ b/notmuch-search.c
\r
72 @@ -34,8 +34,18 @@ typedef enum {
\r
74 #define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)
\r
77 + NOTMUCH_FORMAT_JSON,
\r
78 + NOTMUCH_FORMAT_TEXT,
\r
79 + NOTMUCH_FORMAT_TEXT0,
\r
80 + NOTMUCH_FORMAT_SEXP
\r
84 + notmuch_database_t *notmuch;
\r
85 + format_sel_t format_sel;
\r
87 + notmuch_exclude_t exclude;
\r
88 notmuch_query_t *query;
\r
89 notmuch_sort_t sort;
\r
91 @@ -413,14 +423,14 @@ do_search_messages (search_context_t *ctx)
\r
95 -do_search_tags (notmuch_database_t *notmuch,
\r
96 - const search_context_t *ctx)
\r
97 +do_search_tags (const search_context_t *ctx)
\r
99 notmuch_messages_t *messages = NULL;
\r
100 notmuch_tags_t *tags;
\r
102 sprinter_t *format = ctx->format;
\r
103 notmuch_query_t *query = ctx->query;
\r
104 + notmuch_database_t *notmuch = ctx->notmuch;
\r
106 /* should the following only special case if no excluded terms
\r
108 @@ -464,8 +474,9 @@ do_search_tags (notmuch_database_t *notmuch,
\r
110 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
112 - notmuch_database_t *notmuch;
\r
113 search_context_t ctx = {
\r
114 + .format_sel = NOTMUCH_FORMAT_TEXT,
\r
115 + .exclude = NOTMUCH_EXCLUDE_TRUE,
\r
116 .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
119 @@ -474,22 +485,14 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
122 int opt_index, ret;
\r
123 - notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;
\r
127 - NOTMUCH_FORMAT_JSON,
\r
128 - NOTMUCH_FORMAT_TEXT,
\r
129 - NOTMUCH_FORMAT_TEXT0,
\r
130 - NOTMUCH_FORMAT_SEXP
\r
131 - } format_sel = NOTMUCH_FORMAT_TEXT;
\r
133 notmuch_opt_desc_t options[] = {
\r
134 { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',
\r
135 (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
136 { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
138 - { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
\r
139 + { NOTMUCH_OPT_KEYWORD, &ctx.format_sel, "format", 'f',
\r
140 (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
141 { "sexp", NOTMUCH_FORMAT_SEXP },
\r
142 { "text", NOTMUCH_FORMAT_TEXT },
\r
143 @@ -505,7 +508,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
144 { "files", OUTPUT_FILES },
\r
145 { "tags", OUTPUT_TAGS },
\r
147 - { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',
\r
148 + { NOTMUCH_OPT_KEYWORD, &ctx.exclude, "exclude", 'x',
\r
149 (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },
\r
150 { "false", NOTMUCH_EXCLUDE_FALSE },
\r
151 { "flag", NOTMUCH_EXCLUDE_FLAG },
\r
152 @@ -530,7 +533,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
153 return EXIT_FAILURE;
\r
156 - switch (format_sel) {
\r
157 + switch (ctx.format_sel) {
\r
158 case NOTMUCH_FORMAT_TEXT:
\r
159 ctx.format = sprinter_text_create (config, stdout);
\r
161 @@ -555,10 +558,10 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
162 notmuch_exit_if_unsupported_format ();
\r
164 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
165 - NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
166 + NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx.notmuch))
\r
167 return EXIT_FAILURE;
\r
169 - query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
\r
170 + query_str = query_string_from_args (ctx.notmuch, argc-opt_index, argv+opt_index);
\r
171 if (query_str == NULL) {
\r
172 fprintf (stderr, "Out of memory.\n");
\r
173 return EXIT_FAILURE;
\r
174 @@ -568,7 +571,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
175 return EXIT_FAILURE;
\r
178 - ctx.query = notmuch_query_create (notmuch, query_str);
\r
179 + ctx.query = notmuch_query_create (ctx.notmuch, query_str);
\r
180 if (ctx.query == NULL) {
\r
181 fprintf (stderr, "Out of memory\n");
\r
182 return EXIT_FAILURE;
\r
183 @@ -576,15 +579,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
185 notmuch_query_set_sort (ctx.query, ctx.sort);
\r
187 - if (exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {
\r
188 + if (ctx.exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {
\r
189 /* If we are not doing summary output there is nowhere to
\r
190 * print the excluded flag so fall back on including the
\r
191 * excluded messages. */
\r
192 fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");
\r
193 - exclude = NOTMUCH_EXCLUDE_FALSE;
\r
194 + ctx.exclude = NOTMUCH_EXCLUDE_FALSE;
\r
197 - if (exclude != NOTMUCH_EXCLUDE_FALSE) {
\r
198 + if (ctx.exclude != NOTMUCH_EXCLUDE_FALSE) {
\r
199 const char **search_exclude_tags;
\r
200 size_t search_exclude_tags_length;
\r
202 @@ -592,7 +595,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
203 (config, &search_exclude_tags_length);
\r
204 for (i = 0; i < search_exclude_tags_length; i++)
\r
205 notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);
\r
206 - notmuch_query_set_omit_excluded (ctx.query, exclude);
\r
207 + notmuch_query_set_omit_excluded (ctx.query, ctx.exclude);
\r
210 if (ctx.output == OUTPUT_SUMMARY ||
\r
211 @@ -603,14 +606,14 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
212 (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))
\r
213 ret = do_search_messages (&ctx);
\r
214 else if (ctx.output == OUTPUT_TAGS)
\r
215 - ret = do_search_tags (notmuch, &ctx);
\r
216 + ret = do_search_tags (&ctx);
\r
218 fprintf (stderr, "Error: the combination of outputs is not supported.\n");
\r
222 notmuch_query_destroy (ctx.query);
\r
223 - notmuch_database_destroy (notmuch);
\r
224 + notmuch_database_destroy (ctx.notmuch);
\r
226 talloc_free (ctx.format);
\r