Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / 7a / 00a33ade2d9f21da0957b060fbe66f305d8dd8
1 Return-Path: <amdragon@mit.edu>\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 83AF0429E21\r
6         for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 08:50:10 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 Ik4EM4A199m2 for <notmuch@notmuchmail.org>;\r
16         Sun, 13 Nov 2011 08:50:09 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 6EA74431FB6\r
20         for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 08:50:09 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f6e6d0000008df-58-4ebff53e6fa7\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 70.BA.02271.E35FFBE4; Sun, 13 Nov 2011 11:50:06 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id pADGo4Id005198; \r
27         Sun, 13 Nov 2011 11:50:04 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pADGnx4e018984\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sun, 13 Nov 2011 11:50:01 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1RPdI3-0001cm-RV; Sun, 13 Nov 2011 11:52:19 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
39 Subject: Re: [PATCH v4 2/6] cli: add options --first and --maxitems to notmuch\r
40         search\r
41 In-Reply-To:\r
42  <45e0f0f47250b20b4c3372910fea4d2fd5144e20.1320615322.git.jani@nikula.org>\r
43 References: <cover.1320615322.git.jani@nikula.org>\r
44         <45e0f0f47250b20b4c3372910fea4d2fd5144e20.1320615322.git.jani@nikula.org>\r
45 User-Agent: Notmuch/0.9+29~g81d35f0 (http://notmuchmail.org) Emacs/23.3.1\r
46         (i486-pc-linux-gnu)\r
47 Date: Sun, 13 Nov 2011 11:52:19 -0500\r
48 Message-ID: <87ehxcufr0.fsf@awakening.csail.mit.edu>\r
49 MIME-Version: 1.0\r
50 Content-Type: text/plain; charset=us-ascii\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42IRYrdT0bX7ut/PYPkOE4vevYvZLG60djNa\r
53         /G+utmia7myxZ5+XxfWbM5kd2DzunubymNT1jMnj1v3X7B7PVt1i9pi09iSLx5ZD75kD2KK4\r
54         bFJSczLLUov07RK4Mqa9WsJYcM2u4uSZ5WwNjH36XYycHBICJhKNT9pZIWwxiQv31rN1MXJx\r
55         CAnsY5T4/OQ5M4SzgVHiQmMzE4RzkknixNM/UM4SRolrG36ygfSzCWhIbNu/nBHEFhGwkjj3\r
56         8DVLFyMHB7NAhUTT5ViQsLBAqMSbLZvYQMKcAmESs2+EgoSFBGokes7cZQaxRQViJY5eWcYI\r
57         UsIioCrx4qsrSJgX6NCWL3dYIGxBiZMzn4DZzAJaEjf+vWSawCg4C0lqFpLUAkamVYyyKblV\r
58         urmJmTnFqcm6xcmJeXmpRbomermZJXqpKaWbGEHhzinJv4Px20GlQ4wCHIxKPLwO0vv9hFgT\r
59         y4orcw8xSnIwKYnyXvgMFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCW7kCKMebklhZlVqUD5OS\r
60         5mBREudt3OHgJySQnliSmp2aWpBaBJOV4eBQkuDt/ALUKFiUmp5akZaZU4KQZuLgBBnOAzS8\r
61         HaSGt7ggMbc4Mx0if4pRUUqc9zJIQgAkkVGaB9cLS0evGMWBXhHm7QCp4gGmMrjuV0CDmYAG\r
62         syjsBRlckoiQkmpgXBoQxSAutO5arBYHyxGrk+tmc2WxtV9+8+kR16YQu39Pc9gKfi88kyHo\r
63         fCrl76zUBov8i2ujXP1VsssYPBf5tavrFppWiPp27163hfdL/nOlaRFKivH7/htZVYfO4bqz\r
64         zJPV498a+bnKJ0/XGMpzh58+9z2539r3V0GJad2M5C3SBy+J3OxRYinOSDTUYi4qTgQAv3Lk\r
65         LSIDAAA=\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Sun, 13 Nov 2011 16:50:10 -0000\r
79 \r
80 Code LGTM.  Some documentation nits below.\r
81 \r
82 On Sun,  6 Nov 2011 23:47:11 +0200, Jani Nikula <jani@nikula.org> wrote:\r
83 > Add options --first=[-]N and --maxitems=M to notmuch search to determine\r
84 > the first result and maximum number of results to display.\r
85\r
86 > Option --maxitems=M limits the maximum number of results to display to M.\r
87\r
88 > Option --first=[-]N skips the first N results; with the leading '-' skip\r
89 > until the Nth result from the end (showing a total of N results if within\r
90 > bounds of the total number of results and not limited with --maxitems).\r
91\r
92 > Note that --first with a negative N for thread or summary output requires\r
93 > counting the number of matching threads in advance.\r
94\r
95 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
96 > ---\r
97 >  NEWS             |    5 ++++\r
98 >  notmuch-search.c |   70 ++++++++++++++++++++++++++++++++++++++++++++---------\r
99 >  notmuch.1        |   21 ++++++++++++++-\r
100 >  3 files changed, 82 insertions(+), 14 deletions(-)\r
101\r
102 > diff --git a/NEWS b/NEWS\r
103 > index b44b11e..bfdba7b 100644\r
104 > --- a/NEWS\r
105 > +++ b/NEWS\r
106 > @@ -23,6 +23,11 @@ Add search terms to  "notmuch dump"\r
107 >    search/show/tag. The output file argument of dump is deprecated in\r
108 >    favour of using stdout.\r
109 >  \r
110 > +Add "notmuch search" --first and --maxitems options\r
111 > +\r
112 > +  The search command now takes options --first=[-]N and --maxitems=N to limit\r
113 > +  the number of results shown.\r
114 > +\r
115 >  Notmuch 0.9 (2011-10-01)\r
116 >  ========================\r
117 >  \r
118 > diff --git a/notmuch-search.c b/notmuch-search.c\r
119 > index 6f04d9a..c62a594 100644\r
120 > --- a/notmuch-search.c\r
121 > +++ b/notmuch-search.c\r
122 > @@ -194,13 +194,22 @@ static int\r
123 >  do_search_threads (const search_format_t *format,\r
124 >                  notmuch_query_t *query,\r
125 >                  notmuch_sort_t sort,\r
126 > -                output_t output)\r
127 > +                output_t output,\r
128 > +                int first,\r
129 > +                int maxitems)\r
130 >  {\r
131 >      notmuch_thread_t *thread;\r
132 >      notmuch_threads_t *threads;\r
133 >      notmuch_tags_t *tags;\r
134 >      time_t date;\r
135 >      int first_thread = 1;\r
136 > +    int i;\r
137 > +\r
138 > +    if (first < 0) {\r
139 > +     first += notmuch_query_count_threads (query);\r
140 > +     if (first < 0)\r
141 > +         first = 0;\r
142 > +    }\r
143 >  \r
144 >      threads = notmuch_query_search_threads (query);\r
145 >      if (threads == NULL)\r
146 > @@ -208,17 +217,23 @@ do_search_threads (const search_format_t *format,\r
147 >  \r
148 >      fputs (format->results_start, stdout);\r
149 >  \r
150 > -    for (;\r
151 > -      notmuch_threads_valid (threads);\r
152 > -      notmuch_threads_move_to_next (threads))\r
153 > +    for (i = 0;\r
154 > +      notmuch_threads_valid (threads) &&\r
155 > +          (maxitems < 0 || i < first + maxitems);\r
156 > +      notmuch_threads_move_to_next (threads), i++)\r
157 >      {\r
158 >       int first_tag = 1;\r
159 >  \r
160 > +     thread = notmuch_threads_get (threads);\r
161 > +\r
162 > +     if (i < first) {\r
163 > +         notmuch_thread_destroy (thread);\r
164 > +         continue;\r
165 > +     }\r
166 > +\r
167 >       if (! first_thread)\r
168 >           fputs (format->item_sep, stdout);\r
169 >  \r
170 > -     thread = notmuch_threads_get (threads);\r
171 > -\r
172 >       if (output == OUTPUT_THREADS) {\r
173 >           format->item_id (thread, "thread:",\r
174 >                            notmuch_thread_get_thread_id (thread));\r
175 > @@ -271,12 +286,21 @@ do_search_threads (const search_format_t *format,\r
176 >  static int\r
177 >  do_search_messages (const search_format_t *format,\r
178 >                   notmuch_query_t *query,\r
179 > -                 output_t output)\r
180 > +                 output_t output,\r
181 > +                 int first,\r
182 > +                 int maxitems)\r
183 >  {\r
184 >      notmuch_message_t *message;\r
185 >      notmuch_messages_t *messages;\r
186 >      notmuch_filenames_t *filenames;\r
187 >      int first_message = 1;\r
188 > +    int i;\r
189 > +\r
190 > +    if (first < 0) {\r
191 > +     first += notmuch_query_count_messages (query);\r
192 > +     if (first < 0)\r
193 > +         first = 0;\r
194 > +    }\r
195 >  \r
196 >      messages = notmuch_query_search_messages (query);\r
197 >      if (messages == NULL)\r
198 > @@ -284,10 +308,14 @@ do_search_messages (const search_format_t *format,\r
199 >  \r
200 >      fputs (format->results_start, stdout);\r
201 >  \r
202 > -    for (;\r
203 > -      notmuch_messages_valid (messages);\r
204 > -      notmuch_messages_move_to_next (messages))\r
205 > +    for (i = 0;\r
206 > +      notmuch_messages_valid (messages) &&\r
207 > +          (maxitems < 0 || i < first + maxitems);\r
208 > +      notmuch_messages_move_to_next (messages), i++)\r
209 >      {\r
210 > +     if (i < first)\r
211 > +         continue;\r
212 > +\r
213 >       message = notmuch_messages_get (messages);\r
214 >  \r
215 >       if (output == OUTPUT_FILES) {\r
216 > @@ -394,6 +422,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
217 >      const search_format_t *format = &format_text;\r
218 >      int i, ret;\r
219 >      output_t output = OUTPUT_SUMMARY;\r
220 > +    int maxitems = -1; /* unlimited */\r
221 > +    int first = 0;\r
222 >  \r
223 >      argc--; argv++; /* skip subcommand argument */\r
224 >  \r
225 > @@ -412,6 +442,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
226 >               fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
227 >               return 1;\r
228 >           }\r
229 > +     } else if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {\r
230 > +         char *p;\r
231 > +         opt = argv[i] + sizeof ("--first=") - 1;\r
232 > +         first = strtol (opt, &p, 10);\r
233 > +         if (*opt == '\0' || p == opt || *p != '\0') {\r
234 > +             fprintf (stderr, "Invalid value for --first: %s\n", opt);\r
235 > +             return 1;\r
236 > +         }\r
237 > +     } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {\r
238 > +         char *p;\r
239 > +         opt = argv[i] + sizeof ("--maxitems=") - 1;\r
240 > +         maxitems = strtoul (opt, &p, 10);\r
241 > +         if (*opt == '\0' || p == opt || *p != '\0') {\r
242 > +             fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);\r
243 > +             return 1;\r
244 > +         }\r
245 >       } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
246 >           opt = argv[i] + sizeof ("--format=") - 1;\r
247 >           if (strcmp (opt, "text") == 0) {\r
248 > @@ -478,11 +524,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
249 >      default:\r
250 >      case OUTPUT_SUMMARY:\r
251 >      case OUTPUT_THREADS:\r
252 > -     ret = do_search_threads (format, query, sort, output);\r
253 > +     ret = do_search_threads (format, query, sort, output, first, maxitems);\r
254 >       break;\r
255 >      case OUTPUT_MESSAGES:\r
256 >      case OUTPUT_FILES:\r
257 > -     ret = do_search_messages (format, query, output);\r
258 > +     ret = do_search_messages (format, query, output, first, maxitems);\r
259 >       break;\r
260 >      case OUTPUT_TAGS:\r
261 >       ret = do_search_tags (notmuch, format, query);\r
262 > diff --git a/notmuch.1 b/notmuch.1\r
263 > index bba479e..c97334c 100644\r
264 > --- a/notmuch.1\r
265 > +++ b/notmuch.1\r
266 > @@ -214,11 +214,28 @@ when sorting by\r
267 >  .B newest\-first\r
268 >  the threads will be sorted by the newest message in each thread.\r
269 >  \r
270 > -.RE\r
271 > -.RS 4\r
272 >  By default, results will be displayed in reverse chronological order,\r
273 >  (that is, the newest results will be displayed first).\r
274 > +.RE\r
275 > +\r
276 > +.RS 4\r
277 > +.TP 4\r
278 > +.BR \-\-first=[\-]N\r
279 > +\r
280 > +This option can be used to skip the display of first N results. With the\r
281 \r
282 To be consistent with the other documentation style, this should be\r
283 "Skip the display of the first N results." (or, better, "Skip displaying\r
284 the first N results.")\r
285 \r
286 > +leading '\-' skip until the Nth result from the end, showing a total of N\r
287 > +results if not otherwise bounded by total number of matching results or\r
288 > +\-\-maxitems.\r
289 \r
290 ".. if not otherwise bounded by total number of matching results .."  I\r
291 see what you're saying here, but I read this over several times before\r
292 it clicked that you were talking about being bounded by the *beginning*\r
293 of the search results, not the *end* of the search results.  I don't\r
294 think it's necessary to talk about the bounding here at all.  Obviously\r
295 it can't give you more search results than there are, and maxitems is\r
296 discussed separately.  Perhaps just "With the leading '\-', start at the\r
297 Nth result from the end."?\r
298 \r
299 > +.RE\r
300 > +\r
301 > +.RS 4\r
302 > +.TP 4\r
303 > +.BR \-\-maxitems=N\r
304 >  \r
305 > +This option can be used to limit the number of results to display to N.\r
306 \r
307 Likewise, "Limit the number results to display to N." (or, better,\r
308 "Limit the number of displayed results to N.")\r
309 \r
310 > +.RE\r
311 > +\r
312 > +.RS 4\r
313 >  See the\r
314 >  .B "SEARCH SYNTAX"\r
315 >  section below for details of the supported syntax for <search-terms>.\r
316 > -- \r
317 > 1.7.5.4\r
318\r