--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 2AC4E431FDC\r
+ for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:55:05 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4XMGJ5MzuX95 for <notmuch@notmuchmail.org>;\r
+ Mon, 22 Sep 2014 02:55:00 -0700 (PDT)\r
+Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com\r
+ [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id A1318431FC0\r
+ for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:54:52 -0700 (PDT)\r
+Received: by mail-wi0-f171.google.com with SMTP id ho1so2552447wib.16\r
+ for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:54:51 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+ :references:in-reply-to:references;\r
+ bh=fz9Hb+n6ma8fvn9E4RKit/ex3/v5mYWMnz/lwYDVULc=;\r
+ b=KLwX3OTt1hk+6hckGH86s33f+2NBUF7pCMcbqGNOzKK3tcvs2eHz0vczy6V9Pfc432\r
+ 2Vty8n0FVz/4OGLZpLaFX0lIvqQ6j7sceT92qA1z0r1MkJW8z12XlOtowLejMooXDV/D\r
+ Gg45H9i0whsSJZ492XPp51PRBWiWj2oFjATjk/JAfNX4qxSKn7b8d9nLR6ca9y/Lg1pV\r
+ MBfpMwCTv8yT8QCWPZrQWavcb4pro7zW7zcDoA3QHB6oqnYdlXBS/U+Sw4Y+bM9ULByB\r
+ YkvYxohgQJOFRq8l7sQCuoQ5q04i0vyyl3FkWeyiSJ2NG2gAkcM8lNWtGWZiW9aCL0e4\r
+ UXYA==\r
+X-Gm-Message-State:\r
+ ALoCoQktWBsZoP6/X4gstO10FzQEehfC43iL3m0Fgxf72Jxi0I2szN5wbNDNF5PUTkpDhXaxXk6w\r
+X-Received: by 10.194.202.231 with SMTP id kl7mr1046611wjc.134.1411379691594; \r
+ Mon, 22 Sep 2014 02:54:51 -0700 (PDT)\r
+Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
+ by mx.google.com with ESMTPSA id\r
+ ny6sm11466422wic.22.2014.09.22.02.54.50 for <multiple recipients>\r
+ (version=TLSv1.1 cipher=RC4-SHA bits=128/128);\r
+ Mon, 22 Sep 2014 02:54:51 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 03/11] cli/insert: move add_file_to_database to a better place\r
+Date: Mon, 22 Sep 2014 11:54:54 +0200\r
+Message-Id:\r
+ <84d2fc033adbb5cbddb49a937b71ba1f74a701c0.1411379395.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.2.5\r
+In-Reply-To: <cover.1411379395.git.jani@nikula.org>\r
+References: <cover.1411379395.git.jani@nikula.org>\r
+In-Reply-To: <cover.1411379395.git.jani@nikula.org>\r
+References: <cover.1411379395.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 22 Sep 2014 09:55:05 -0000\r
+\r
+Move add_file_to_database around to keep the filesystem related\r
+functions grouped together, improving readability. No functional\r
+changes.\r
+---\r
+ notmuch-insert.c | 92 +++++++++++++++++++++++++++---------------------------\r
+ 1 files changed, 46 insertions(+), 46 deletions(-)\r
+\r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index 770275b..ccb091a 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -294,52 +294,6 @@ copy_stdin (int fdin, int fdout)\r
+ return (!interrupted && !empty);\r
+ }\r
+ \r
+-/* Add the specified message file to the notmuch database, applying tags.\r
+- * The file is renamed to encode notmuch tags as maildir flags. */\r
+-static void\r
+-add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
+- tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)\r
+-{\r
+- notmuch_message_t *message;\r
+- notmuch_status_t status;\r
+-\r
+- status = notmuch_database_add_message (notmuch, path, &message);\r
+- switch (status) {\r
+- case NOTMUCH_STATUS_SUCCESS:\r
+- case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+- break;\r
+- default:\r
+- case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+- case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
+- case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
+- case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
+- case NOTMUCH_STATUS_FILE_ERROR:\r
+- case NOTMUCH_STATUS_NULL_POINTER:\r
+- case NOTMUCH_STATUS_TAG_TOO_LONG:\r
+- case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
+- case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
+- case NOTMUCH_STATUS_LAST_STATUS:\r
+- fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",\r
+- path, notmuch_status_to_string (status));\r
+- return;\r
+- }\r
+-\r
+- if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
+- /* Don't change tags of an existing message. */\r
+- if (synchronize_flags) {\r
+- status = notmuch_message_tags_to_maildir_flags (message);\r
+- if (status != NOTMUCH_STATUS_SUCCESS)\r
+- fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
+- }\r
+- } else {\r
+- tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;\r
+-\r
+- tag_op_list_apply (message, tag_ops, flags);\r
+- }\r
+-\r
+- notmuch_message_destroy (message);\r
+-}\r
+-\r
+ static notmuch_bool_t\r
+ write_message (void *ctx, int fdin, const char *dir, char **newpath)\r
+ {\r
+@@ -389,6 +343,52 @@ write_message (void *ctx, int fdin, const char *dir, char **newpath)\r
+ return FALSE;\r
+ }\r
+ \r
++/* Add the specified message file to the notmuch database, applying tags.\r
++ * The file is renamed to encode notmuch tags as maildir flags. */\r
++static void\r
++add_file_to_database (notmuch_database_t *notmuch, const char *path,\r
++ tag_op_list_t *tag_ops, notmuch_bool_t synchronize_flags)\r
++{\r
++ notmuch_message_t *message;\r
++ notmuch_status_t status;\r
++\r
++ status = notmuch_database_add_message (notmuch, path, &message);\r
++ switch (status) {\r
++ case NOTMUCH_STATUS_SUCCESS:\r
++ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
++ break;\r
++ default:\r
++ case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
++ case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
++ case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
++ case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
++ case NOTMUCH_STATUS_FILE_ERROR:\r
++ case NOTMUCH_STATUS_NULL_POINTER:\r
++ case NOTMUCH_STATUS_TAG_TOO_LONG:\r
++ case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:\r
++ case NOTMUCH_STATUS_UNBALANCED_ATOMIC:\r
++ case NOTMUCH_STATUS_LAST_STATUS:\r
++ fprintf (stderr, "Error: failed to add `%s' to notmuch database: %s\n",\r
++ path, notmuch_status_to_string (status));\r
++ return;\r
++ }\r
++\r
++ if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
++ /* Don't change tags of an existing message. */\r
++ if (synchronize_flags) {\r
++ status = notmuch_message_tags_to_maildir_flags (message);\r
++ if (status != NOTMUCH_STATUS_SUCCESS)\r
++ fprintf (stderr, "Error: failed to sync tags to maildir flags\n");\r
++ }\r
++ } else {\r
++ tag_op_flag_t flags = synchronize_flags ? TAG_FLAG_MAILDIR_SYNC : 0;\r
++\r
++ tag_op_list_apply (message, tag_ops, flags);\r
++ }\r
++\r
++ notmuch_message_destroy (message);\r
++}\r
++\r
+ int\r
+ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+-- \r
+1.7.2.5\r
+\r