[RFC 3/5] cli: support shell globbing patterns in new.ignore
authorJani Nikula <jani@nikula.org>
Tue, 3 Nov 2015 19:49:31 +0000 (21:49 +0200)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:49:59 +0000 (14:49 -0700)
f9/0bca7b8e9bbb9d8c6072fd508ba2b76014f1a7 [new file with mode: 0644]

diff --git a/f9/0bca7b8e9bbb9d8c6072fd508ba2b76014f1a7 b/f9/0bca7b8e9bbb9d8c6072fd508ba2b76014f1a7
new file mode 100644 (file)
index 0000000..201d57f
--- /dev/null
@@ -0,0 +1,167 @@
+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 arlo.cworth.org (Postfix) with ESMTP id C84176DE19C7\r
+ for <notmuch@notmuchmail.org>; Tue,  3 Nov 2015 11:50:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.541\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.541 tagged_above=-999 required=5 tests=[AWL=0.179,\r
+  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
+ RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id YckMbYUXk08I for <notmuch@notmuchmail.org>;\r
+ Tue,  3 Nov 2015 11:50:20 -0800 (PST)\r
+Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
+ [209.85.212.174])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 352646DE0214\r
+ for <notmuch@notmuchmail.org>; Tue,  3 Nov 2015 11:50:16 -0800 (PST)\r
+Received: by wicfx6 with SMTP id fx6so76394716wic.1\r
+ for <notmuch@notmuchmail.org>; Tue, 03 Nov 2015 11:50:14 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=nikula_org.20150623.gappssmtp.com; s=20150623;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references\r
+ :in-reply-to:references;\r
+ bh=GVWCyFt1T1PL8HQlQjHJiAGQMJhOiMO7zHCnlltoPVQ=;\r
+ b=TrWXJsYkeU1RDEpfykRopZnEy60TEZp+NWK/Ho8/CX2F/ahTFtgk97k5SdkT58yvgL\r
+ Zzlmks6YVRQwUksD52h7t7bXyexVrWpLIQ6Xt0q1BDhLZEQVcz/A+ziXMOTlJxTKF35x\r
+ EeeEpz2tPre7nmbLx3y3qQKlduoCn/D1U9Eesa61DnRfdvqsYfuB9Rqyo7MJ5Gue/Axu\r
+ RYJZ6dXmsqpCQUCOMEiujlaeaRPU2Xp40Cs9EsM8FRbKxrvYYZt5NN0mXUYQ8S+XTOOy\r
+ 8a7IFSf2Bi4xTn5vA1vdRPUvSu9w1Vm/wj7cNh8Hd4gyovZP5WJHJJAq62t+Icd4B0+X\r
+ fqdA==\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=GVWCyFt1T1PL8HQlQjHJiAGQMJhOiMO7zHCnlltoPVQ=;\r
+ b=NO6x1QyHUIF9+YenzJuRpFbONB0NPoEUl2eeokLcGop3ljNxx0B1Wnsr2IipZeDYdz\r
+ iQH2ama7gQNsRqi8VQn+OvGGXdNFEHxjAJod03LJbsvHsVVAScN4KlEibnQw9gBNPuBl\r
+ ZCAWETU8dzICLab9H6z5pKn0gQOfYniIgnNloU3vxUThoAc+KawiAEhemr0Ksu778nTP\r
+ 1CLRoa0ZBB2IIAqIpddk8oY1q4vNdiG8bycWP6eOILJvWMZP6FgmYdGb5BLGUebm8IXQ\r
+ Ic9X2JVz5orYhgClGKowpa1iMsJIt03sDka8QxZCThEttZB0Dz+aPbG79DlLobi+CDB9\r
+ h4ow==\r
+X-Gm-Message-State:\r
+ ALoCoQn2v4hQREezcuElfhoYS0w+IXahS9UtZXDju8pLZug+7IgL7jy4qjqCwXn6tVKxxSvVoZp6\r
+X-Received: by 10.194.193.99 with SMTP id hn3mr36163588wjc.15.1446580214644;\r
+ Tue, 03 Nov 2015 11:50:14 -0800 (PST)\r
+Received: from localhost (mobile-access-bceec0-208.dhcp.inet.fi.\r
+ [188.238.192.208])\r
+ by smtp.gmail.com with ESMTPSA id h198sm24928298wmd.9.2015.11.03.11.50.13\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Tue, 03 Nov 2015 11:50:14 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC 3/5] cli: support shell globbing patterns in new.ignore\r
+Date: Tue,  3 Nov 2015 21:49:31 +0200\r
+Message-Id:\r
+ <51db8c12299cb1765d346fa2c93c6c95abb92613.1446579858.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <cover.1446579858.git.jani@nikula.org>\r
+References: <cover.1446579858.git.jani@nikula.org>\r
+In-Reply-To: <cover.1446579858.git.jani@nikula.org>\r
+References: <cover.1446579858.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 03 Nov 2015 19:50:22 -0000\r
+\r
+Keep the existing strcmp on the basename for backwards compatibility,\r
+and additionally use the new.ignore entries as fnmatch(3) patterns on\r
+the absolute filename. Note that it's not enough to add e.g. "foo*bar"\r
+to the list; you will need to do "*/foo*bar" to match the path also.\r
+---\r
+ notmuch-new.c | 33 +++++++++++++++++++++++++--------\r
+ 1 file changed, 25 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index da1d1be2ed3b..d06f9c906fc6 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -22,6 +22,7 @@\r
+ #include "tag-util.h"\r
\r
+ #include <unistd.h>\r
++#include <fnmatch.h>\r
\r
+ typedef struct _filename_node {\r
+     char *filename;\r
+@@ -236,15 +237,31 @@ _entries_resemble_maildir (const char *path, struct dirent **entries, int count)\r
+ /* Test if the file/directory is to be ignored.\r
+  */\r
+ static notmuch_bool_t\r
+-_entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
++_entry_in_ignore_list (const char *path, const char *entry,\r
++                     add_files_state_t *state)\r
+ {\r
++    char *abspath;\r
++    notmuch_bool_t ret = FALSE;\r
+     size_t i;\r
\r
+-    for (i = 0; i < state->new_ignore_length; i++)\r
+-      if (strcmp (entry, state->new_ignore[i]) == 0)\r
+-          return TRUE;\r
++    if (state->new_ignore_length == 0)\r
++      return FALSE;\r
++\r
++    abspath = talloc_asprintf (NULL, "%s/%s", path, entry);\r
++    if (! abspath)\r
++      return FALSE;\r
\r
+-    return FALSE;\r
++    for (i = 0; i < state->new_ignore_length; i++) {\r
++      if (strcmp (entry, state->new_ignore[i]) == 0 ||\r
++          fnmatch (state->new_ignore[i], abspath, 0) == 0) {\r
++          ret = TRUE;\r
++          break;\r
++      }\r
++    }\r
++\r
++    talloc_free (abspath);\r
++\r
++    return ret;\r
+ }\r
\r
+ /* Add a single file to the database. */\r
+@@ -443,7 +460,7 @@ add_files (notmuch_database_t *notmuch,\r
+        * and because we don't care if dirent_type fails on entries\r
+        * that are explicitly ignored.\r
+        */\r
+-      if (_entry_in_ignore_list (entry->d_name, state)) {\r
++      if (_entry_in_ignore_list (path, entry->d_name, state)) {\r
+           if (state->debug)\r
+               printf ("(D) add_files, pass 1: explicitly ignoring %s/%s\n",\r
+                       path, entry->d_name);\r
+@@ -511,7 +528,7 @@ add_files (notmuch_database_t *notmuch,\r
+         entry = fs_entries[i];\r
\r
+       /* Ignore files & directories user has configured to be ignored */\r
+-      if (_entry_in_ignore_list (entry->d_name, state)) {\r
++      if (_entry_in_ignore_list (path, entry->d_name, state)) {\r
+           if (state->debug)\r
+               printf ("(D) add_files, pass 2: explicitly ignoring %s/%s\n",\r
+                       path, entry->d_name);\r
+@@ -744,7 +761,7 @@ count_files (const char *path, int *count, add_files_state_t *state)\r
+       /* Ignore any files/directories the user has configured to be\r
+        * ignored\r
+        */\r
+-      if (_entry_in_ignore_list (entry->d_name, state)) {\r
++      if (_entry_in_ignore_list (path, entry->d_name, state)) {\r
+           if (state->debug)\r
+               printf ("(D) count_files: explicitly ignoring %s/%s\n",\r
+                       path, entry->d_name);\r
+-- \r
+2.1.4\r
+\r