1 Return-Path: <jani@nikula.org>
\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 EE312431FC4
\r
6 for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[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 ehi70FpH3FEX for <notmuch@notmuchmail.org>;
\r
17 Sun, 19 Jan 2014 12:32:42 -0800 (PST)
\r
18 Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com
\r
19 [209.85.215.169]) (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 3A661431FC0
\r
22 for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:42 -0800 (PST)
\r
23 Received: by mail-ea0-f169.google.com with SMTP id l9so2371573eaj.14
\r
24 for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:39 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 :references:in-reply-to:references;
\r
29 bh=ZlZO3SgikNTtTG871qD0qm4K3Hzd6zaq6UH2X0CJPDo=;
\r
30 b=Oaw+5gdLHB+qlC1PEHtTJNOoqbcKHsh6OoOcq1OnE7ZaaGde6CJICNwXRFG6FKmkqo
\r
31 AbpdiVsmCFzxVEopZKFfQHtaLOKA3Sp12B2bo07V7NvSs5OGgOohVbHJxx9mGxuHlkQT
\r
32 g18s90Xh6jtkj8u4aLI2xj2tS461ywWRJT3gg5mS/+5JwyRHSYry8j83gB7lsGgaOwfb
\r
33 yaQwkKvYWHWkqhOOvq8o18bDGVKnJ3U1EutFUTl4Siq9UfPfVNsDaa7SpGmPJtrFZqlZ
\r
34 e8Dxu4DG66TNOkJ/aOsl2gReax0rrmiV/w7gOgEaFtFNL3dZnaKEMCKkQ0SGnLpZ8bwP
\r
37 ALoCoQmGoaz1AtOsqlHdIdgHJwqHpsWQ7YxPihXjxLFC3guDsLvgDp8tWzQ4FvxFRByBenPu2All
\r
38 X-Received: by 10.15.54.72 with SMTP id s48mr13906238eew.3.1390163559636;
\r
39 Sun, 19 Jan 2014 12:32:39 -0800 (PST)
\r
40 Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.
\r
42 by mx.google.com with ESMTPSA id 4sm46526754eed.14.2014.01.19.12.32.37
\r
43 for <multiple recipients>
\r
44 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
45 Sun, 19 Jan 2014 12:32:38 -0800 (PST)
\r
46 From: Jani Nikula <jani@nikula.org>
\r
47 To: notmuch@notmuchmail.org
\r
48 Subject: [PATCH 1/7] cli: extract single message addition in notmuch new to
\r
50 Date: Sun, 19 Jan 2014 22:32:22 +0200
\r
52 <a7e29c2d62b3e1547aab7d242d9ea52e64a9c84d.1390163335.git.jani@nikula.org>
\r
53 X-Mailer: git-send-email 1.8.5.2
\r
54 In-Reply-To: <cover.1390163335.git.jani@nikula.org>
\r
55 References: <cover.1390163335.git.jani@nikula.org>
\r
56 In-Reply-To: <cover.1390163335.git.jani@nikula.org>
\r
57 References: <cover.1390163335.git.jani@nikula.org>
\r
58 X-BeenThere: notmuch@notmuchmail.org
\r
59 X-Mailman-Version: 2.1.13
\r
61 List-Id: "Use and development of the notmuch mail system."
\r
62 <notmuch.notmuchmail.org>
\r
63 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
64 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
65 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
66 List-Post: <mailto:notmuch@notmuchmail.org>
\r
67 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
68 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
69 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
70 X-List-Received-Date: Sun, 19 Jan 2014 20:32:49 -0000
\r
72 The add_files() function has grown huge, chop it up a bit. No
\r
75 notmuch-new.c | 109 +++++++++++++++++++++++++++++-----------------------------
\r
76 1 file changed, 55 insertions(+), 54 deletions(-)
\r
78 diff --git a/notmuch-new.c b/notmuch-new.c
\r
79 index 6a8b1b2..1dd8fc9 100644
\r
82 @@ -240,6 +240,60 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)
\r
86 +/* Add a single file to the database. */
\r
87 +static notmuch_status_t
\r
88 +add_file (notmuch_database_t *notmuch, const char *filename,
\r
89 + add_files_state_t *state)
\r
91 + notmuch_message_t *message = NULL;
\r
93 + notmuch_status_t status;
\r
95 + status = notmuch_database_begin_atomic (notmuch);
\r
99 + status = notmuch_database_add_message (notmuch, filename, &message);
\r
100 + switch (status) {
\r
102 + case NOTMUCH_STATUS_SUCCESS:
\r
103 + state->added_messages++;
\r
104 + notmuch_message_freeze (message);
\r
105 + for (tag = state->new_tags; *tag != NULL; tag++)
\r
106 + notmuch_message_add_tag (message, *tag);
\r
107 + if (state->synchronize_flags)
\r
108 + notmuch_message_maildir_flags_to_tags (message);
\r
109 + notmuch_message_thaw (message);
\r
111 + /* Non-fatal issues (go on to next file). */
\r
112 + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
113 + if (state->synchronize_flags)
\r
114 + notmuch_message_maildir_flags_to_tags (message);
\r
116 + case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
117 + fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename);
\r
119 + /* Fatal issues. Don't process anymore. */
\r
120 + case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
121 + case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
122 + case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
123 + fprintf (stderr, "Error: %s. Halting processing.\n",
\r
124 + notmuch_status_to_string (status));
\r
127 + INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
131 + status = notmuch_database_end_atomic (notmuch);
\r
135 + notmuch_message_destroy (message);
\r
140 /* Examine 'path' recursively as follows:
\r
142 * o Ask the filesystem for the mtime of 'path' (fs_mtime)
\r
143 @@ -291,7 +345,6 @@ add_files (notmuch_database_t *notmuch,
\r
145 time_t fs_mtime, db_mtime;
\r
146 notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;
\r
147 - notmuch_message_t *message = NULL;
\r
148 struct dirent **fs_entries = NULL;
\r
149 int i, num_fs_entries = 0, entry_type;
\r
150 notmuch_directory_t *directory;
\r
151 @@ -300,7 +353,6 @@ add_files (notmuch_database_t *notmuch,
\r
154 notmuch_bool_t is_maildir;
\r
155 - const char **tag;
\r
157 if (stat (path, &st)) {
\r
158 fprintf (stderr, "Error reading directory %s: %s\n",
\r
159 @@ -527,63 +579,12 @@ add_files (notmuch_database_t *notmuch,
\r
163 - status = notmuch_database_begin_atomic (notmuch);
\r
164 + status = add_file (notmuch, next, state);
\r
170 - status = notmuch_database_add_message (notmuch, next, &message);
\r
171 - switch (status) {
\r
173 - case NOTMUCH_STATUS_SUCCESS:
\r
174 - state->added_messages++;
\r
175 - notmuch_message_freeze (message);
\r
176 - for (tag=state->new_tags; *tag != NULL; tag++)
\r
177 - notmuch_message_add_tag (message, *tag);
\r
178 - if (state->synchronize_flags == TRUE)
\r
179 - notmuch_message_maildir_flags_to_tags (message);
\r
180 - notmuch_message_thaw (message);
\r
182 - /* Non-fatal issues (go on to next file) */
\r
183 - case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
184 - if (state->synchronize_flags == TRUE)
\r
185 - notmuch_message_maildir_flags_to_tags (message);
\r
187 - case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
188 - fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
191 - /* Fatal issues. Don't process anymore. */
\r
192 - case NOTMUCH_STATUS_READ_ONLY_DATABASE:
\r
193 - case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
\r
194 - case NOTMUCH_STATUS_OUT_OF_MEMORY:
\r
195 - fprintf (stderr, "Error: %s. Halting processing.\n",
\r
196 - notmuch_status_to_string (status));
\r
200 - case NOTMUCH_STATUS_FILE_ERROR:
\r
201 - case NOTMUCH_STATUS_NULL_POINTER:
\r
202 - case NOTMUCH_STATUS_TAG_TOO_LONG:
\r
203 - case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
\r
204 - case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
\r
205 - case NOTMUCH_STATUS_LAST_STATUS:
\r
206 - INTERNAL_ERROR ("add_message returned unexpected value: %d", status);
\r
210 - status = notmuch_database_end_atomic (notmuch);
\r
217 - notmuch_message_destroy (message);
\r
221 if (do_print_progress) {
\r
222 do_print_progress = 0;
\r
223 generic_print_progress ("Processed", "files", state->tv_start,
\r