[PATCH v6 2/3] add support for user-specified files & directories to ignore

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 11:28:24 +0200, Tomi Ollila  wrote:
> A new configuration key 'new.ignore' is used to determine which
> files and directories user wants not to be scanned as new mails.
> 
> Mark the corresponding test as no longer broken.
> 
> This work merges my previous attempts and Andreas Amann's work
> in id:"ylp7hi23mw8.fsf at tyndall.ie"

I marked this patch with 'needs-review' for consistency with
the 2 other patches. No code changes to the previous version.

Tomi



[PATCH v6 2/3] add support for user-specified files & directories to ignore

2012-02-06 Thread Tomi Ollila
A new configuration key 'new.ignore' is used to determine which
files and directories user wants not to be scanned as new mails.

Mark the corresponding test as no longer broken.

This work merges my previous attempts and Andreas Amann's work
in id:"ylp7hi23mw8.fsf at tyndall.ie"
---
 notmuch-client.h |9 +
 notmuch-config.c |   30 +-
 notmuch-new.c|   45 +
 test/new |1 -
 4 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..f1762ae 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -250,6 +250,15 @@ 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
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);

diff --git a/notmuch-config.c b/notmuch-config.c
index a124e34..1f01128 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -44,7 +44,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 file and directory names\n"
+"\tthat will not be searched for messages by \"notmuch new\".\n";

 static const char user_config_comment[] =
 " User configuration\n"
@@ -105,6 +108,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;
 notmuch_bool_t maildir_synchronize_flags;
 const char **search_exclude_tags;
 size_t search_exclude_tags_length;
@@ -264,6 +269,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;
 config->maildir_synchronize_flags = TRUE;
 config->search_exclude_tags = NULL;
 config->search_exclude_tags_length = 0;
@@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
notmuch_config_set_new_tags (config, tags, 2);
 }

+if (notmuch_config_get_new_ignore (config, ) == NULL) {
+   notmuch_config_set_new_ignore (config, NULL, 0);
+}
+
 if (notmuch_config_get_search_exclude_tags (config, ) == NULL) {
if (is_new) {
const char *tags[] = { "deleted", "spam" };
@@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   
size_t *length)
 &(config->new_tags_length), length);
 }

+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
+{
+return _config_get_list (config, "new", "ignore",
+&(config->new_ignore),
+&(config->new_ignore_length), length);
+}
+
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
 const char *list[],
@@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 &(config->new_tags));
 }

+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *list[],
+  size_t length)
+{
+_config_set_list (config, "new", "ignore", list, length,
+&(config->new_ignore));
+}
+
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t 
*length)
 {
diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..8a615e6 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -39,6 +39,8 @@ typedef struct {
 int verbose;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;

 int total_files;
 int processed_files;
@@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int 
count)
 return 0;
 }

+/* 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)
+{
+size_t i;
+
+for (i = 0; i < state->new_ignore_length; i++)
+   if (strcmp (entry, state->new_ignore[i]) == 0)
+   return TRUE;
+
+return FALSE;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,

[PATCH v6 2/3] add support for user-specified files directories to ignore

2012-02-06 Thread Tomi Ollila
A new configuration key 'new.ignore' is used to determine which
files and directories user wants not to be scanned as new mails.

Mark the corresponding test as no longer broken.

This work merges my previous attempts and Andreas Amann's work
in id:ylp7hi23mw8@tyndall.ie
---
 notmuch-client.h |9 +
 notmuch-config.c |   30 +-
 notmuch-new.c|   45 +
 test/new |1 -
 4 files changed, 71 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index e0eb594..f1762ae 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -250,6 +250,15 @@ 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
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
 
diff --git a/notmuch-config.c b/notmuch-config.c
index a124e34..1f01128 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -44,7 +44,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 file and directory names\n
+\tthat will not be searched for messages by \notmuch new\.\n;
 
 static const char user_config_comment[] =
  User configuration\n
@@ -105,6 +108,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;
 notmuch_bool_t maildir_synchronize_flags;
 const char **search_exclude_tags;
 size_t search_exclude_tags_length;
@@ -264,6 +269,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;
 config-maildir_synchronize_flags = TRUE;
 config-search_exclude_tags = NULL;
 config-search_exclude_tags_length = 0;
@@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
notmuch_config_set_new_tags (config, tags, 2);
 }
 
+if (notmuch_config_get_new_ignore (config, tmp) == NULL) {
+   notmuch_config_set_new_ignore (config, NULL, 0);
+}
+
 if (notmuch_config_get_search_exclude_tags (config, tmp) == NULL) {
if (is_new) {
const char *tags[] = { deleted, spam };
@@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   
size_t *length)
 (config-new_tags_length), length);
 }
 
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
+{
+return _config_get_list (config, new, ignore,
+(config-new_ignore),
+(config-new_ignore_length), length);
+}
+
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
 const char *list[],
@@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 (config-new_tags));
 }
 
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+  const char *list[],
+  size_t length)
+{
+_config_set_list (config, new, ignore, list, length,
+(config-new_ignore));
+}
+
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t 
*length)
 {
diff --git a/notmuch-new.c b/notmuch-new.c
index a569a54..8a615e6 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -39,6 +39,8 @@ typedef struct {
 int verbose;
 const char **new_tags;
 size_t new_tags_length;
+const char **new_ignore;
+size_t new_ignore_length;
 
 int total_files;
 int processed_files;
@@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int 
count)
 return 0;
 }
 
+/* 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)
+{
+size_t i;
+
+for (i = 0; i  state-new_ignore_length; i++)
+   if (strcmp (entry, state-new_ignore[i]) == 0)
+   return TRUE;
+
+return FALSE;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
}
 
/* Ignore special directories 

Re: [PATCH v6 2/3] add support for user-specified files directories to ignore

2012-02-06 Thread Tomi Ollila
On Mon,  6 Feb 2012 11:28:24 +0200, Tomi Ollila tomi.oll...@iki.fi wrote:
 A new configuration key 'new.ignore' is used to determine which
 files and directories user wants not to be scanned as new mails.
 
 Mark the corresponding test as no longer broken.
 
 This work merges my previous attempts and Andreas Amann's work
 in id:ylp7hi23mw8@tyndall.ie

I marked this patch with 'needs-review' for consistency with
the 2 other patches. No code changes to the previous version.

Tomi

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch