1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 42E9C431FBC
\r
6 for <notmuch@notmuchmail.org>; Mon, 7 Dec 2009 19:15:04 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id 8LcHcrDNToTx for <notmuch@notmuchmail.org>;
\r
11 Mon, 7 Dec 2009 19:15:03 -0800 (PST)
\r
12 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])
\r
13 by olra.theworths.org (Postfix) with ESMTP id 4BD4A431FAE
\r
14 for <notmuch@notmuchmail.org>; Mon, 7 Dec 2009 19:15:03 -0800 (PST)
\r
16 fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net
\r
17 ([142.167.182.194] helo=localhost)
\r
18 by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)
\r
19 (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)
\r
20 id 1NHqXT-0007Ji-Ja; Mon, 07 Dec 2009 23:15:02 -0400
\r
21 Received: from bremner by localhost with local (Exim 4.69)
\r
22 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
23 id 1NHqXN-00047O-I7; Mon, 07 Dec 2009 23:14:53 -0400
\r
24 From: david@tethera.net
\r
25 To: notmuch@notmuchmail.org
\r
26 Date: Mon, 7 Dec 2009 23:14:48 -0400
\r
27 Message-Id: <1260242088-15680-1-git-send-email-david@tethera.net>
\r
28 X-Mailer: git-send-email 1.6.5.3
\r
29 In-Reply-To: <1260124225-10830-1-git-send-email-david@tethera.net>
\r
30 References: <1260124225-10830-1-git-send-email-david@tethera.net>
\r
31 X-Sender-Verified: bremner@pivot.cs.unb.ca
\r
32 Cc: David Bremner <bremner@unb.ca>
\r
33 Subject: [notmuch] [PATCH] notmuch-restore.c: only update tags for messages
\r
34 that differ from dump file.
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.12
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Tue, 08 Dec 2009 03:15:04 -0000
\r
49 From: David Bremner <bremner@unb.ca>
\r
51 The main feature of this patch is that it compares the list of current
\r
52 tags on a message with those read by restore. Only if the two lists
\r
53 differ is the tag list in the message replaced. In my experiments this leads to
\r
54 a large performance improvement.
\r
56 Since I had to rewrite the parsing of tags from the dump file anyway
\r
57 to keep a list of tags (in case they should be written to the
\r
58 database), I decided to make it a bit more robust. It sorts the
\r
59 incoming tags (it is critical for the comparison of the two tag lists
\r
60 that they are both sorted), and allows arbitrary whitespace (as
\r
61 determined by "isspace") between tags.
\r
63 The patch allocates a temporary array to keep track of the current
\r
64 list of tags using calloc and grows it as neccesary using realloc.
\r
67 This is the second version of the patch, the only difference is in the test
\r
68 on line 144 (used to be 142), and the comment before explaining it.
\r
70 notmuch-restore.c | 75 ++++++++++++++++++++++++++++++++++++++++++++--------
\r
71 1 files changed, 63 insertions(+), 12 deletions(-)
\r
73 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
74 index 1b9598d..9d7bd17 100644
\r
75 --- a/notmuch-restore.c
\r
76 +++ b/notmuch-restore.c
\r
78 * Author: Carl Worth <cworth@cworth.org>
\r
81 +#include <stdlib.h>
\r
82 +#include <string.h>
\r
84 #include "notmuch-client.h"
\r
86 +#define DEFAULT_TAG_ARRAY_SIZE 2
\r
88 +static int scmp( const void *sp1, const void *sp2 )
\r
90 + return( strcmp(*(const char **)sp1, *(const char **)sp2) );
\r
93 notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
95 @@ -31,6 +40,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
99 + char **tag_array=NULL;
\r
100 + int tag_array_size=DEFAULT_TAG_ARRAY_SIZE;
\r
103 config = notmuch_config_open (ctx, NULL, NULL);
\r
104 if (config == NULL)
\r
105 @@ -61,11 +73,18 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
106 "^([^ ]+) \\(([^)]*)\\)$",
\r
109 + /* Make an array of pointers to point to individual tokens */
\r
110 + tag_array=calloc(tag_array_size,sizeof(char*));
\r
112 while ((line_len = getline (&line, &line_size, input)) != -1) {
\r
113 regmatch_t match[3];
\r
114 - char *message_id, *tags, *tag, *next;
\r
115 + char *message_id, *tags, *next;
\r
116 notmuch_message_t *message;
\r
117 notmuch_status_t status;
\r
120 + notmuch_tags_t *tag_list;
\r
123 chomp_newline (line);
\r
125 @@ -89,26 +108,55 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
129 - notmuch_message_freeze (message);
\r
133 + while(*next && isspace(*next))
\r
136 + while (tag_count>= tag_array_size){
\r
137 + tag_array_size*=2;
\r
138 + tag_array=realloc(tag_array,tag_array_size*sizeof(char *));
\r
140 + tag_array[tag_count]=next;
\r
143 + while (*next && !isspace(*next))
\r
151 + qsort(tag_array,tag_count,sizeof(char*),scmp);
\r
153 + tag_list = notmuch_message_get_tags (message);
\r
155 + while (notmuch_tags_has_more (tag_list) && i<tag_count &&
\r
156 + (strcmp(notmuch_tags_get (tag_list),tag_array[i])==0)){
\r
157 + notmuch_tags_advance (tag_list);
\r
161 - notmuch_message_remove_all_tags (message);
\r
162 + /* the only success condition is for the tag list comparison is to run
\r
163 + off the end of both lists at the same time */
\r
164 + if (notmuch_tags_has_more (tag_list) || i<tag_count ){
\r
165 + notmuch_message_freeze (message);
\r
166 + notmuch_message_remove_all_tags (message);
\r
170 - tag = strsep (&next, " ");
\r
171 - if (*tag == '\0')
\r
173 - status = notmuch_message_add_tag (message, tag);
\r
174 + for (i=0; i<tag_count; i++) {
\r
175 + status = notmuch_message_add_tag (message, tag_array[i]);
\r
178 "Error applying tag %s to message %s:\n",
\r
179 - tag, message_id);
\r
180 + tag_array[i], message_id);
\r
181 fprintf (stderr, "%s\n",
\r
182 notmuch_status_to_string (status));
\r
185 + notmuch_message_thaw (message);
\r
188 - notmuch_message_thaw (message);
\r
189 notmuch_message_destroy (message);
\r
192 @@ -120,6 +168,9 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
197 + free (tag_array);
\r
199 notmuch_database_close (notmuch);
\r
200 if (input != stdin)
\r