Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 918F640BFD3 for ; Wed, 13 Oct 2010 16:16:26 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -4.2 X-Spam-Level: X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ndB0ckcgaiCS for ; Wed, 13 Oct 2010 16:16:15 -0700 (PDT) Received: from mail2.tyndall.ie (tyndall.ucc.ie [143.239.64.1]) by olra.theworths.org (Postfix) with ESMTP id B9C6540BFD5 for ; Wed, 13 Oct 2010 16:16:14 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail2.tyndall.ie (Postfix) with ESMTP id 29C08B216F; Thu, 14 Oct 2010 00:16:13 +0100 (IST) X-Virus-Scanned: Debian amavisd-new at mail.tyndall.ie Received: from mail2.tyndall.ie ([127.0.0.1]) by localhost (bastion2.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uvIXBwdIb7+2; Thu, 14 Oct 2010 00:16:13 +0100 (IST) Received: from unixmail.tyndall.ie (unknown [10.1.64.22]) by mail2.tyndall.ie (Postfix) with ESMTP id 0E2ACB216A; Thu, 14 Oct 2010 00:16:13 +0100 (IST) Received: from localhost (localhost [127.0.0.1]) by unixmail.tyndall.ie (Postfix) with ESMTP id 0AD6594DC1; Thu, 14 Oct 2010 00:16:13 +0100 (IST) X-Virus-Scanned: amavisd-new at tyndall.ie Received: from unixmail.tyndall.ie ([127.0.0.1]) by localhost (unixmail.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dOiHSlnk0hxH; Thu, 14 Oct 2010 00:16:11 +0100 (IST) Received: from localhost6.localdomain6 (lnx0015f24b24c7.nmrc.ucc.ie [10.1.65.106]) by unixmail.tyndall.ie (Postfix) with ESMTP id A8CBE94DBB; Thu, 14 Oct 2010 00:16:11 +0100 (IST) Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.3) with ESMTP id o9DND3ve011055; Thu, 14 Oct 2010 00:13:03 +0100 Received: (from aamann@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id o9DNCvTX011053; Thu, 14 Oct 2010 00:12:57 +0100 X-Authentication-Warning: localhost6.localdomain6: aamann set sender to andreas.amann@tyndall.ie using -f From: Andreas Amann To: Michal Sojka , notmuch@notmuchmail.org Subject: Re: [PATCH] Allow user to specify ignored directories In-Reply-To: <87zkui1mtu.fsf@steelpick.2x.cz> References: <87zkui1mtu.fsf@steelpick.2x.cz> User-Agent: Notmuch/0.3.1-92-g42f7a90 (http://notmuchmail.org) Emacs/24.0.50.1 (x86_64-unknown-linux-gnu) Date: Thu, 14 Oct 2010 00:12:57 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Wed, 13 Oct 2010 23:16:26 -0000 On Wed, 13 Oct 2010 11:09:01 +0200, Michal Sojka wrote: > On Thu, 30 Sep 2010, Andreas Amann wrote: > > Hi, > > thanks, the patch seems good to me. See the comment bellow. > > > > @@ -202,7 +219,8 @@ _entries_resemble_maildir (struct dirent **entries, int count) > > static notmuch_status_t > > add_files_recursive (notmuch_database_t *notmuch, > > const char *path, > > - add_files_state_t *state) > > + add_files_state_t *state, > > + notmuch_config_t *config) > > I would not add additional parameter here. It's IMHO better to add field > "ignored_files" to add_files_state_t similarly as it is done for > new_tags. > Thanks for your comment, you are right. Here is an improved version, any comments? Add functionality to ignore user specified directories during recursive search. An "ignore" label in the "new" section of the configuration file is added. Example snippet from ~/.notmuch-config: [new] ignore=.git;.notmuch; tags=unread;inbox; --- notmuch-client.h | 8 +++++++ notmuch-config.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- notmuch-new.c | 35 ++++++++++++++++++++++++-------- 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 20be43b..9bc6ef1 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -191,6 +191,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config, const char *new_tags[], size_t length); +const char ** +notmuch_config_get_new_ignore (notmuch_config_t *config, + size_t *length); +void +notmuch_config_set_new_ignore (notmuch_config_t *config, + const char *new_ignore[], + size_t length); + notmuch_bool_t debugger_is_active (void); diff --git a/notmuch-config.c b/notmuch-config.c index cf30603..8841eaf 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -43,7 +43,10 @@ static const char new_config_comment[] = " The following options are supported here:\n" "\n" "\ttags A list (separated by ';') of the tags that will be\n" - "\t added to all messages incorporated by \"notmuch new\".\n"; + "\t added to all messages incorporated by \"notmuch new\".\n" + "\n" + "\tignore A list (separated by ';') of directories that will not\n" + "\t be searched for messages by \"notmuch new\".\n"; static const char user_config_comment[] = " User configuration\n" @@ -72,6 +75,8 @@ struct _notmuch_config { size_t user_other_email_length; const char **new_tags; size_t new_tags_length; + const char **new_ignore; + size_t new_ignore_length; }; static int @@ -221,6 +226,8 @@ notmuch_config_open (void *ctx, config->user_other_email_length = 0; config->new_tags = NULL; config->new_tags_length = 0; + config->new_ignore = NULL; + config->new_ignore_length = 0; if (! g_key_file_load_from_file (config->key_file, config->filename, @@ -313,6 +320,11 @@ notmuch_config_open (void *ctx, notmuch_config_set_new_tags (config, tags, 2); } + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) { + const char *ignore[] = { ".notmuch" }; + notmuch_config_set_new_ignore (config, ignore, 2); + } + /* Whenever we know of configuration sections that don't appear in * the configuration file, we add some comments to help the user * understand what can be done. */ @@ -562,3 +574,46 @@ notmuch_config_set_new_tags (notmuch_config_t *config, config->new_tags = NULL; } +const char ** +notmuch_config_get_new_ignore (notmuch_config_t *config, + size_t *length) +{ + char **ignore; + size_t ignore_length; + unsigned int i; + + if (config->new_ignore == NULL) { + ignore = g_key_file_get_string_list (config->key_file, + "new", "ignore", + &ignore_length, NULL); + if (ignore) { + config->new_ignore = talloc_size (config, + sizeof (char *) * + (ignore_length + 1)); + for (i = 0; i < ignore_length; i++) + config->new_ignore[i] = talloc_strdup (config->new_ignore, + ignore[i]); + config->new_ignore[i] = NULL; + + g_strfreev (ignore); + + config->new_ignore_length = ignore_length; + } + } + + *length = config->new_ignore_length; + return config->new_ignore; +} + +void +notmuch_config_set_new_ignore (notmuch_config_t *config, + const char *new_ignore[], + size_t length) +{ + g_key_file_set_string_list (config->key_file, + "new", "ignore", + new_ignore, length); + + talloc_free (config->new_ignore); + config->new_ignore = NULL; +} diff --git a/notmuch-new.c b/notmuch-new.c index 8818728..241a74e 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -38,6 +38,9 @@ typedef struct { const char **new_tags; size_t new_tags_length; + const char **ignore_list; + size_t ignore_list_length; + int total_files; int processed_files; int added_messages; @@ -164,6 +167,21 @@ _entries_resemble_maildir (struct dirent **entries, int count) return 0; } +/* Check if user asked to ignore these directories */ + +static int +_entry_in_ignore_list ( const char *entry, add_files_state_t* state) +{ + size_t j; + for (j = 0; jignore_list_length; j++) + { + if (strcmp (entry, state->ignore_list[j]) == 0 ) + return 1; + } + + return 0; +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -287,12 +305,10 @@ add_files_recursive (notmuch_database_t *notmuch, * Also ignore the .notmuch directory and any "tmp" directory * that appears within a maildir. */ - /* XXX: Eventually we'll want more sophistication to let the - * user specify files to be ignored. */ if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || (is_maildir && strcmp (entry->d_name, "tmp") == 0) || - strcmp (entry->d_name, ".notmuch") ==0) + _entry_in_ignore_list (entry->d_name, state) ) { continue; } @@ -571,7 +587,7 @@ add_files (notmuch_database_t *notmuch, * initialized to zero by the top-level caller before calling * count_files). */ static void -count_files (const char *path, int *count) +count_files (const char *path, int *count, add_files_state_t *state) { struct dirent *entry = NULL; char *next; @@ -595,11 +611,9 @@ count_files (const char *path, int *count) /* Ignore special directories to avoid infinite recursion. * Also ignore the .notmuch directory. */ - /* XXX: Eventually we'll want more sophistication to let the - * user specify files to be ignored. */ if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || - strcmp (entry->d_name, ".notmuch") == 0) + _entry_in_ignore_list (entry->d_name, state) ) { continue; } @@ -620,7 +634,7 @@ count_files (const char *path, int *count) fflush (stdout); } } else if (S_ISDIR (st.st_mode)) { - count_files (next, count); + count_files (next, count, state); } free (next); @@ -737,6 +751,9 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) return 1; add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); + add_files_state.ignore_list = + notmuch_config_get_new_ignore (config, &add_files_state.ignore_list_length); + db_path = notmuch_config_get_database_path (config); dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch"); @@ -745,7 +762,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) int count; count = 0; - count_files (db_path, &count); + count_files (db_path, &count, &add_files_state); if (interrupted) return 1; -- 1.7.0.4