Re: Flat search and threaded views
[notmuch-archives.git] / 38 / 29cad55131f2a44bb4edb8a6b86bbddfce766f
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 0253A431FAF\r
6         for <notmuch@notmuchmail.org>; Sun,  4 Nov 2012 02:21:04 -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.699\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
12         tests=[HTML_MESSAGE=0.001, 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 pmrY5ULl70g2 for <notmuch@notmuchmail.org>;\r
16         Sun,  4 Nov 2012 02:21:03 -0800 (PST)\r
17 Received: from mail-oa0-f53.google.com (mail-oa0-f53.google.com\r
18         [209.85.219.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 046CD431FAE\r
21         for <notmuch@notmuchmail.org>; Sun,  4 Nov 2012 02:21:02 -0800 (PST)\r
22 Received: by mail-oa0-f53.google.com with SMTP id j6so5171694oag.26\r
23         for <notmuch@notmuchmail.org>; Sun, 04 Nov 2012 02:21:02 -0800 (PST)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=mime-version:in-reply-to:references:date:message-id:subject:from:to\r
27         :cc:content-type:x-gm-message-state;\r
28         bh=zXSpgS3DMSzKlCOsj6qCbUDqK64q4wfMITJmEamc3zU=;\r
29         b=epCEiDFpj5uOPRlHcg3XUPubgEI8yDb0b9jNpF3mBg6LNowsC5sPB2Wwaouwrw7Y8w\r
30         lEjlm4N+Aic3G2zYkBCYtlVXreNQXT59jr7JJeBEGQoSib4DfcTLN+TPLi72e8ybx3/O\r
31         XcEEjI8pntMCCFmS3E5ZYH9NIQJ/vOugAEas8Tof6cCwoQEN5aD4iz5UDpUcArL7pNJD\r
32         EuXb8TOmKkB3acEM/N+U9WJkwiSaDPryMRZe7Mt6aq94YdTZMRNOCiJR96P7W2N+RMgD\r
33         gbkZfNsXiQ0WKfBi/XNFmyPmKGjRxuKlcmgBiSzJyQZzhiwoRciGgSRp7g9Yo1pkwIMT\r
34         Dc7A==\r
35 MIME-Version: 1.0\r
36 Received: by 10.60.19.168 with SMTP id g8mr5235227oee.101.1352024461364; Sun,\r
37         04 Nov 2012 02:21:01 -0800 (PST)\r
38 Received: by 10.76.69.138 with HTTP; Sun, 4 Nov 2012 02:21:01 -0800 (PST)\r
39 Received: by 10.76.69.138 with HTTP; Sun, 4 Nov 2012 02:21:01 -0800 (PST)\r
40 In-Reply-To: <1351998962-25135-11-git-send-email-blakej@foo.net>\r
41 References: <1351998962-25135-1-git-send-email-blakej@foo.net>\r
42         <1351998962-25135-11-git-send-email-blakej@foo.net>\r
43 Date: Sun, 4 Nov 2012 12:21:01 +0200\r
44 Message-ID:\r
45  <CAB+hUn-HBMnbrxQtn4E1RkKJa-wUEvm2HbdvtDxJGrv3jmtQdw@mail.gmail.com>\r
46 Subject: Re: [PATCH 10/10] timegm: add portable implementation (Solaris\r
47         support)\r
48 From: Jani Nikula <jani@nikula.org>\r
49 To: Blake Jones <blakej@foo.net>\r
50 Content-Type: multipart/alternative; boundary=e89a8fb2062cbf4fcf04cda8b931\r
51 X-Gm-Message-State:\r
52  ALoCoQn8vvIW7D7MKT4K4oUEILFZhdWQoLdHoC0rzjt/+cpov8pWrU3mjywLJxzGQbVepmLRh9xd\r
53 Cc: notmuch@notmuchmail.org\r
54 X-BeenThere: notmuch@notmuchmail.org\r
55 X-Mailman-Version: 2.1.13\r
56 Precedence: list\r
57 List-Id: "Use and development of the notmuch mail system."\r
58         <notmuch.notmuchmail.org>\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
62 List-Post: <mailto:notmuch@notmuchmail.org>\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
66 X-List-Received-Date: Sun, 04 Nov 2012 10:21:04 -0000\r
67 \r
68 --e89a8fb2062cbf4fcf04cda8b931\r
69 Content-Type: text/plain; charset=UTF-8\r
70 \r
71 On Nov 4, 2012 11:30 AM, "Blake Jones" <blakej@foo.net> wrote:\r
72 >\r
73 > The timegm(3) function is a non-standard extension to libc which is\r
74 > available in GNU libc and on some BSDs.  Although SunOS had this\r
75 > function in its libc, Solaris (unfortunately) removed it.  This patch\r
76 > implements a very simple version of timegm() which is good enough for\r
77 > parse-time-string.c.\r
78 >\r
79 > Although notmuch's idiom for portability is to test for native\r
80 > availability and put alternate versions in compat/, that approach led to\r
81 > a compilation problem in this case.  libnotmuch.a includes a call to\r
82 > parse_time_string() from parse-time-vrp.o, and parse_time_string() in\r
83 > libparse-time-string.a needs to call timegm().  An attempt to create\r
84 > compat/timegm.c caused the link to fail, because libparse-time-string.a\r
85 > acquired a dependency on the new timegm.o in libnotmuch.a, and the\r
86 > linker only does a single pass on each ".a" looking for dependencies.\r
87 > This seems to be the case both for the GNU linker and the Solaris\r
88 > linker.  A different possible workaround would have been to include\r
89 > libnotmuch.a multiple times on the link line, but that seemed like a\r
90 > brittle way to track this dependency.\r
91 \r
92 I'd prefer to use timegm() where available, and the suggested alternative\r
93 [1] elsewhere. I'll look into the compat build issues when I have a moment.\r
94 \r
95 Jani.\r
96 \r
97 [1] http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.html\r
98 \r
99 > ---\r
100 >  parse-time-string/parse-time-string.c |   37\r
101 ++++++++++++++++++++++++++++++++-\r
102 >  1 file changed, 36 insertions(+), 1 deletion(-)\r
103 >\r
104 > diff --git a/parse-time-string/parse-time-string.c\r
105 b/parse-time-string/parse-time-string.c\r
106 > index 584067d..28901af 100644\r
107 > --- a/parse-time-string/parse-time-string.c\r
108 > +++ b/parse-time-string/parse-time-string.c\r
109 > @@ -1315,6 +1315,41 @@ fixup_ampm (struct state *state)\r
110 >      return 0;\r
111 >  }\r
112 >\r
113 > +static int\r
114 > +leapyear (int year)\r
115 > +{\r
116 > +    return ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0));\r
117 > +}\r
118 > +\r
119 > +/*\r
120 > + * This is a simple implementation of timegm() which does what is needed\r
121 > + * by create_output() -- just turns the "struct tm" into a GMT time_t.\r
122 > + * It does not normalize any of the fields of the "struct tm", nor does\r
123 > + * it set tm_wday or tm_yday.\r
124 > + */\r
125 > +static time_t\r
126 > +local_timegm (struct tm *tm)\r
127 > +{\r
128 > +    int        monthlen[2][12] = {\r
129 > +       { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
130 > +       { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },\r
131 > +    };\r
132 > +    int        year, month, days;\r
133 > +\r
134 > +    days = 365 * (tm->tm_year - 70);\r
135 > +    for (year = 70; year < tm->tm_year; year++) {\r
136 > +       if (leapyear(1900 + year)) {\r
137 > +           days++;\r
138 > +       }\r
139 > +    }\r
140 > +    for (month = 0; month < tm->tm_mon; month++) {\r
141 > +       days += monthlen[leapyear(1900 + year)][month];\r
142 > +    }\r
143 > +    days += tm->tm_mday - 1;\r
144 > +\r
145 > +    return ((((days * 24) + tm->tm_hour) * 60 + tm->tm_min) * 60 +\r
146 tm->tm_sec);\r
147 > +}\r
148 > +\r
149 >  /* Combine absolute and relative fields, and round. */\r
150 >  static int\r
151 >  create_output (struct state *state, time_t *t_out, const time_t *ref,\r
152 > @@ -1465,7 +1500,7 @@ create_output (struct state *state, time_t *t_out,\r
153 const time_t *ref,\r
154 >      if (is_field_set (state, TM_TZ)) {\r
155 >         /* tm is in specified TZ, convert to UTC for timegm(3). */\r
156 >         tm.tm_min -= get_field (state, TM_TZ);\r
157 > -       t = timegm (&tm);\r
158 > +       t = local_timegm (&tm);\r
159 >      } else {\r
160 >         /* tm is in local time. */\r
161 >         t = mktime (&tm);\r
162 > --\r
163 > 1.7.9.2\r
164 >\r
165 > _______________________________________________\r
166 > notmuch mailing list\r
167 > notmuch@notmuchmail.org\r
168 > http://notmuchmail.org/mailman/listinfo/notmuch\r
169 \r
170 --e89a8fb2062cbf4fcf04cda8b931\r
171 Content-Type: text/html; charset=UTF-8\r
172 Content-Transfer-Encoding: quoted-printable\r
173 \r
174 <p><br>\r
175 On Nov 4, 2012 11:30 AM, &quot;Blake Jones&quot; &lt;<a href=3D"mailto:blak=\r
176 ej@foo.net">blakej@foo.net</a>&gt; wrote:<br>\r
177 &gt;<br>\r
178 &gt; The timegm(3) function is a non-standard extension to libc which is<br=\r
179 >\r
180 &gt; available in GNU libc and on some BSDs. =C2=A0Although SunOS had this<=\r
181 br>\r
182 &gt; function in its libc, Solaris (unfortunately) removed it. =C2=A0This p=\r
183 atch<br>\r
184 &gt; implements a very simple version of timegm() which is good enough for<=\r
185 br>\r
186 &gt; parse-time-string.c.<br>\r
187 &gt;<br>\r
188 &gt; Although notmuch&#39;s idiom for portability is to test for native<br>\r
189 &gt; availability and put alternate versions in compat/, that approach led =\r
190 to<br>\r
191 &gt; a compilation problem in this case. =C2=A0libnotmuch.a includes a call=\r
192  to<br>\r
193 &gt; parse_time_string() from parse-time-vrp.o, and parse_time_string() in<=\r
194 br>\r
195 &gt; libparse-time-string.a needs to call timegm(). =C2=A0An attempt to cre=\r
196 ate<br>\r
197 &gt; compat/timegm.c caused the link to fail, because libparse-time-string.=\r
198 a<br>\r
199 &gt; acquired a dependency on the new timegm.o in libnotmuch.a, and the<br>\r
200 &gt; linker only does a single pass on each &quot;.a&quot; looking for depe=\r
201 ndencies.<br>\r
202 &gt; This seems to be the case both for the GNU linker and the Solaris<br>\r
203 &gt; linker. =C2=A0A different possible workaround would have been to inclu=\r
204 de<br>\r
205 &gt; libnotmuch.a multiple times on the link line, but that seemed like a<b=\r
206 r>\r
207 &gt; brittle way to track this dependency.</p>\r
208 <p>I&#39;d prefer to use timegm() where available, and the suggested altern=\r
209 ative [1] elsewhere. I&#39;ll look into the compat build issues when I have=\r
210  a moment.</p>\r
211 <p>Jani.</p>\r
212 <p>[1] <a href=3D"http://www.kernel.org/doc/man-pages/online/pages/man3/tim=\r
213 egm.3.html">http://www.kernel.org/doc/man-pages/online/pages/man3/timegm.3.=\r
214 html</a><br></p>\r
215 <p>&gt; ---<br>\r
216 &gt; =C2=A0parse-time-string/parse-time-string.c | =C2=A0 37 ++++++++++++++=\r
217 ++++++++++++++++++-<br>\r
218 &gt; =C2=A01 file changed, 36 insertions(+), 1 deletion(-)<br>\r
219 &gt;<br>\r
220 &gt; diff --git a/parse-time-string/parse-time-string.c b/parse-time-string=\r
221 /parse-time-string.c<br>\r
222 &gt; index 584067d..28901af 100644<br>\r
223 &gt; --- a/parse-time-string/parse-time-string.c<br>\r
224 &gt; +++ b/parse-time-string/parse-time-string.c<br>\r
225 &gt; @@ -1315,6 +1315,41 @@ fixup_ampm (struct state *state)<br>\r
226 &gt; =C2=A0 =C2=A0 =C2=A0return 0;<br>\r
227 &gt; =C2=A0}<br>\r
228 &gt;<br>\r
229 &gt; +static int<br>\r
230 &gt; +leapyear (int year)<br>\r
231 &gt; +{<br>\r
232 &gt; + =C2=A0 =C2=A0return ((year % 4) =3D=3D 0 &amp;&amp; ((year % 100) !=\r
233 =3D 0 || (year % 400) =3D=3D 0));<br>\r
234 &gt; +}<br>\r
235 &gt; +<br>\r
236 &gt; +/*<br>\r
237 &gt; + * This is a simple implementation of timegm() which does what is nee=\r
238 ded<br>\r
239 &gt; + * by create_output() -- just turns the &quot;struct tm&quot; into a =\r
240 GMT time_t.<br>\r
241 &gt; + * It does not normalize any of the fields of the &quot;struct tm&quo=\r
242 t;, nor does<br>\r
243 &gt; + * it set tm_wday or tm_yday.<br>\r
244 &gt; + */<br>\r
245 &gt; +static time_t<br>\r
246 &gt; +local_timegm (struct tm *tm)<br>\r
247 &gt; +{<br>\r
248 &gt; + =C2=A0 =C2=A0int =C2=A0 =C2=A0 =C2=A0 =C2=A0monthlen[2][12] =3D {<br=\r
249 >\r
250 &gt; + =C2=A0 =C2=A0 =C2=A0 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3=\r
251 1 },<br>\r
252 &gt; + =C2=A0 =C2=A0 =C2=A0 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3=\r
253 1 },<br>\r
254 &gt; + =C2=A0 =C2=A0};<br>\r
255 &gt; + =C2=A0 =C2=A0int =C2=A0 =C2=A0 =C2=A0 =C2=A0year, month, days;<br>\r
256 &gt; +<br>\r
257 &gt; + =C2=A0 =C2=A0days =3D 365 * (tm-&gt;tm_year - 70);<br>\r
258 &gt; + =C2=A0 =C2=A0for (year =3D 70; year &lt; tm-&gt;tm_year; year++) {<b=\r
259 r>\r
260 &gt; + =C2=A0 =C2=A0 =C2=A0 if (leapyear(1900 + year)) {<br>\r
261 &gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 days++;<br>\r
262 &gt; + =C2=A0 =C2=A0 =C2=A0 }<br>\r
263 &gt; + =C2=A0 =C2=A0}<br>\r
264 &gt; + =C2=A0 =C2=A0for (month =3D 0; month &lt; tm-&gt;tm_mon; month++) {<=\r
265 br>\r
266 &gt; + =C2=A0 =C2=A0 =C2=A0 days +=3D monthlen[leapyear(1900 + year)][month=\r
267 ];<br>\r
268 &gt; + =C2=A0 =C2=A0}<br>\r
269 &gt; + =C2=A0 =C2=A0days +=3D tm-&gt;tm_mday - 1;<br>\r
270 &gt; +<br>\r
271 &gt; + =C2=A0 =C2=A0return ((((days * 24) + tm-&gt;tm_hour) * 60 + tm-&gt;t=\r
272 m_min) * 60 + tm-&gt;tm_sec);<br>\r
273 &gt; +}<br>\r
274 &gt; +<br>\r
275 &gt; =C2=A0/* Combine absolute and relative fields, and round. */<br>\r
276 &gt; =C2=A0static int<br>\r
277 &gt; =C2=A0create_output (struct state *state, time_t *t_out, const time_t =\r
278 *ref,<br>\r
279 &gt; @@ -1465,7 +1500,7 @@ create_output (struct state *state, time_t *t_ou=\r
280 t, const time_t *ref,<br>\r
281 &gt; =C2=A0 =C2=A0 =C2=A0if (is_field_set (state, TM_TZ)) {<br>\r
282 &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* tm is in specified TZ, convert to UTC f=\r
283 or timegm(3). */<br>\r
284 &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 tm.tm_min -=3D get_field (state, TM_TZ);<b=\r
285 r>\r
286 &gt; - =C2=A0 =C2=A0 =C2=A0 t =3D timegm (&amp;tm);<br>\r
287 &gt; + =C2=A0 =C2=A0 =C2=A0 t =3D local_timegm (&amp;tm);<br>\r
288 &gt; =C2=A0 =C2=A0 =C2=A0} else {<br>\r
289 &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* tm is in local time. */<br>\r
290 &gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 t =3D mktime (&amp;tm);<br>\r
291 &gt; --<br>\r
292 &gt; 1.7.9.2<br>\r
293 &gt;<br>\r
294 &gt; _______________________________________________<br>\r
295 &gt; notmuch mailing list<br>\r
296 &gt; <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=\r
297 <br>\r
298 &gt; <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=\r
299 muchmail.org/mailman/listinfo/notmuch</a><br>\r
300 </p>\r
301 \r
302 --e89a8fb2062cbf4fcf04cda8b931--\r