[PATCH 3/7] cli: use dirent_type in count_files too
authorJani Nikula <jani@nikula.org>
Sun, 19 Jan 2014 20:32:24 +0000 (22:32 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:59:10 +0000 (09:59 -0800)
48/1f345a0f9aecb5767bbff2aab4dddeab96ee3a [new file with mode: 0644]

diff --git a/48/1f345a0f9aecb5767bbff2aab4dddeab96ee3a b/48/1f345a0f9aecb5767bbff2aab4dddeab96ee3a
new file mode 100644 (file)
index 0000000..6e2dd7f
--- /dev/null
@@ -0,0 +1,113 @@
+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 2D1C1431FDA\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:55 -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 Ps5hzXYP0CpR for <notmuch@notmuchmail.org>;\r
+       Sun, 19 Jan 2014 12:32:49 -0800 (PST)\r
+Received: from mail-ee0-f41.google.com (mail-ee0-f41.google.com\r
+ [74.125.83.41])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ A3E5C431FC3   for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:45 -0800\r
+ (PST)\r
+Received: by mail-ee0-f41.google.com with SMTP id e49so3129468eek.28\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:44 -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=cGu1awp5zoGgbQDv131j+/NvXXFicBGwWJMMOMjBvus=;\r
+       b=BUHdDfQtTziEIEi9mDX0AwU1W6st98KO7FnJOQy6pRxOR3q/ovs6aPYWPK/SLzGSVW\r
+       KqxSqIA0abtET/Wrx0LoTIVT5mvVj5Gn8cC12BYjfnrFLm8YMQHTGwEjVNcXeBwf9Ord\r
+       3S7AfCzEiaGQuLpq5CpbG7o+C93oWK9TDfN4J4K9ges4C9AVyTjMJGUyRzukVQ9LG8H/\r
+       hliSv/oW/IQl6teNip4YbP8J7Y46sx4/gcpa772BTv7SBN51fzy1/O1hyt50toU0xLrh\r
+       mR0njbUPyGBjZNFYOldrzu7uM+T3syHSgy0+TrDgLHWkM6vMdvMNIl1TB4wNH0bLmxhb\r
+       XdNA==\r
+X-Gm-Message-State:\r
+ ALoCoQk5bCdQQJtgzq4V+e4HEyn2yGOkaH7gnLEWXihVeKpkel6WOfZYCboX19ntu1zNd8lMTBG+\r
+X-Received: by 10.14.99.66 with SMTP id w42mr1129032eef.63.1390163564378;\r
+       Sun, 19 Jan 2014 12:32:44 -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 n7sm46512417eef.5.2014.01.19.12.32.43\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 19 Jan 2014 12:32:43 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/7] cli: use dirent_type in count_files too\r
+Date: Sun, 19 Jan 2014 22:32:24 +0200\r
+Message-Id:\r
+ <024420e6f583f7e4c76ded29b5c9158608dd8f6c.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:55 -0000\r
+\r
+Avoid an extra stat per file, if possible, also when counting the\r
+files for initial indexing.\r
+---\r
+ notmuch-new.c | 9 ++++-----\r
+ 1 file changed, 4 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 7f3b3b0..e6ca841 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -702,9 +702,9 @@ count_files (const char *path, int *count, add_files_state_t *state)\r
+ {\r
+     struct dirent *entry = NULL;\r
+     char *next;\r
+-    struct stat st;\r
+     struct dirent **fs_entries = NULL;\r
+     int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);\r
++    int entry_type;\r
+     int i = 0;\r
\r
+     if (num_fs_entries == -1) {\r
+@@ -742,15 +742,14 @@ count_files (const char *path, int *count, add_files_state_t *state)\r
+           continue;\r
+       }\r
\r
+-      stat (next, &st);\r
+-\r
+-      if (S_ISREG (st.st_mode)) {\r
++      entry_type = dirent_type (path, entry);\r
++      if (entry_type == S_IFREG) {\r
+           *count = *count + 1;\r
+           if (*count % 1000 == 0) {\r
+               printf ("Found %d files so far.\r", *count);\r
+               fflush (stdout);\r
+           }\r
+-      } else if (S_ISDIR (st.st_mode)) {\r
++      } else if (entry_type == S_IFDIR) {\r
+           count_files (next, count, state);\r
+       }\r
\r
+-- \r
+1.8.5.2\r
+\r