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 88EB940BFD5 for ; Thu, 30 Sep 2010 15:16:24 -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 UpijZct-RKD7 for ; Thu, 30 Sep 2010 15:16:13 -0700 (PDT) X-Greylist: delayed 475 seconds by postgrey-1.32 at olra; Thu, 30 Sep 2010 15:16:12 PDT Received: from mail2.tyndall.ie (tyndall.ucc.ie [143.239.64.1]) by olra.theworths.org (Postfix) with ESMTP id C88F84196F2 for ; Thu, 30 Sep 2010 15:16:12 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail2.tyndall.ie (Postfix) with ESMTP id 61463B2132 for ; Thu, 30 Sep 2010 23:08:16 +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 qZZgLVRAplvL for ; Thu, 30 Sep 2010 23:08:16 +0100 (IST) Received: from unixmail.tyndall.ie (unknown [10.1.64.22]) by mail2.tyndall.ie (Postfix) with ESMTP id 427D0B2131 for ; Thu, 30 Sep 2010 23:08:16 +0100 (IST) Received: from localhost (localhost [127.0.0.1]) by unixmail.tyndall.ie (Postfix) with ESMTP id 3E6E6865FB for ; Thu, 30 Sep 2010 23:08:16 +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 nWSsz3ua4MTA for ; Thu, 30 Sep 2010 23:08:10 +0100 (IST) Received: from localhost.localdomain (lnx0015f24b24c7.nmrc.ucc.ie [10.1.65.106]) by unixmail.tyndall.ie (Postfix) with ESMTP id 9B64D865F5 for ; Thu, 30 Sep 2010 23:08:10 +0100 (IST) Received: from localhost.localdomain (lnx0015f24b24c7 [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.3) with ESMTP id o8UM8Ptb032602 for ; Thu, 30 Sep 2010 23:08:25 +0100 Received: (from aamann@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) id o8UM8NMB032600; Thu, 30 Sep 2010 23:08:23 +0100 X-Authentication-Warning: localhost.localdomain: aamann set sender to andreas.amann@tyndall.ie using -f From: Andreas Amann To: notmuch@notmuchmail.org Subject: [PATCH] Allow user to specify ignored directories User-Agent: Notmuch/0.3.1-59-g676d251 (http://notmuchmail.org) Emacs/24.0.50.1 (x86_64-unknown-linux-gnu) Date: Thu, 30 Sep 2010 23:08:23 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Mailman-Approved-At: Tue, 12 Oct 2010 16:01:05 -0700 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: Thu, 30 Sep 2010 22:16:24 -0000 Hi list, this is my first post. I found notmuch a couple of days ago and it works great. However I wanted to be able to ignore certain directories (mostly .git in my case) when "notmuch new" is running. With this patch the user can provide a list of directories which are ignored during the recursive search for new messages. An "ignore" label in the "new" section of the configuration file is added for this purpose to enable for example something like [new] ignore=.git;.notmuch; tags=unread;inbox; in the .notmuch-config file. Feel free to apply if you find it useful. Andreas --- notmuch-client.h | 8 +++++++ notmuch-config.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++- notmuch-new.c | 43 +++++++++++++++++++++++++++------------- 3 files changed, 93 insertions(+), 15 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..0e9c4d7 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -164,6 +164,23 @@ _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, notmuch_config_t *config) +{ + size_t j; + size_t ignore_length; + const char** ignore = notmuch_config_get_new_ignore (config, &ignore_length); + for (j = 0; jd_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, config) ) { continue; } next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); - status = add_files_recursive (notmuch, next, state); + status = add_files_recursive (notmuch, next, state, config); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; talloc_free (next); @@ -509,7 +525,8 @@ add_files_recursive (notmuch_database_t *notmuch, static notmuch_status_t add_files (notmuch_database_t *notmuch, const char *path, - add_files_state_t *state) + add_files_state_t *state, + notmuch_config_t *config) { notmuch_status_t status; struct sigaction action; @@ -546,7 +563,7 @@ add_files (notmuch_database_t *notmuch, return NOTMUCH_STATUS_FILE_ERROR; } - status = add_files_recursive (notmuch, path, state); + status = add_files_recursive (notmuch, path, state, config); if (timer_is_active) { /* Now stop the timer. */ @@ -571,7 +588,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, notmuch_config_t *config) { struct dirent *entry = NULL; char *next; @@ -595,11 +612,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, config) ) { continue; } @@ -620,7 +635,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, config); } free (next); @@ -745,7 +760,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) int count; count = 0; - count_files (db_path, &count); + count_files (db_path, &count, config); if (interrupted) return 1; @@ -792,7 +807,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) add_files_state.removed_files = _filename_list_create (ctx); add_files_state.removed_directories = _filename_list_create (ctx); - ret = add_files (notmuch, db_path, &add_files_state); + ret = add_files (notmuch, db_path, &add_files_state, config); removed_files = 0; renamed_files = 0; -- 1.7.0.4 -- Dr. Andreas Amann Tyndall National Institute University College Cork Ireland