[RFC PATCH 0/6] cli/reply: refactoring part 2
[notmuch-archives.git] / 92 / 9f5043cea8e2fc9a30302ce9a14e0cfb20e970
1 Return-Path: <markwalters1009@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 3C982429E3D\r
6         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:19 -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.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id K0LxvE28UVTS for <notmuch@notmuchmail.org>;\r
18         Wed, 15 Feb 2012 01:03:15 -0800 (PST)\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
20  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  0174041ED72    for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:07 -0800\r
23  (PST)\r
24 Received: by mail-ww0-f45.google.com with SMTP id dt12so647956wgb.2\r
25         for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 01:03:07 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=/KlPkyW/AXjCqzMbLSxItjxAsw7VRUH2C8W7KcRN+z0=;\r
29         b=m58EfW6g+YNr2DZYPVbdfJ3en2bBJvhR+atExQN5uiimHViLGVICaNQMugk6qKCfIg\r
30         UrNGiiJm+q8FViq71rQKhMd5iRFzsXY81USpIpiCMpBRDOHMRGKnkSYqkKNyOdsS+inv\r
31         +bVHp1/4qPg1NyNRSXQPWdJKIdFiJU+R/dLrA=\r
32 Received: by 10.180.106.33 with SMTP id gr1mr34044331wib.6.1329296587752;\r
33         Wed, 15 Feb 2012 01:03:07 -0800 (PST)\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
35  [94.192.233.223])      by mx.google.com with ESMTPS id\r
36  da8sm32096112wib.6.2012.02.15.01.03.06 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Wed, 15 Feb 2012 01:03:07 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [RFC PATCH v5 06/11] lib: Add the exclude flag to\r
41         notmuch_query_search_threads\r
42 Date: Wed, 15 Feb 2012 09:03:34 +0000\r
43 Message-Id: <1329296619-7463-7-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
46 References: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Wed, 15 Feb 2012 09:03:19 -0000\r
60 \r
61 Add the NOTMUCH_MESSAGE_FLAG_EXCLUDED flag to\r
62 notmuch_query_search_threads. Implemented by inspecting the tags\r
63 directly in _notmuch_thread_create/_thread_add_message rather than as\r
64 a Xapian query for speed reasons.\r
65 \r
66 Note notmuch_thread_get_matched_messages now returns the number of\r
67 non-excluded matching messages. This API is not totally desirable but\r
68 fixing it means breaking binary compatibility so we delay that.\r
69 ---\r
70  lib/notmuch-private.h |    7 +++++--\r
71  lib/notmuch.h         |    6 ++++--\r
72  lib/query.cc          |    1 +\r
73  lib/thread.cc         |   18 +++++++++++++++---\r
74  4 files changed, 25 insertions(+), 7 deletions(-)\r
75 \r
76 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
77 index e791bb0..ea836f7 100644\r
78 --- a/lib/notmuch-private.h\r
79 +++ b/lib/notmuch-private.h\r
80 @@ -148,6 +148,8 @@ typedef enum _notmuch_private_status {\r
81  \r
82  typedef struct _notmuch_doc_id_set notmuch_doc_id_set_t;\r
83  \r
84 +typedef struct _notmuch_string_list notmuch_string_list_t;\r
85 +\r
86  /* database.cc */\r
87  \r
88  /* Lookup a prefix value by name.\r
89 @@ -216,6 +218,7 @@ _notmuch_thread_create (void *ctx,\r
90                         notmuch_database_t *notmuch,\r
91                         unsigned int seed_doc_id,\r
92                         notmuch_doc_id_set_t *match_set,\r
93 +                       notmuch_string_list_t *excluded_terms,\r
94                         notmuch_sort_t sort);\r
95  \r
96  /* message.cc */\r
97 @@ -459,11 +462,11 @@ typedef struct _notmuch_string_node {\r
98      struct _notmuch_string_node *next;\r
99  } notmuch_string_node_t;\r
100  \r
101 -typedef struct visible _notmuch_string_list {\r
102 +struct visible _notmuch_string_list {\r
103      int length;\r
104      notmuch_string_node_t *head;\r
105      notmuch_string_node_t **tail;\r
106 -} notmuch_string_list_t;\r
107 +};\r
108  \r
109  notmuch_string_list_t *\r
110  _notmuch_string_list_create (const void *ctx);\r
111 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
112 index f75afae..babd208 100644\r
113 --- a/lib/notmuch.h\r
114 +++ b/lib/notmuch.h\r
115 @@ -672,8 +672,10 @@ notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);\r
116  /* Get the number of messages in 'thread' that matched the search.\r
117   *\r
118   * This count includes only the messages in this thread that were\r
119 - * matched by the search from which the thread was created. Contrast\r
120 - * with notmuch_thread_get_total_messages() .\r
121 + * matched by the search from which the thread was created and were\r
122 + * not excluded by any exclude tags passed in with the query (see\r
123 + * notmuch_query_add_tag_exclude). Contrast with\r
124 + * notmuch_thread_get_total_messages() .\r
125   */\r
126  int\r
127  notmuch_thread_get_matched_messages (notmuch_thread_t *thread);\r
128 diff --git a/lib/query.cc b/lib/query.cc\r
129 index 90a71a1..e1c3977 100644\r
130 --- a/lib/query.cc\r
131 +++ b/lib/query.cc\r
132 @@ -472,6 +472,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
133                                    threads->query->notmuch,\r
134                                    doc_id,\r
135                                    &threads->match_set,\r
136 +                                  threads->query->exclude_terms,\r
137                                    threads->query->sort);\r
138  }\r
139  \r
140 diff --git a/lib/thread.cc b/lib/thread.cc\r
141 index 0435ee6..e976d64 100644\r
142 --- a/lib/thread.cc\r
143 +++ b/lib/thread.cc\r
144 @@ -214,7 +214,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,\r
145   */\r
146  static void\r
147  _thread_add_message (notmuch_thread_t *thread,\r
148 -                    notmuch_message_t *message)\r
149 +                    notmuch_message_t *message,\r
150 +                    notmuch_string_list_t *exclude_terms)\r
151  {\r
152      notmuch_tags_t *tags;\r
153      const char *tag;\r
154 @@ -262,6 +263,15 @@ _thread_add_message (notmuch_thread_t *thread,\r
155          notmuch_tags_move_to_next (tags))\r
156      {\r
157         tag = notmuch_tags_get (tags);\r
158 +       /* Mark excluded messages. */\r
159 +       for (notmuch_string_node_t *term = exclude_terms->head; term;\r
160 +            term = term->next) {\r
161 +           /* We ignore initial 'K'. */\r
162 +           if (strcmp(tag, (term->string + 1)) == 0) {\r
163 +               notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
164 +               break;\r
165 +           }\r
166 +       }\r
167         g_hash_table_insert (thread->tags, xstrdup (tag), NULL);\r
168      }\r
169  }\r
170 @@ -321,7 +331,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
171             _thread_set_subject_from_message (thread, message);\r
172      }\r
173  \r
174 -    thread->matched_messages++;\r
175 +    if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))\r
176 +       thread->matched_messages++;\r
177  \r
178      if (g_hash_table_lookup_extended (thread->message_hash,\r
179                             notmuch_message_get_message_id (message), NULL,\r
180 @@ -392,6 +403,7 @@ _notmuch_thread_create (void *ctx,\r
181                         notmuch_database_t *notmuch,\r
182                         unsigned int seed_doc_id,\r
183                         notmuch_doc_id_set_t *match_set,\r
184 +                       notmuch_string_list_t *exclude_terms,\r
185                         notmuch_sort_t sort)\r
186  {\r
187      notmuch_thread_t *thread;\r
188 @@ -467,7 +479,7 @@ _notmuch_thread_create (void *ctx,\r
189         if (doc_id == seed_doc_id)\r
190             message = seed_message;\r
191  \r
192 -       _thread_add_message (thread, message);\r
193 +       _thread_add_message (thread, message, exclude_terms);\r
194  \r
195         if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
196             _notmuch_doc_id_set_remove (match_set, doc_id);\r
197 -- \r
198 1.7.2.3\r
199 \r