Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / 57 / 1dace430ce584fe7c673c073424212049d5e0d
1 Return-Path: <amthrax@awakening.csail.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 8D3C6431FB6\r
6         for <notmuch@notmuchmail.org>; Thu,  9 Dec 2010 13:00:42 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 LvZ6sl0KU3kC for <notmuch@notmuchmail.org>;\r
16         Thu,  9 Dec 2010 13:00:39 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id D2C6F41A54C\r
20         for <notmuch@notmuchmail.org>; Thu,  9 Dec 2010 13:00:34 -0800 (PST)\r
21 X-AuditID: 12074422-b7c3eae000000a70-03-4d01437258e2\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id DE.D7.02672.273410D4; Thu,  9 Dec 2010 16:00:34 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id oB9L0YZR026448; \r
27         Thu, 9 Dec 2010 16:00:34 -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 oB9L0XPF010109\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Thu, 9 Dec 2010 16:00:34 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)\r
35         (envelope-from <amthrax@awakening.csail.mit.edu>)\r
36         id 1PQnbN-0007Hs-6j; Thu, 09 Dec 2010 16:00:33 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 3/5] Add a generic function to get a list of terms with some\r
40         prefix.\r
41 Date: Thu,  9 Dec 2010 15:59:54 -0500\r
42 Message-Id: <1291928396-27937-4-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.2.3\r
44 In-Reply-To: <1291928396-27937-1-git-send-email-amdragon@mit.edu>\r
45 References: <1291928396-27937-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker: AAAAAA==\r
47 Cc: Austin Clements <amdragon@mit.edu>\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\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, 09 Dec 2010 21:00:43 -0000\r
61 \r
62 Replace _notmuch_convert_tags with this and simplify\r
63 _create_filenames_for_terms_with_prefix.  This will also come in handy\r
64 shortly to get the message file name list.\r
65 ---\r
66  lib/database-private.h |   16 +++++++---------\r
67  lib/database.cc        |   36 ++++++++++++++----------------------\r
68  lib/directory.cc       |   18 +++---------------\r
69  lib/message.cc         |    6 +++++-\r
70  4 files changed, 29 insertions(+), 47 deletions(-)\r
71 \r
72 diff --git a/lib/database-private.h b/lib/database-private.h\r
73 index 140b54e..9f83407 100644\r
74 --- a/lib/database-private.h\r
75 +++ b/lib/database-private.h\r
76 @@ -53,18 +53,16 @@ struct _notmuch_database {\r
77      Xapian::ValueRangeProcessor *value_range_processor;\r
78  };\r
79  \r
80 -/* Convert tags from Xapian internal format to notmuch format.\r
81 - *\r
82 - * The function gets a TermIterator as argument and uses that iterator to find\r
83 - * all tag terms in the object. The tags are then converted to a\r
84 - * notmuch_tags_t list and returned. The function needs to allocate memory for\r
85 - * the resulting list and it uses the argument ctx as talloc context.\r
86 +/* Return the list of terms from the given iterator matching a prefix.\r
87 + * The prefix will be stripped from the strings in the returned list.\r
88 + * The list will be allocated using ctx as the talloc context.\r
89   *\r
90   * The function returns NULL on failure.\r
91   */\r
92 -notmuch_tags_t *\r
93 -_notmuch_convert_tags (void *ctx, Xapian::TermIterator &i,\r
94 -                      Xapian::TermIterator &end);\r
95 +notmuch_string_list_t *\r
96 +_notmuch_get_terms_with_prefix (void *ctx, Xapian::TermIterator &i,\r
97 +                               Xapian::TermIterator &end,\r
98 +                               const char *prefix);\r
99  \r
100  #pragma GCC visibility pop\r
101  \r
102 diff --git a/lib/database.cc b/lib/database.cc\r
103 index 45613bd..f8245ab 100644\r
104 --- a/lib/database.cc\r
105 +++ b/lib/database.cc\r
106 @@ -1747,49 +1747,41 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,\r
107      return status;\r
108  }\r
109  \r
110 -notmuch_tags_t *\r
111 -_notmuch_convert_tags (void *ctx, Xapian::TermIterator &i,\r
112 -                      Xapian::TermIterator &end)\r
113 +notmuch_string_list_t *\r
114 +_notmuch_get_terms_with_prefix (void *ctx, Xapian::TermIterator &i,\r
115 +                               Xapian::TermIterator &end,\r
116 +                               const char *prefix)\r
117  {\r
118 -    const char *prefix = _find_prefix ("tag");\r
119 +    int prefix_len = strlen (prefix);\r
120      notmuch_string_list_t *list;\r
121 -    std::string tag;\r
122 -\r
123 -    /* Currently this iteration is written with the assumption that\r
124 -     * "tag" has a single-character prefix. */\r
125 -    assert (strlen (prefix) == 1);\r
126  \r
127      list = _notmuch_string_list_create (ctx);\r
128      if (unlikely (list == NULL))\r
129         return NULL;\r
130  \r
131 -    i.skip_to (prefix);\r
132 -\r
133 -    while (i != end) {\r
134 -       tag = *i;\r
135 -\r
136 -       if (tag.empty () || tag[0] != *prefix)\r
137 +    for (i.skip_to (prefix); i != end; i++) {\r
138 +       /* Terminate loop at first term without desired prefix. */\r
139 +       if (strncmp ((*i).c_str (), prefix, prefix_len))\r
140             break;\r
141  \r
142 -       _notmuch_string_list_append (list, tag.c_str () + 1);\r
143 -\r
144 -       i++;\r
145 +       _notmuch_string_list_append (list, (*i).c_str () + prefix_len);\r
146      }\r
147  \r
148 -    _notmuch_string_list_sort (list);\r
149 -\r
150 -    return _notmuch_tags_create (ctx, list, TRUE);\r
151 +    return list;\r
152  }\r
153  \r
154  notmuch_tags_t *\r
155  notmuch_database_get_all_tags (notmuch_database_t *db)\r
156  {\r
157      Xapian::TermIterator i, end;\r
158 +    notmuch_string_list_t *tags;\r
159  \r
160      try {\r
161         i = db->xapian_db->allterms_begin();\r
162         end = db->xapian_db->allterms_end();\r
163 -       return _notmuch_convert_tags(db, i, end);\r
164 +       tags = _notmuch_get_terms_with_prefix (db, i, end, _find_prefix ("tag"));\r
165 +       _notmuch_string_list_sort (tags);\r
166 +       return _notmuch_tags_create (db, tags, TRUE);\r
167      } catch (const Xapian::Error &error) {\r
168         fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",\r
169                  error.get_msg().c_str());\r
170 diff --git a/lib/directory.cc b/lib/directory.cc\r
171 index aeee9ca..fb6ef03 100644\r
172 --- a/lib/directory.cc\r
173 +++ b/lib/directory.cc\r
174 @@ -23,10 +23,6 @@\r
175  \r
176  /* Create an iterator to iterate over the basenames of files (or\r
177   * directories) that all share a common parent directory.\r
178 - *\r
179 - * The code here is general enough to be reused for any case of\r
180 - * iterating over the non-prefixed portion of terms sharing a common\r
181 - * prefix.\r
182   */\r
183  static notmuch_filenames_t *\r
184  _create_filenames_for_terms_with_prefix (void *ctx,\r
185 @@ -35,21 +31,13 @@ _create_filenames_for_terms_with_prefix (void *ctx,\r
186  {\r
187      notmuch_string_list_t *filename_list;\r
188      Xapian::TermIterator i, end;\r
189 -    int prefix_len = strlen (prefix);\r
190  \r
191 -    filename_list = _notmuch_string_list_create (ctx);\r
192 +    i = notmuch->xapian_db->allterms_begin();\r
193 +    end = notmuch->xapian_db->allterms_end();\r
194 +    filename_list = _notmuch_get_terms_with_prefix (ctx, i, end, prefix);\r
195      if (unlikely (filename_list == NULL))\r
196         return NULL;\r
197  \r
198 -    end = notmuch->xapian_db->allterms_end (prefix);\r
199 -\r
200 -    for (i = notmuch->xapian_db->allterms_begin (prefix); i != end; i++)\r
201 -    {\r
202 -       std::string term = *i;\r
203 -\r
204 -       _notmuch_string_list_append (filename_list, term.c_str () + prefix_len);\r
205 -    }\r
206 -\r
207      return _notmuch_filenames_create (ctx, filename_list);\r
208  }\r
209  \r
210 diff --git a/lib/message.cc b/lib/message.cc\r
211 index 031eda5..dbf683c 100644\r
212 --- a/lib/message.cc\r
213 +++ b/lib/message.cc\r
214 @@ -640,9 +640,13 @@ notmuch_tags_t *\r
215  notmuch_message_get_tags (notmuch_message_t *message)\r
216  {\r
217      Xapian::TermIterator i, end;\r
218 +    notmuch_string_list_t *tags;\r
219      i = message->doc.termlist_begin();\r
220      end = message->doc.termlist_end();\r
221 -    return _notmuch_convert_tags(message, i, end);\r
222 +    tags = _notmuch_get_terms_with_prefix (message, i, end,\r
223 +                                          _find_prefix ("tag"));\r
224 +    _notmuch_string_list_sort (tags);\r
225 +    return _notmuch_tags_create (message, tags, TRUE);\r
226  }\r
227  \r
228  const char *\r
229 -- \r
230 1.7.2.3\r
231 \r