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