[PATCH] Allow user to specify ignored directories
Andreas Amann
andreas.amann at tyndall.ie
Wed Oct 13 16:12:57 PDT 2010
On Wed, 13 Oct 2010 11:09:01 +0200, Michal Sojka <sojkam1 at fel.cvut.cz> 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; j<state->ignore_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
More information about the notmuch
mailing list