--- /dev/null
+Return-Path: <glasse@cs.rpi.edu>\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 A7939429E48\r
+ for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:10:30 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.54\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,\r
+ RCVD_IN_SORBS_WEB=0.614] 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 w3ZrmvnjD5Zl for <notmuch@notmuchmail.org>;\r
+ Wed, 15 Feb 2012 14:10:30 -0800 (PST)\r
+Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu\r
+ [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS\r
+ id D6AAB429E43 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:10:29 -0800\r
+ (PST)\r
+X-Hash:\r
+ S|27febe0d6a4a25f7165855ffcf20f3e2c2e41321|d46bf90b1bccc1c6fd89498d004525ee\r
+X-Countries: Cameroon, United States\r
+X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]\r
+ (localhost) {Cameroon}\r
+DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from\r
+ :to:cc:subject:date:message-id:in-reply-to:references; s=\r
+ default; i=glasse@cs.rpi.edu; t=1329343827; x=1329948627; l=4690;\r
+ bh=1gAx2pb+B+LfzgRdy0uZzzlaHmY=; b=Ips66o/vU8UNdpRkj5ujg91\r
+ Gwf/71hDPAEs+KnYN4QPKP1xRk8UntxS5oosR3wHhmm/S3fKJqvL0hD+gJgw4lKx\r
+ brsuk0E/NvhnpIN0ZCdYitEMm1aKsU8nBOBwoMPpqNisuuZNai+vlPo6AGIYT/Sc\r
+ aA8T+1iEmW0Gm06JlrMQ=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc\r
+ :subject:date:message-id:in-reply-to:references; q=dns; s=\r
+ default; b=Z3UCn4n21CxtwkaHSSJcYLmhaxTp9y4K3Vp+ApBPabX34eEe3eRn6\r
+ x6krPyGTw/Pc8ShYI/z1WjDqcENBuczt3096jlbf5pR7RUnVXzvh8RUePmfJbxrw\r
+ MxIBsB/fMrdZ/LsD2iBsQyk7QTa3jPMDguSlaiqEOoT2iOY5gKl+io=\r
+X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00\r
+X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit\r
+ 15)\r
+Authentication-Results: cliffclavin.cs.rpi.edu;\r
+ DKIM=neutral (none) header.from=glasse@cs.rpi.edu;\r
+ SPF=neutral (mfrom;\r
+ Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu\r
+X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM9tuK008835 Auth:glasse\r
+X-Virus-Scanned-By: cliffclavin.cs.rpi.edu\r
+Received: from localhost ([195.24.209.20]) (authenticated bits=0)\r
+ by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM9tuK008835\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);\r
+ Wed, 15 Feb 2012 17:10:19 -0500 (EST)\r
+ (envelope-from glasse@cs.rpi.edu)\r
+From: Ethan Glasser-Camp <glasse@cs.rpi.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC PATCH 08/13] count_files and add_files shall be generic\r
+Date: Wed, 15 Feb 2012 17:02:01 -0500\r
+Message-Id: <1329343326-16410-9-git-send-email-glasse@cs.rpi.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>\r
+X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25\r
+Cc: Ethan Glasser-Camp <ethan@betacantrips.com>\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: Wed, 15 Feb 2012 22:10:30 -0000\r
+\r
+From: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+\r
+Rename current count_files and add_files to maildir_count_files and\r
+maildir_add_files. This allows the possibility, at least, of having\r
+other backends.\r
+\r
+Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>\r
+---\r
+ notmuch-new.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-----------\r
+ 1 files changed, 50 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index dbdfbb6..d30fba1 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -340,9 +340,9 @@ _add_message (add_files_state_t *state, notmuch_database_t *notmuch,\r
+ * if fs_mtime isn't the current wall-clock time.\r
+ */\r
+ static notmuch_status_t\r
+-add_files_recursive (notmuch_database_t *notmuch,\r
+- const char *path,\r
+- add_files_state_t *state)\r
++maildir_add_files_recursive (notmuch_database_t *notmuch,\r
++ const char *path,\r
++ add_files_state_t *state)\r
+ {\r
+ DIR *dir = NULL;\r
+ struct dirent *entry = NULL;\r
+@@ -449,7 +449,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ }\r
+ \r
+ next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+- status = add_files_recursive (notmuch, next, state);\r
++ status = maildir_add_files_recursive (notmuch, next, state);\r
+ if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
+ ret = status;\r
+ talloc_free (next);\r
+@@ -663,13 +663,34 @@ stop_progress_printing_timer (void)\r
+ sigaction (SIGALRM, &action, NULL);\r
+ }\r
+ \r
++static notmuch_status_t\r
++maildir_add_files (notmuch_database_t *notmuch,\r
++ const char *path,\r
++ add_files_state_t *state);\r
++\r
++/* Dispatch function to call the correct mailstore_add_files\r
++ * function. */\r
++static notmuch_status_t\r
++add_files (notmuch_database_t *notmuch, notmuch_config_t *config,\r
++ add_files_state_t *state)\r
++{\r
++ const char *path = notmuch_config_get_database_path (config);\r
++ if (strcmp (notmuch_config_get_database_type (config), "maildir") == 0)\r
++ return maildir_add_files (notmuch, path, state);\r
++\r
++ /* Default case */\r
++ fprintf (stderr, "Could not add files for mailstore %s: unknown mailstore\n",\r
++ notmuch_config_get_database_type (config));\r
++ /* FIXME: "invalid argument" error code would be nice */\r
++ return NOTMUCH_STATUS_FILE_ERROR;\r
++}\r
+ \r
+ /* This is the top-level entry point for add_files. It does a couple\r
+ * of error checks and then calls into the recursive function. */\r
+ static notmuch_status_t\r
+-add_files (notmuch_database_t *notmuch,\r
+- const char *path,\r
+- add_files_state_t *state)\r
++maildir_add_files (notmuch_database_t *notmuch,\r
++ const char *path,\r
++ add_files_state_t *state)\r
+ {\r
+ notmuch_status_t status;\r
+ struct stat st;\r
+@@ -685,11 +706,28 @@ add_files (notmuch_database_t *notmuch,\r
+ return NOTMUCH_STATUS_FILE_ERROR;\r
+ }\r
+ \r
+- status = add_files_recursive (notmuch, path, state);\r
++ status = maildir_add_files_recursive (notmuch, path, state);\r
+ \r
+ return status;\r
+ }\r
+ \r
++static void\r
++maildir_count_files (const char *path, int *count);\r
++\r
++/* Dispatch function to call the correct mailstore_count_files\r
++ * function. N.B. This function may get refactored into add_files! */\r
++static void\r
++count_files (unused (notmuch_database_t *notmuch), notmuch_config_t *config, int *count)\r
++{\r
++ if (strcmp (notmuch_config_get_database_type (config), "maildir") == 0) {\r
++ maildir_count_files (notmuch_config_get_database_path (config), count);\r
++ return;\r
++ }\r
++\r
++ /* Eh, screw it, this function shouldn't even exist */\r
++ *count = 0;\r
++}\r
++\r
+ /* XXX: This should be merged with the add_files function since it\r
+ * shares a lot of logic with it. */\r
+ /* Recursively count all regular files in path and all sub-directories\r
+@@ -697,7 +735,7 @@ add_files (notmuch_database_t *notmuch,\r
+ * initialized to zero by the top-level caller before calling\r
+ * count_files). */\r
+ static void\r
+-count_files (const char *path, int *count)\r
++maildir_count_files (const char *path, int *count)\r
+ {\r
+ struct dirent *entry = NULL;\r
+ char *next;\r
+@@ -746,7 +784,7 @@ count_files (const char *path, int *count)\r
+ fflush (stdout);\r
+ }\r
+ } else if (S_ISDIR (st.st_mode)) {\r
+- count_files (next, count);\r
++ maildir_count_files (next, count);\r
+ }\r
+ \r
+ free (next);\r
+@@ -905,7 +943,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ int count;\r
+ \r
+ count = 0;\r
+- count_files (db_path, &count);\r
++ count_files (notmuch, config, &count);\r
+ if (interrupted)\r
+ return 1;\r
+ \r
+@@ -962,7 +1000,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ timer_is_active = TRUE;\r
+ }\r
+ \r
+- ret = add_files (notmuch, db_path, &add_files_state);\r
++ ret = add_files (notmuch, config, &add_files_state);\r
+ \r
+ gettimeofday (&tv_start, NULL);\r
+ for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {\r
+-- \r
+1.7.5.4\r
+\r