[PATCH v2 03/14] cli/reply: reuse show_reply_headers() in headers-only format
[notmuch-archives.git] / 70 / 528bfe7420e538068895ca35fc71d3e60ef318
1 Return-Path: <amthrax@drake.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 2473E429E23\r
6         for <notmuch@notmuchmail.org>; Thu, 17 Feb 2011 23:59:40 -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 lfrgXpE-wUEj for <notmuch@notmuchmail.org>;\r
16         Thu, 17 Feb 2011 23:59:38 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id 3D55A429E32\r
20         for <notmuch@notmuchmail.org>; Thu, 17 Feb 2011 23:59:30 -0800 (PST)\r
21 X-AuditID: 1209190f-b7c1dae000000a2b-6c-4d5e26e27861\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id 6C.42.02603.2E62E5D4; Fri, 18 Feb 2011 02:59:30 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p1I7xTUn027142; \r
27         Fri, 18 Feb 2011 02:59:29 -0500\r
28 Received: from drake.mit.edu\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p1I7xSXw001550\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Fri, 18 Feb 2011 02:59:29 -0500 (EST)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
36         (envelope-from <amthrax@drake.mit.edu>)\r
37         id 1PqLFQ-0008LQ-Oq; Fri, 18 Feb 2011 02:59:28 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 08/10] new: Synchronize maildir flags eagerly.\r
41 Date: Fri, 18 Feb 2011 02:58:58 -0500\r
42 Message-Id: <1298015940-31986-9-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.2.3\r
44 In-Reply-To: <1298015940-31986-1-git-send-email-amdragon@mit.edu>\r
45 References: <1298015940-31986-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker: AAAAARdyUy0=\r
47 Cc: 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: Fri, 18 Feb 2011 07:59:40 -0000\r
61 \r
62 Because flag synchronization is stateless, it can be performed at any\r
63 time as long as it's guaranteed to be performed after any change to a\r
64 message's filename list.  Take advantage of this to synchronize tags\r
65 immediately after a filename is added or removed while the message is\r
66 still frozen.  With this change, filename removal is atomic and the\r
67 unsynchronized window for filename add is very short.\r
68 ---\r
69  notmuch-new.c |   57 +++++++++++++++++----------------------------------------\r
70  1 files changed, 17 insertions(+), 40 deletions(-)\r
71 \r
72 diff --git a/notmuch-new.c b/notmuch-new.c\r
73 index 56fe7b0..767722a 100644\r
74 --- a/notmuch-new.c\r
75 +++ b/notmuch-new.c\r
76 @@ -50,7 +50,6 @@ typedef struct {\r
77      _filename_list_t *directory_mtimes;\r
78  \r
79      notmuch_bool_t synchronize_flags;\r
80 -    _filename_list_t *message_ids_to_sync;\r
81  } add_files_state_t;\r
82  \r
83  static volatile sig_atomic_t do_print_progress = 0;\r
84 @@ -439,11 +438,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
85             break;\r
86         /* Non-fatal issues (go on to next file) */\r
87         case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
88 -           /* Defer sync of maildir flags until after old filenames\r
89 -            * are removed in the case of a rename. */\r
90             if (state->synchronize_flags == TRUE)\r
91 -               _filename_list_add (state->message_ids_to_sync,\r
92 -                                   notmuch_message_get_message_id (message));\r
93 +               notmuch_message_maildir_flags_to_tags (message);\r
94             break;\r
95         case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
96             fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
97 @@ -696,18 +692,23 @@ static notmuch_status_t\r
98  remove_file (notmuch_database_t *notmuch,\r
99              const char *path,\r
100              int *renamed_files,\r
101 -            int *removed_files)\r
102 +            int *removed_files,\r
103 +            add_files_state_t *state)\r
104  {\r
105      notmuch_status_t status;\r
106      notmuch_message_t *message;\r
107      message = notmuch_database_find_message_by_filename (notmuch, path);\r
108      if (!message)\r
109         return NOTMUCH_STATUS_SUCCESS;\r
110 +    notmuch_message_freeze (message);\r
111      status = notmuch_message_remove_filename (message, path);\r
112 -    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)\r
113 +    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
114         (*renamed_files)++;\r
115 -    else\r
116 +       if (state->synchronize_flags == TRUE)\r
117 +           notmuch_message_maildir_flags_to_tags (message);\r
118 +    } else\r
119         (*removed_files)++;\r
120 +    notmuch_message_thaw (message);\r
121      notmuch_message_destroy (message);\r
122      return status;\r
123  }\r
124 @@ -719,7 +720,8 @@ _remove_directory (void *ctx,\r
125                    notmuch_database_t *notmuch,\r
126                    const char *path,\r
127                    int *renamed_files,\r
128 -                  int *removed_files)\r
129 +                  int *removed_files,\r
130 +                  add_files_state_t *state)\r
131  {\r
132      notmuch_directory_t *directory;\r
133      notmuch_filenames_t *files, *subdirs;\r
134 @@ -733,7 +735,7 @@ _remove_directory (void *ctx,\r
135      {\r
136         absolute = talloc_asprintf (ctx, "%s/%s", path,\r
137                                     notmuch_filenames_get (files));\r
138 -       remove_file (notmuch, absolute, renamed_files, removed_files);\r
139 +       remove_file (notmuch, absolute, renamed_files, removed_files, state);\r
140         talloc_free (absolute);\r
141      }\r
142  \r
143 @@ -743,7 +745,8 @@ _remove_directory (void *ctx,\r
144      {\r
145         absolute = talloc_asprintf (ctx, "%s/%s", path,\r
146                                     notmuch_filenames_get (subdirs));\r
147 -       _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files);\r
148 +       _remove_directory (ctx, notmuch, absolute, renamed_files, removed_files,\r
149 +                          state);\r
150         talloc_free (absolute);\r
151      }\r
152  \r
153 @@ -785,7 +788,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
154  \r
155      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
156      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
157 -    add_files_state.message_ids_to_sync = _filename_list_create (ctx);\r
158      db_path = notmuch_config_get_database_path (config);\r
159  \r
160      dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
161 @@ -854,7 +856,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
162      renamed_files = 0;\r
163      gettimeofday (&tv_start, NULL);\r
164      for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {\r
165 -       remove_file (notmuch, f->filename, &renamed_files, &removed_files);\r
166 +       remove_file (notmuch, f->filename, &renamed_files, &removed_files,\r
167 +                    &add_files_state);\r
168         if (do_print_progress) {\r
169             do_print_progress = 0;\r
170             generic_print_progress ("Cleaned up", "messages",\r
171 @@ -866,7 +869,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
172      gettimeofday (&tv_start, NULL);\r
173      for (f = add_files_state.removed_directories->head, i = 0; f && !interrupted; f = f->next, i++) {\r
174         _remove_directory (ctx, notmuch, f->filename,\r
175 -                          &renamed_files, &removed_files);\r
176 +                          &renamed_files, &removed_files, &add_files_state);\r
177         if (do_print_progress) {\r
178             do_print_progress = 0;\r
179             generic_print_progress ("Cleaned up", "directories",\r
180 @@ -888,32 +891,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
181      talloc_free (add_files_state.removed_directories);\r
182      talloc_free (add_files_state.directory_mtimes);\r
183  \r
184 -    /* Now that removals are done (hence the database is aware of all\r
185 -     * renames), we can synchronize maildir_flags to tags for all\r
186 -     * messages that had new filenames appear on this run. */\r
187 -    gettimeofday (&tv_start, NULL);\r
188 -    if (add_files_state.synchronize_flags) {\r
189 -       _filename_node_t *node;\r
190 -       notmuch_message_t *message;\r
191 -       for (node = add_files_state.message_ids_to_sync->head, i = 0;\r
192 -            node;\r
193 -            node = node->next, i++)\r
194 -       {\r
195 -           message = notmuch_database_find_message (notmuch, node->filename);\r
196 -           notmuch_message_maildir_flags_to_tags (message);\r
197 -           notmuch_message_destroy (message);\r
198 -           if (do_print_progress) {\r
199 -               do_print_progress = 0;\r
200 -               generic_print_progress (\r
201 -                   "Synchronized tags for", "messages",\r
202 -                   tv_start, i, add_files_state.message_ids_to_sync->count);\r
203 -           }\r
204 -       }\r
205 -    }\r
206 -\r
207 -    talloc_free (add_files_state.message_ids_to_sync);\r
208 -    add_files_state.message_ids_to_sync = NULL;\r
209 -\r
210      if (timer_is_active)\r
211         stop_progress_printing_timer ();\r
212  \r
213 -- \r
214 1.7.2.3\r
215 \r