[PATCH] lib: provide _notmuch_database_log_append
[notmuch-archives.git] / 6e / 7670a44109e120c29c1aa4e175ede6b7cfd91d
1 Return-Path: <bremner@tethera.net>\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 arlo.cworth.org (Postfix) with ESMTP id 4D96D6DE1510\r
6  for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 05:17:53 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.11\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.11 tagged_above=-999 required=5 tests=[AWL=0.110]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id B3vyZ-KdSRtK for <notmuch@notmuchmail.org>;\r
16  Sun, 27 Sep 2015 05:17:51 -0700 (PDT)\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 25BA66DE141E\r
19  for <notmuch@notmuchmail.org>; Sun, 27 Sep 2015 05:17:51 -0700 (PDT)\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
21  (envelope-from <bremner@tethera.net>)\r
22  id 1ZgAt8-0007YZ-9h; Sun, 27 Sep 2015 12:17:06 +0000\r
23 Received: (nullmailer pid 15557 invoked by uid 1000); Sun, 27 Sep 2015\r
24  12:16:47 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
27 Subject: [patch v3.1] lib: add versions of n_q_count_{message,threads} with\r
28  status return\r
29 Date: Sun, 27 Sep 2015 09:16:26 -0300\r
30 Message-Id: <1443356186-15517-1-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.5.3\r
32 In-Reply-To: <1443322213-31075-3-git-send-email-david@tethera.net>\r
33 References: <1443322213-31075-3-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.18\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sun, 27 Sep 2015 12:17:53 -0000\r
47 \r
48 Although I think it's a pretty bad idea to continue using the old API,\r
49 this allows both a more gentle transition for clients of the library,\r
50 and allows us to break one monolithic change into a series\r
51 ---\r
52  lib/database.cc | 11 ++++++++++-\r
53  lib/notmuch.h   | 48 ++++++++++++++++++++++++++++++++++++++++++------\r
54  lib/query.cc    | 47 +++++++++++++++++++++++++++++++++--------------\r
55  3 files changed, 85 insertions(+), 21 deletions(-)\r
56 \r
57 diff --git a/lib/database.cc b/lib/database.cc\r
58 index dcfad8c..fbfb1af 100644\r
59 --- a/lib/database.cc\r
60 +++ b/lib/database.cc\r
61 @@ -1410,7 +1410,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
62         (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |\r
63          NOTMUCH_FEATURE_LAST_MOD)) {\r
64         query = notmuch_query_create (notmuch, "");\r
65 -       total += notmuch_query_count_messages (query);\r
66 +       unsigned msg_count;\r
67 +\r
68 +       status = notmuch_query_count_messages_st (query, &msg_count);\r
69 +       if (status)\r
70 +           goto DONE;\r
71 +\r
72 +       total += msg_count;\r
73         notmuch_query_destroy (query);\r
74      }\r
75      if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
76 @@ -1612,6 +1618,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
77         sigaction (SIGALRM, &action, NULL);\r
78      }\r
79  \r
80 +    if (query)\r
81 +       notmuch_query_destroy (query);\r
82 +\r
83      talloc_free (local);\r
84      return status;\r
85  }\r
86 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
87 index 8775683..2fb778b 100644\r
88 --- a/lib/notmuch.h\r
89 +++ b/lib/notmuch.h\r
90 @@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
91   * This function performs a search and returns the number of matching\r
92   * messages.\r
93   *\r
94 - * If a Xapian exception occurs, this function may return 0 (after\r
95 - * printing a message).\r
96 + * @returns\r
97 + *\r
98 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
99 + *\r
100 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
101 + *      value of *count is not defined.\r
102   */\r
103 -unsigned\r
104 +notmuch_status_t\r
105 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
106 +\r
107 +/**\r
108 + * like notmuch_query_count_messages_st, but without a status return\r
109 + *\r
110 + * May return 0 in the case of errors.\r
111 + *\r
112 + * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please\r
113 + * use notmuch_query_count_messages_st instead.\r
114 + */\r
115 +NOTMUCH_DEPRECATED(4,3)\r
116 +unsigned int\r
117  notmuch_query_count_messages (notmuch_query_t *query);\r
118  \r
119  /**\r
120 @@ -998,11 +1014,31 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
121   * search.\r
122   *\r
123   * Note that this is a significantly heavier operation than\r
124 - * notmuch_query_count_messages().\r
125 + * notmuch_query_count_messages{_st}().\r
126 + *\r
127 + * @returns\r
128   *\r
129 - * If an error occurs, this function may return 0.\r
130 + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
131 + *      of *count is not defined\r
132 +\r
133 + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
134 + *\r
135 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
136 + *      value of *count is not defined.\r
137   */\r
138 -unsigned\r
139 +notmuch_status_t\r
140 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
141 +\r
142 +/**\r
143 + * like notmuch_query_count_threads, but without a status return.\r
144 + *\r
145 + * May return 0 in case of errors.\r
146 + *\r
147 + * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please\r
148 + * use notmuch_query_count_threads_st instead.\r
149 + */\r
150 +NOTMUCH_DEPRECATED(4,3)\r
151 +unsigned int\r
152  notmuch_query_count_threads (notmuch_query_t *query);\r
153  \r
154  /**\r
155 diff --git a/lib/query.cc b/lib/query.cc\r
156 index 8cf0a07..e627bfc 100644\r
157 --- a/lib/query.cc\r
158 +++ b/lib/query.cc\r
159 @@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
160      talloc_free (threads);\r
161  }\r
162  \r
163 -unsigned\r
164 +unsigned int\r
165  notmuch_query_count_messages (notmuch_query_t *query)\r
166  {\r
167 +    notmuch_status_t status;\r
168 +    unsigned int count;\r
169 +\r
170 +    status = notmuch_query_count_messages_st (query, &count);\r
171 +    return status ? 0 : count;\r
172 +}\r
173 +\r
174 +notmuch_status_t\r
175 +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
176 +{\r
177      notmuch_database_t *notmuch = query->notmuch;\r
178      const char *query_string = query->query_string;\r
179      Xapian::doccount count = 0;\r
180 @@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
181                                "Query string was: %s\n",\r
182                                error.get_msg().c_str(),\r
183                                query->query_string);\r
184 -\r
185 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
186      }\r
187  \r
188 -    return count;\r
189 +    *count_out = count;\r
190 +    return NOTMUCH_STATUS_SUCCESS;\r
191  }\r
192  \r
193  unsigned\r
194  notmuch_query_count_threads (notmuch_query_t *query)\r
195  {\r
196 +    notmuch_status_t status;\r
197 +    unsigned int count;\r
198 +\r
199 +    status = notmuch_query_count_threads_st (query, &count);\r
200 +    return status ? 0 : count;\r
201 +}\r
202 +\r
203 +notmuch_status_t\r
204 +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
205 +{\r
206      notmuch_messages_t *messages;\r
207      GHashTable *hash;\r
208 -    unsigned int count;\r
209      notmuch_sort_t sort;\r
210 -    notmuch_status_t status;\r
211 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
212  \r
213      sort = query->sort;\r
214      query->sort = NOTMUCH_SORT_UNSORTED;\r
215 -    status = notmuch_query_search_messages_st (query, &messages);\r
216 -    if (status)\r
217 -       return 0;\r
218 -\r
219 +    ret = notmuch_query_search_messages_st (query, &messages);\r
220 +    if (ret)\r
221 +       return ret;\r
222      query->sort = sort;\r
223      if (messages == NULL)\r
224 -       return 0;\r
225 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
226  \r
227      hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
228      if (hash == NULL) {\r
229         talloc_free (messages);\r
230 -       return 0;\r
231 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
232      }\r
233  \r
234      while (notmuch_messages_valid (messages)) {\r
235 @@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
236         char *thread_id_copy = talloc_strdup (messages, thread_id);\r
237         if (unlikely (thread_id_copy == NULL)) {\r
238             notmuch_message_destroy (message);\r
239 -           count = 0;\r
240 +           ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
241             goto DONE;\r
242         }\r
243         g_hash_table_insert (hash, thread_id_copy, NULL);\r
244 @@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
245         notmuch_messages_move_to_next (messages);\r
246      }\r
247  \r
248 -    count = g_hash_table_size (hash);\r
249 +    *count = g_hash_table_size (hash);\r
250  \r
251    DONE:\r
252      g_hash_table_unref (hash);\r
253      talloc_free (messages);\r
254  \r
255 -    return count;\r
256 +    return ret;\r
257  }\r
258  \r
259  notmuch_database_t *\r
260 -- \r
261 2.5.3\r
262 \r