--- /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 EE312431FC4\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:48 -0800 (PST)\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 ehi70FpH3FEX for <notmuch@notmuchmail.org>;\r
+ Sun, 19 Jan 2014 12:32:42 -0800 (PST)\r
+Received: from mail-ea0-f169.google.com (mail-ea0-f169.google.com\r
+ [209.85.215.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 3A661431FC0\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:42 -0800 (PST)\r
+Received: by mail-ea0-f169.google.com with SMTP id l9so2371573eaj.14\r
+ for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:39 -0800 (PST)\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=ZlZO3SgikNTtTG871qD0qm4K3Hzd6zaq6UH2X0CJPDo=;\r
+ b=Oaw+5gdLHB+qlC1PEHtTJNOoqbcKHsh6OoOcq1OnE7ZaaGde6CJICNwXRFG6FKmkqo\r
+ AbpdiVsmCFzxVEopZKFfQHtaLOKA3Sp12B2bo07V7NvSs5OGgOohVbHJxx9mGxuHlkQT\r
+ g18s90Xh6jtkj8u4aLI2xj2tS461ywWRJT3gg5mS/+5JwyRHSYry8j83gB7lsGgaOwfb\r
+ yaQwkKvYWHWkqhOOvq8o18bDGVKnJ3U1EutFUTl4Siq9UfPfVNsDaa7SpGmPJtrFZqlZ\r
+ e8Dxu4DG66TNOkJ/aOsl2gReax0rrmiV/w7gOgEaFtFNL3dZnaKEMCKkQ0SGnLpZ8bwP\r
+ jTKA==\r
+X-Gm-Message-State:\r
+ ALoCoQmGoaz1AtOsqlHdIdgHJwqHpsWQ7YxPihXjxLFC3guDsLvgDp8tWzQ4FvxFRByBenPu2All\r
+X-Received: by 10.15.54.72 with SMTP id s48mr13906238eew.3.1390163559636;\r
+ Sun, 19 Jan 2014 12:32:39 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+ [88.195.111.91])\r
+ by mx.google.com with ESMTPSA id 4sm46526754eed.14.2014.01.19.12.32.37\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 19 Jan 2014 12:32:38 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/7] cli: extract single message addition in notmuch new to\r
+ clarify code\r
+Date: Sun, 19 Jan 2014 22:32:22 +0200\r
+Message-Id:\r
+ <a7e29c2d62b3e1547aab7d242d9ea52e64a9c84d.1390163335.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.8.5.2\r
+In-Reply-To: <cover.1390163335.git.jani@nikula.org>\r
+References: <cover.1390163335.git.jani@nikula.org>\r
+In-Reply-To: <cover.1390163335.git.jani@nikula.org>\r
+References: <cover.1390163335.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: Sun, 19 Jan 2014 20:32:49 -0000\r
+\r
+The add_files() function has grown huge, chop it up a bit. No\r
+functional changes.\r
+---\r
+ notmuch-new.c | 109 +++++++++++++++++++++++++++++-----------------------------\r
+ 1 file changed, 55 insertions(+), 54 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 6a8b1b2..1dd8fc9 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -240,6 +240,60 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
+ return FALSE;\r
+ }\r
+ \r
++/* Add a single file to the database. */\r
++static notmuch_status_t\r
++add_file (notmuch_database_t *notmuch, const char *filename,\r
++ add_files_state_t *state)\r
++{\r
++ notmuch_message_t *message = NULL;\r
++ const char **tag;\r
++ notmuch_status_t status;\r
++\r
++ status = notmuch_database_begin_atomic (notmuch);\r
++ if (status)\r
++ goto DONE;\r
++\r
++ status = notmuch_database_add_message (notmuch, filename, &message);\r
++ switch (status) {\r
++ /* Success. */\r
++ case NOTMUCH_STATUS_SUCCESS:\r
++ state->added_messages++;\r
++ notmuch_message_freeze (message);\r
++ for (tag = state->new_tags; *tag != NULL; tag++)\r
++ notmuch_message_add_tag (message, *tag);\r
++ if (state->synchronize_flags)\r
++ notmuch_message_maildir_flags_to_tags (message);\r
++ notmuch_message_thaw (message);\r
++ break;\r
++ /* Non-fatal issues (go on to next file). */\r
++ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
++ if (state->synchronize_flags)\r
++ notmuch_message_maildir_flags_to_tags (message);\r
++ break;\r
++ case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
++ fprintf (stderr, "Note: Ignoring non-mail file: %s\n", filename);\r
++ break;\r
++ /* Fatal issues. Don't process anymore. */\r
++ case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
++ case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
++ case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
++ fprintf (stderr, "Error: %s. Halting processing.\n",\r
++ notmuch_status_to_string (status));\r
++ goto DONE;\r
++ default:\r
++ INTERNAL_ERROR ("add_message returned unexpected value: %d", status);\r
++ goto DONE;\r
++ }\r
++\r
++ status = notmuch_database_end_atomic (notmuch);\r
++\r
++ DONE:\r
++ if (message)\r
++ notmuch_message_destroy (message);\r
++\r
++ return status;\r
++}\r
++\r
+ /* Examine 'path' recursively as follows:\r
+ *\r
+ * o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+@@ -291,7 +345,6 @@ add_files (notmuch_database_t *notmuch,\r
+ char *next = NULL;\r
+ time_t fs_mtime, db_mtime;\r
+ notmuch_status_t status, ret = NOTMUCH_STATUS_SUCCESS;\r
+- notmuch_message_t *message = NULL;\r
+ struct dirent **fs_entries = NULL;\r
+ int i, num_fs_entries = 0, entry_type;\r
+ notmuch_directory_t *directory;\r
+@@ -300,7 +353,6 @@ add_files (notmuch_database_t *notmuch,\r
+ time_t stat_time;\r
+ struct stat st;\r
+ notmuch_bool_t is_maildir;\r
+- const char **tag;\r
+ \r
+ if (stat (path, &st)) {\r
+ fprintf (stderr, "Error reading directory %s: %s\n",\r
+@@ -527,63 +579,12 @@ add_files (notmuch_database_t *notmuch,\r
+ fflush (stdout);\r
+ }\r
+ \r
+- status = notmuch_database_begin_atomic (notmuch);\r
++ status = add_file (notmuch, next, state);\r
+ if (status) {\r
+ ret = status;\r
+ goto DONE;\r
+ }\r
+ \r
+- status = notmuch_database_add_message (notmuch, next, &message);\r
+- switch (status) {\r
+- /* success */\r
+- case NOTMUCH_STATUS_SUCCESS:\r
+- state->added_messages++;\r
+- notmuch_message_freeze (message);\r
+- for (tag=state->new_tags; *tag != NULL; tag++)\r
+- notmuch_message_add_tag (message, *tag);\r
+- if (state->synchronize_flags == TRUE)\r
+- notmuch_message_maildir_flags_to_tags (message);\r
+- notmuch_message_thaw (message);\r
+- break;\r
+- /* Non-fatal issues (go on to next file) */\r
+- case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+- if (state->synchronize_flags == TRUE)\r
+- notmuch_message_maildir_flags_to_tags (message);\r
+- break;\r
+- case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+- fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
+- next);\r
+- break;\r
+- /* Fatal issues. Don't process anymore. */\r
+- case NOTMUCH_STATUS_READ_ONLY_DATABASE:\r
+- case NOTMUCH_STATUS_XAPIAN_EXCEPTION:\r
+- case NOTMUCH_STATUS_OUT_OF_MEMORY:\r
+- fprintf (stderr, "Error: %s. Halting processing.\n",\r
+- notmuch_status_to_string (status));\r
+- ret = status;\r
+- goto DONE;\r
+- default:\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
+- INTERNAL_ERROR ("add_message returned unexpected value: %d", status);\r
+- goto DONE;\r
+- }\r
+-\r
+- status = notmuch_database_end_atomic (notmuch);\r
+- if (status) {\r
+- ret = status;\r
+- goto DONE;\r
+- }\r
+-\r
+- if (message) {\r
+- notmuch_message_destroy (message);\r
+- message = NULL;\r
+- }\r
+-\r
+ if (do_print_progress) {\r
+ do_print_progress = 0;\r
+ generic_print_progress ("Processed", "files", state->tv_start,\r
+-- \r
+1.8.5.2\r
+\r