[PATCH] Allow user to specify ignored directories

2010-10-14 Thread Andreas Amann
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"
 "\ttagsA list (separated by ';') of the tags that will be\n"
-"\tadded to all messages incorporated by \"notmuch new\".\n";
+"\tadded to all messages incorporated by \"notmuch new\".\n"
+"\n"
+"\tignore  A list (separated by ';') of directories that will not\n"
+"\tbe 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, ) == 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",
+ _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 

[PATCH] Allow user to specify ignored directories

2010-10-13 Thread Michal Sojka
On Thu, 30 Sep 2010, Andreas Amann wrote:
> 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

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.

-Michal


[PATCH] Allow user to specify ignored directories

2010-10-01 Thread Andreas Amann
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"
 "\ttagsA list (separated by ';') of the tags that will be\n"
-"\tadded to all messages incorporated by \"notmuch new\".\n";
+"\tadded to all messages incorporated by \"notmuch new\".\n"
+"\n"
+"\tignore  A list (separated by ';') of directories that will not\n"
+"\tbe 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, ) == 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",
+ _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