Error with contrib/notmuch-pick
[notmuch-archives.git] / cd / ba152eaa139ba6a606f7ba4390f55ffdc44ded
1 Return-Path: <amdragon@gmail.com>\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 38457431FD0\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Jun 2011 07:38:49 -0700 (PDT)\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=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
13         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 S+TvpbWxgSr3 for <notmuch@notmuchmail.org>;\r
17         Thu,  2 Jun 2011 07:38:48 -0700 (PDT)\r
18 Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
19         [209.85.216.181]) (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 24CD7431FB6\r
22         for <notmuch@notmuchmail.org>; Thu,  2 Jun 2011 07:38:48 -0700 (PDT)\r
23 Received: by qyg14 with SMTP id 14so525363qyg.5\r
24         for <notmuch@notmuchmail.org>; Thu, 02 Jun 2011 07:38:47 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=domainkey-signature:mime-version:sender:in-reply-to:references:date\r
27         :x-google-sender-auth:message-id:subject:from:to:cc:content-type;\r
28         bh=WGnx4TC0uJY+Q7IhUFou5EPL0Y4Nqgr7SRfsC14aEoc=;\r
29         b=Gc67lnVLks9xqaI+0qz8/sGuGVg5ESXLUVPY3ES35SAE9bta9ZTX2CYVpXm04OFK5H\r
30         HRXfjZBIoOdRdzdPp+rGo6W2RKjI8qMf8tuMp4mlX0ORKYHrZaYJuzRhdGm7vmedLe4U\r
31         S6tqk5JuqKUmt9dVGu7pYYtjFqL/JJ+QK0Pp8=\r
32 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
33         h=mime-version:sender:in-reply-to:references:date\r
34         :x-google-sender-auth:message-id:subject:from:to:cc:content-type;\r
35         b=iEanlP7mLxM9AOJjlHr1ibgHbUxyFYBcoCT7eumgIScwXgZlaZVO4t5P+U4ETpFucL\r
36         G5ts+54Itkpvy6qbll2tO+8ZPWtofwE12mMF+AMyRz3v1qBWD68XuDcx7wiiqpJBUml1\r
37         iRD/h8tiHMh4L3nJRTxHJFolv3w8ACMahFIEY=\r
38 MIME-Version: 1.0\r
39 Received: by 10.224.187.9 with SMTP id cu9mr532984qab.381.1307025527091; Thu,\r
40         02 Jun 2011 07:38:47 -0700 (PDT)\r
41 Sender: amdragon@gmail.com\r
42 Received: by 10.229.188.68 with HTTP; Thu, 2 Jun 2011 07:38:46 -0700 (PDT)\r
43 In-Reply-To: <87r57cuxgh.fsf@SSpaeth.de>\r
44 References: <1306588052-sup-9838@brick>\r
45         <BANLkTikEJ9dJ5kLg2QJQ+egHg2sh7S1wiA@mail.gmail.com>\r
46         <87aae07lxi.fsf@SSpaeth.de>\r
47         <BANLkTi=df3+LBWasFic9ZNrKaLGA7Bmdew@mail.gmail.com>\r
48         <87r57cuxgh.fsf@SSpaeth.de>\r
49 Date: Thu, 2 Jun 2011 10:38:46 -0400\r
50 X-Google-Sender-Auth: 0ESy2bkvXgnvGVXhVHQ2pab55KI\r
51 Message-ID: <BANLkTimMqJJLWx8AfLz8CKuOWjky_HR0Ag@mail.gmail.com>\r
52 Subject: Re: [python] get all messages of a thread\r
53 From: Austin Clements <amdragon@mit.edu>\r
54 To: Sebastian Spaeth <Sebastian@sspaeth.de>\r
55 Content-Type: text/plain; charset=ISO-8859-1\r
56 Cc: notmuch <notmuch@notmuchmail.org>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Thu, 02 Jun 2011 14:38:49 -0000\r
70 \r
71 On Thu, Jun 2, 2011 at 10:20 AM, Sebastian Spaeth <Sebastian@sspaeth.de> wrote:\r
72 > On Thu, 2 Jun 2011 19:43:29 +1000, Brian May wrote:\r
73 >> On 2 June 2011 17:05, Sebastian Spaeth <Sebastian@sspaeth.de> wrote:\r
74 >>\r
75 >> > What would be the best way to solve this (besides fixing the C api to\r
76 >> > allow to reset the iterator ;-) ?)\r
77 >\r
78 >> * It is not easy to fix the C api to reset the iterator (what about\r
79 >> repeating the search?)\r
80 >\r
81 > I am not sure about the difficulty of that, I am not a C-kind of\r
82 > guy. Repeating the search would be easy but potentially gives you\r
83 > different results since the db could have changed since then.\r
84 \r
85 Not too hard.  Here's an utterly untested patch that implements\r
86 iterator resetting for notmuch_messages_t iterators.  It *should* be\r
87 much more efficient than performing the query again, but if you use\r
88 it, I'd love to know if that's actually true.\r
89 \r
90 This may not be useful if __len__ is gone, unless you really want to\r
91 turn Messages/Threads into iterators rather than generators (as I've\r
92 pointed out before, there is absolutely nothing unusual or un-Pythonic\r
93 about how Messages/Threads works right now [well, except for the\r
94 presence of __len__ in a generator, I suppose]).\r
95 \r
96 diff --git a/lib/messages.c b/lib/messages.c\r
97 index 7bcd1ab..085691c 100644\r
98 --- a/lib/messages.c\r
99 +++ b/lib/messages.c\r
100 @@ -80,7 +80,8 @@ _notmuch_messages_create (notmuch_message_list_t *list)\r
101         return NULL;\r
102 \r
103      messages->is_of_list_type = TRUE;\r
104 -    messages->iterator = list->head;\r
105 +    messages->head = list->head;\r
106 +    notmuch_messages_reset (messages);\r
107 \r
108      return messages;\r
109  }\r
110 @@ -137,6 +138,15 @@ notmuch_messages_move_to_next (notmuch_messages_t\r
111 *messages)\r
112  }\r
113 \r
114  void\r
115 +notmuch_messages_reset (notmuch_messages_t *messages)\r
116 +{\r
117 +    if (! messages->is_of_list_type)\r
118 +       return _notmuch_mset_messages_reset (messages);\r
119 +\r
120 +    messages->iterator = messages->head;\r
121 +}\r
122 +\r
123 +void\r
124  notmuch_messages_destroy (notmuch_messages_t *messages)\r
125  {\r
126      talloc_free (messages);\r
127 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
128 index 02e24ee..805d60c 100644\r
129 --- a/lib/notmuch-private.h\r
130 +++ b/lib/notmuch-private.h\r
131 @@ -413,6 +413,7 @@ typedef struct _notmuch_message_list {\r
132   */\r
133  struct visible _notmuch_messages {\r
134      notmuch_bool_t is_of_list_type;\r
135 +    notmuch_message_node_t *head;\r
136      notmuch_message_node_t *iterator;\r
137  };\r
138 \r
139 @@ -441,6 +442,9 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages);\r
140  void\r
141  _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages);\r
142 \r
143 +void\r
144 +_notmuch_mset_messages_reset (notmuch_messages_t *messages);\r
145 +\r
146  notmuch_bool_t\r
147  _notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids,\r
148                                unsigned int doc_id);\r
149 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
150 index 9cdcec0..044cfaa 100644\r
151 --- a/lib/notmuch.h\r
152 +++ b/lib/notmuch.h\r
153 @@ -734,6 +734,15 @@ notmuch_messages_get (notmuch_messages_t *messages);\r
154  void\r
155  notmuch_messages_move_to_next (notmuch_messages_t *messages);\r
156 \r
157 +/* Reset the 'messages' iterator back to the first message.\r
158 + *\r
159 + * For iterators returned from notmuch_query_search_messages, this is\r
160 + * both more efficient than performing the query a second time and\r
161 + * guaranteed to result in the same messages as the first iteration.\r
162 + */\r
163 +void\r
164 +notmuch_messages_reset (notmuch_messages_t *messages);\r
165 +\r
166  /* Destroy a notmuch_messages_t object.\r
167   *\r
168   * It's not strictly necessary to call this function. All memory from\r
169 diff --git a/lib/query.cc b/lib/query.cc\r
170 index 6f02b04..1e75be0 100644\r
171 --- a/lib/query.cc\r
172 +++ b/lib/query.cc\r
173 @@ -32,6 +32,7 @@ struct _notmuch_query {\r
174  typedef struct _notmuch_mset_messages {\r
175      notmuch_messages_t base;\r
176      notmuch_database_t *notmuch;\r
177 +    Xapian::MSet mset;\r
178      Xapian::MSetIterator iterator;\r
179      Xapian::MSetIterator iterator_end;\r
180  } notmuch_mset_messages_t;\r
181 @@ -128,6 +129,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
182         messages->base.is_of_list_type = FALSE;\r
183         messages->base.iterator = NULL;\r
184         messages->notmuch = notmuch;\r
185 +       new (&messages->mset) Xapian::MSet ();\r
186         new (&messages->iterator) Xapian::MSetIterator ();\r
187         new (&messages->iterator_end) Xapian::MSetIterator ();\r
188 \r
189 @@ -181,8 +183,8 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
190 \r
191         mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
192 \r
193 -       messages->iterator = mset.begin ();\r
194 -       messages->iterator_end = mset.end ();\r
195 +       messages->mset = mset;\r
196 +       _notmuch_mset_messages_reset (&messages->base);\r
197 \r
198         return &messages->base;\r
199 \r
200 @@ -257,6 +259,17 @@ _notmuch_mset_messages_move_to_next\r
201 (notmuch_messages_t *messages)\r
202      mset_messages->iterator++;\r
203  }\r
204 \r
205 +void\r
206 +_notmuch_mset_messages_reset (notmuch_messages_t *messages)\r
207 +{\r
208 +    notmuch_mset_messages_t *mset_messages;\r
209 +\r
210 +    mset_messages = (notmuch_mset_messages_t *) messages;\r
211 +\r
212 +    mset_messages->iterator = mset_messages->mset.begin ();\r
213 +    mset_messages->iterator_end = mset_messages->mset.end ();\r
214 +}\r
215 +\r
216  static notmuch_bool_t\r
217  _notmuch_doc_id_set_init (void *ctx,\r
218                           notmuch_doc_id_set_t *doc_ids,\r