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 0A601431FD0
\r
6 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 14:14:26 -0700 (PDT)
\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 efgAb6eM-7lM for <notmuch@notmuchmail.org>;
\r
16 Thu, 30 Oct 2014 14:14:18 -0700 (PDT)
\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 6D7EA431FCB
\r
19 for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 14:14:18 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 7B66619F373C;
\r
22 Thu, 30 Oct 2014 22:14:15 +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
27 with ESMTP id k_YH2tZCUAxV; Thu, 30 Oct 2014 22:14:11 +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 1DCF719F373D;
\r
30 Thu, 30 Oct 2014 22:14:11 +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 1Xjx2i-0005ca-9c; Thu, 30 Oct 2014 22:14:04 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org
\r
36 Subject: Re: [PATCH v4 1/6] cli: search: Refactor passing of command line
\r
38 In-Reply-To: <87k33iuh0m.fsf@qmul.ac.uk>
\r
39 References: <1414421455-3037-1-git-send-email-sojkam1@fel.cvut.cz>
\r
40 <1414421455-3037-2-git-send-email-sojkam1@fel.cvut.cz>
\r
41 <87k33iuh0m.fsf@qmul.ac.uk>
\r
42 User-Agent: Notmuch/0.18.2+157~ga00d359 (http://notmuchmail.org) Emacs/24.3.1
\r
43 (x86_64-pc-linux-gnu)
\r
44 Date: Thu, 30 Oct 2014 22:14:04 +0100
\r
45 Message-ID: <878ujxclb7.fsf@steelpick.2x.cz>
\r
47 Content-Type: text/plain
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Thu, 30 Oct 2014 21:14:26 -0000
\r
64 On Thu, Oct 30 2014, Mark Walters wrote:
\r
67 > On Mon, 27 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
\r
68 >> Many functions that implement the search command need to access command
\r
69 >> line options. Instead of passing each option in a separate variable, put
\r
70 >> them in a structure and pass only this structure.
\r
72 >> This will become handy in the following patches.
\r
74 >> notmuch-search.c | 125 ++++++++++++++++++++++++++++---------------------------
\r
75 >> 1 file changed, 64 insertions(+), 61 deletions(-)
\r
77 >> diff --git a/notmuch-search.c b/notmuch-search.c
\r
78 >> index bc9be45..0c3e972 100644
\r
79 >> --- a/notmuch-search.c
\r
80 >> +++ b/notmuch-search.c
\r
81 >> @@ -30,6 +30,16 @@ typedef enum {
\r
85 >> +typedef struct {
\r
86 >> + sprinter_t *format;
\r
87 >> + notmuch_query_t *query;
\r
88 >> + notmuch_sort_t sort;
\r
89 >> + output_t output;
\r
93 >> +} search_options_t;
\r
95 >> /* Return two stable query strings that identify exactly the matched
\r
96 >> * and unmatched messages currently in thread. If there are no
\r
97 >> * matched or unmatched messages, the returned buffers will be
\r
98 >> @@ -70,43 +80,39 @@ get_thread_query (notmuch_thread_t *thread,
\r
102 >> -do_search_threads (sprinter_t *format,
\r
103 >> - notmuch_query_t *query,
\r
104 >> - notmuch_sort_t sort,
\r
105 >> - output_t output,
\r
108 >> +do_search_threads (search_options_t *opt)
\r
110 >> notmuch_thread_t *thread;
\r
111 >> notmuch_threads_t *threads;
\r
112 >> notmuch_tags_t *tags;
\r
113 >> + sprinter_t *format = opt->format;
\r
117 >> - if (offset < 0) {
\r
118 >> - offset += notmuch_query_count_threads (query);
\r
119 >> - if (offset < 0)
\r
121 >> + if (opt->offset < 0) {
\r
122 >> + opt->offset += notmuch_query_count_threads (opt->query);
\r
123 >> + if (opt->offset < 0)
\r
124 >> + opt->offset = 0;
\r
127 >> - threads = notmuch_query_search_threads (query);
\r
128 >> + threads = notmuch_query_search_threads (opt->query);
\r
129 >> if (threads == NULL)
\r
132 >> format->begin_list (format);
\r
135 >> - notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);
\r
136 >> + notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
137 >> notmuch_threads_move_to_next (threads), i++)
\r
139 >> thread = notmuch_threads_get (threads);
\r
141 >> - if (i < offset) {
\r
142 >> + if (i < opt->offset) {
\r
143 >> notmuch_thread_destroy (thread);
\r
147 >> - if (output == OUTPUT_THREADS) {
\r
148 >> + if (opt->output == OUTPUT_THREADS) {
\r
149 >> format->set_prefix (format, "thread");
\r
150 >> format->string (format,
\r
151 >> notmuch_thread_get_thread_id (thread));
\r
152 >> @@ -123,7 +129,7 @@ do_search_threads (sprinter_t *format,
\r
154 >> format->begin_map (format);
\r
156 >> - if (sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
157 >> + if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
158 >> date = notmuch_thread_get_oldest_date (thread);
\r
160 >> date = notmuch_thread_get_newest_date (thread);
\r
161 >> @@ -215,40 +221,36 @@ do_search_threads (sprinter_t *format,
\r
165 >> -do_search_messages (sprinter_t *format,
\r
166 >> - notmuch_query_t *query,
\r
167 >> - output_t output,
\r
171 >> +do_search_messages (search_options_t *opt)
\r
173 >> notmuch_message_t *message;
\r
174 >> notmuch_messages_t *messages;
\r
175 >> notmuch_filenames_t *filenames;
\r
176 >> + sprinter_t *format = opt->format;
\r
179 >> - if (offset < 0) {
\r
180 >> - offset += notmuch_query_count_messages (query);
\r
181 >> - if (offset < 0)
\r
183 >> + if (opt->offset < 0) {
\r
184 >> + opt->offset += notmuch_query_count_messages (opt->query);
\r
185 >> + if (opt->offset < 0)
\r
186 >> + opt->offset = 0;
\r
189 >> - messages = notmuch_query_search_messages (query);
\r
190 >> + messages = notmuch_query_search_messages (opt->query);
\r
191 >> if (messages == NULL)
\r
194 >> format->begin_list (format);
\r
197 >> - notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit);
\r
198 >> + notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
199 >> notmuch_messages_move_to_next (messages), i++)
\r
201 >> - if (i < offset)
\r
202 >> + if (i < opt->offset)
\r
205 >> message = notmuch_messages_get (messages);
\r
207 >> - if (output == OUTPUT_FILES) {
\r
208 >> + if (opt->output == OUTPUT_FILES) {
\r
210 >> filenames = notmuch_message_get_filenames (message);
\r
212 >> @@ -256,7 +258,7 @@ do_search_messages (sprinter_t *format,
\r
213 >> notmuch_filenames_valid (filenames);
\r
214 >> notmuch_filenames_move_to_next (filenames), j++)
\r
216 >> - if (dupe < 0 || dupe == j) {
\r
217 >> + if (opt->dupe < 0 || opt->dupe == j) {
\r
218 >> format->string (format, notmuch_filenames_get (filenames));
\r
219 >> format->separator (format);
\r
221 >> @@ -283,12 +285,13 @@ do_search_messages (sprinter_t *format,
\r
224 >> do_search_tags (notmuch_database_t *notmuch,
\r
225 >> - sprinter_t *format,
\r
226 >> - notmuch_query_t *query)
\r
227 >> + const search_options_t *opt)
\r
230 > What about leaving out the *notmuch argument and getting that from the
\r
231 > query (query->notmuch I think)?
\r
233 I was also thinking about this, but notmuch_query_t is an opaque
\r
234 structure which means that we would need a getter function in the
\r
235 library. I think it is simpler to have it this way.
\r