]> git.notmuchmail.org Git - notmuch/commitdiff
cli/insert: move add_file_to_database to a better place
authorJani Nikula <jani@nikula.org>
Mon, 22 Sep 2014 09:54:54 +0000 (11:54 +0200)
committerDavid Bremner <david@tethera.net>
Wed, 24 Sep 2014 18:20:12 +0000 (20:20 +0200)
Move add_file_to_database around to keep the filesystem related
functions grouped together, improving readability. No functional
changes.

notmuch-insert.c

index 770275bb1f98924aadbe6a12a7d213a663b88165..ccb091ac0561f1af3ceb1f2daefd0e26f7990e88 100644 (file)
@@ -294,52 +294,6 @@ copy_stdin (int fdin, int fdout)
     return (!interrupted && !empty);
 }
 
-/* Add the specified message file to the notmuch database, applying tags.
- * The file is renamed to encode notmuch tags as maildir flags. */
-static void
-add_file_to_database (notmuch_database_t *notmuch, const char *path,
-                     tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)
-{
-    notmuch_message_t *message;
-    notmuch_status_t status;
-
-    status = notmuch_database_add_message (notmuch, path, &message);
-    switch (status) {
-    case NOTMUCH_STATUS_SUCCESS:
-    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-       break;
-    default:
-    case NOTMUCH_STATUS_FILE_NOT_EMAIL:
-    case NOTMUCH_STATUS_READ_ONLY_DATABASE:
-    case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
-    case NOTMUCH_STATUS_OUT_OF_MEMORY:
-    case NOTMUCH_STATUS_FILE_ERROR:
-    case NOTMUCH_STATUS_NULL_POINTER:
-    case NOTMUCH_STATUS_TAG_TOO_LONG:
-    case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
-    case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
-    case NOTMUCH_STATUS_LAST_STATUS:
-       fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",
-                path, notmuch_status_to_string (status));
-       return;
-    }
-
-    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
-       /* Don't change tags of an existing message. */
-       if (synchronize_flags) {
-           status = notmuch_message_tags_to_maildir_flags (message);
-           if (status != NOTMUCH_STATUS_SUCCESS)
-               fprintf (stderr, "Error: failed to sync tags to maildir flags\n");
-       }
-    } else {
-       tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;
-
-       tag_op_list_apply (message, tag_ops, flags);
-    }
-
-    notmuch_message_destroy (message);
-}
-
 static notmuch_bool_t
 write_message (void *ctx, int fdin, const char *dir, char **newpath)
 {
@@ -389,6 +343,52 @@ write_message (void *ctx, int fdin, const char *dir, char **newpath)
     return FALSE;
 }
 
+/* Add the specified message file to the notmuch database, applying tags.
+ * The file is renamed to encode notmuch tags as maildir flags. */
+static void
+add_file_to_database (notmuch_database_t *notmuch, const char *path,
+                     tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)
+{
+    notmuch_message_t *message;
+    notmuch_status_t status;
+
+    status = notmuch_database_add_message (notmuch, path, &message);
+    switch (status) {
+    case NOTMUCH_STATUS_SUCCESS:
+    case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
+       break;
+    default:
+    case NOTMUCH_STATUS_FILE_NOT_EMAIL:
+    case NOTMUCH_STATUS_READ_ONLY_DATABASE:
+    case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
+    case NOTMUCH_STATUS_OUT_OF_MEMORY:
+    case NOTMUCH_STATUS_FILE_ERROR:
+    case NOTMUCH_STATUS_NULL_POINTER:
+    case NOTMUCH_STATUS_TAG_TOO_LONG:
+    case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
+    case NOTMUCH_STATUS_UNBALANCED_ATOMIC:
+    case NOTMUCH_STATUS_LAST_STATUS:
+       fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",
+                path, notmuch_status_to_string (status));
+       return;
+    }
+
+    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
+       /* Don't change tags of an existing message. */
+       if (synchronize_flags) {
+           status = notmuch_message_tags_to_maildir_flags (message);
+           if (status != NOTMUCH_STATUS_SUCCESS)
+               fprintf (stderr, "Error: failed to sync tags to maildir flags\n");
+       }
+    } else {
+       tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;
+
+       tag_op_list_apply (message, tag_ops, flags);
+    }
+
+    notmuch_message_destroy (message);
+}
+
 int
 notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
 {