[PATCH 6/6] cli: add top level --config=FILE option

2013-01-29 Thread Jani Nikula
Let the user specify the config file on the command line.
---
 notmuch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/notmuch.c b/notmuch.c
index f4bfeaa..71cd0d6 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -258,6 +258,7 @@ main (int argc, char *argv[])
 char *talloc_report;
 const char *command_name = NULL;
 command_t *command;
+char *config_file_name = NULL;
 notmuch_config_t *config;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -266,6 +267,7 @@ main (int argc, char *argv[])
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_BOOLEAN, _help, "help", 'h', 0 },
{ NOTMUCH_OPT_BOOLEAN, _version, "version", 'v', 0 },
+   { NOTMUCH_OPT_STRING, _file_name, "config", 'c', 0 },
{ 0, 0, 0, 0, 0 }
 };

@@ -303,7 +305,7 @@ main (int argc, char *argv[])
return 1;
 }

-config = notmuch_config_open (local, NULL, command->create_config);
+config = notmuch_config_open (local, config_file_name, 
command->create_config);
 if (!config)
return 1;

-- 
1.7.10.4



[PATCH 5/6] cli: move config open/close to main() from subcommands

2013-01-29 Thread Jani Nikula
This allows specifying config file as a top level argument to notmuch,
and generally makes it possible to override config file options in
main(), without having to touch the subcommands.

This also makes notmuch config the talloc context for subcommands.
---
 notmuch-client.h  |   30 +++---
 notmuch-config.c  |   40 +++
 notmuch-count.c   |   11 +++---
 notmuch-dump.c|7 +-
 notmuch-new.c |   17 ++-
 notmuch-reply.c   |   15 +
 notmuch-restore.c |   11 +++---
 notmuch-search.c  |   15 +
 notmuch-setup.c   |   17 ++-
 notmuch-show.c|   15 +
 notmuch-tag.c |   15 +
 notmuch.c |   61 +++--
 12 files changed, 91 insertions(+), 163 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index b3dcb21..45749a6 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -150,6 +150,8 @@ chomp_newline (char *str)
  */
 extern int notmuch_format_version;

+typedef struct _notmuch_config notmuch_config_t;
+
 /* Commands that support structured output should support the
  * following argument
  *  { NOTMUCH_OPT_INT, _format_version, "format-version", 0, 0 }
@@ -169,40 +171,34 @@ int
 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);

 int
-notmuch_count_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_dump_command (void *ctx, int argc, char *argv[]);
+notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_new_command (void *ctx, int argc, char *argv[]);
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_reply_command (void *ctx, int argc, char *argv[]);
+notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_restore_command (void *ctx, int argc, char *argv[]);
+notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_search_command (void *ctx, int argc, char *argv[]);
+notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_setup_command (void *ctx, int argc, char *argv[]);
+notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_show_command (void *ctx, int argc, char *argv[]);
+notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_tag_command (void *ctx, int argc, char *argv[]);
+notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
+notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);

 int
-notmuch_cat_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_config_command (void *ctx, int argc, char *argv[]);
+notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);

 const char *
 notmuch_time_relative_date (const void *ctx, time_t then);
@@ -243,8 +239,6 @@ json_quote_str (const void *ctx, const char *str);

 /* notmuch-config.c */

-typedef struct _notmuch_config notmuch_config_t;
-
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
diff --git a/notmuch-config.c b/notmuch-config.c
index 247fbe4..48312e3 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key)
 }

 static int
-notmuch_config_command_get (void *ctx, char *item)
+notmuch_config_command_get (notmuch_config_t *config, char *item)
 {
-notmuch_config_t *config;
-
-config = notmuch_config_open (ctx, NULL, FALSE);
-if (config == NULL)
-   return 1;
-
 if (strcmp(item, "database.path") == 0) {
printf ("%s\n", notmuch_config_get_database_path (config));
 } else if (strcmp(item, "user.name") == 0) {
@@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item)
g_strfreev (value);
 }

-notmuch_config_close (config);
-
 return 0;
 }

 static int
-notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
+notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, 
char *argv[])
 {
-notmuch_config_t *config;
 char *group, *key;
-int ret;

 if (_item_split (item, , ))
return 1;

-config = notmuch_config_open (ctx, NULL, FALSE);
-if (config == NULL)
-   return 1;
-
 /* With only the name of an item, we clear it from the
  * configuration file.
  *
@@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int 
argc, char *argv[])
break;
 }

-ret = notmuch_config_save (config);
-notmuch_config_close (config);
-
-return ret;
+return notmuch_config_save (config);
 }

 static int
-notmuch_config_command_list (void *ctx)
+notmuch_config_command_list (notmuch_config_t *config)
 {
-notmuch_config_t *config;
 char **groups;
 size_t g, groups_length;

-config = 

[PATCH 4/6] cli: plug main notmuch command into subcommand machinery

2013-01-29 Thread Jani Nikula
This also allows the main notmuch command to have arguments (though
they are not used).
---
 notmuch.c |   26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index c47b998..67d5772 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -34,7 +34,13 @@ typedef struct command {
 static int
 notmuch_help_command (void *ctx, int argc, char *argv[]);

+static int
+notmuch_command (void *ctx, int argc, char *argv[]);
+
 static command_t commands[] = {
+{ NULL, notmuch_command,
+  NULL,
+  "Notmuch main command." },
 { "setup", notmuch_setup_command,
   NULL,
   "Interactively setup notmuch for first use." },
@@ -76,7 +82,8 @@ find_command (const char *name)
 size_t i;

 for (i = 0; i < ARRAY_SIZE (commands); i++)
-   if (strcmp (name, commands[i].name) == 0)
+   if ((!name && !commands[i].name) ||
+   (name && commands[i].name && strcmp (name, commands[i].name) == 0))
return [i];

 return NULL;
@@ -101,8 +108,8 @@ usage (FILE *out)
 for (i = 0; i < ARRAY_SIZE (commands); i++) {
command = [i];

-   fprintf (out, "  %-11s  %s\n",
-command->name, command->summary);
+   if (command->name)
+   fprintf (out, "  %-11s  %s\n", command->name, command->summary);
 }

 fprintf (out, "\n");
@@ -192,7 +199,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
  * to be more clever about this in the future.
  */
 static int
-notmuch (void *ctx)
+notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
 {
 notmuch_config_t *config;
 char *db_path;
@@ -255,6 +262,7 @@ main (int argc, char *argv[])
 {
 void *local;
 char *talloc_report;
+const char *command_name = NULL;
 command_t *command;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -276,9 +284,6 @@ main (int argc, char *argv[])
 /* Globally default to the current output format version. */
 notmuch_format_version = NOTMUCH_FORMAT_CUR;

-if (argc == 1)
-   return notmuch (local);
-
 opt_index = parse_arguments (argc, argv, options, 1);
 if (opt_index < 0) {
/* diagnostics already printed */
@@ -293,10 +298,13 @@ main (int argc, char *argv[])
return 0;
 }

-command = find_command (argv[opt_index]);
+if (opt_index < argc)
+   command_name = argv[opt_index];
+
+command = find_command (command_name);
 if (!command) {
fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
-argv[opt_index]);
+command_name);
return 1;
 }

-- 
1.7.10.4



[PATCH 3/6] cli: abstract subcommand finding into a new function

2013-01-29 Thread Jani Nikula
Clean up code.
---
 notmuch.c |   68 +++--
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index b413b53..c47b998 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -70,6 +70,18 @@ static command_t commands[] = {
   "This message, or more detailed help for the named command." }
 };

+static command_t *
+find_command (const char *name)
+{
+size_t i;
+
+for (i = 0; i < ARRAY_SIZE (commands); i++)
+   if (strcmp (name, commands[i].name) == 0)
+   return [i];
+
+return NULL;
+}
+
 int notmuch_format_version;

 static void
@@ -139,7 +151,6 @@ static int
 notmuch_help_command (void *ctx, int argc, char *argv[])
 {
 command_t *command;
-unsigned int i;

 argc--; argv++; /* Ignore "help" */

@@ -158,13 +169,10 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
return 0;
 }

-for (i = 0; i < ARRAY_SIZE (commands); i++) {
-   command = [i];
-
-   if (strcmp (argv[0], command->name) == 0) {
-   char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
-   exec_man (page);
-   }
+command = find_command (argv[0]);
+if (command) {
+   char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
+   exec_man (page);
 }

 if (strcmp (argv[0], "search-terms") == 0) {
@@ -246,10 +254,11 @@ int
 main (int argc, char *argv[])
 {
 void *local;
+char *talloc_report;
 command_t *command;
-unsigned int i;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
+int ret = 0;

 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_BOOLEAN, _help, "help", 'h', 0 },
@@ -284,37 +293,30 @@ main (int argc, char *argv[])
return 0;
 }

-for (i = 0; i < ARRAY_SIZE (commands); i++) {
-   command = [i];
-
-   if (strcmp (argv[opt_index], command->name) == 0) {
-   int ret;
-   char *talloc_report;
-
-   ret = (command->function)(local, argc - opt_index, argv + 
opt_index);
+command = find_command (argv[opt_index]);
+if (!command) {
+   fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
+argv[opt_index]);
+   return 1;
+}

-   /* in the future support for this environment variable may
-* be supplemented or replaced by command line arguments
-* --leak-report and/or --leak-report-full */
+ret = (command->function)(local, argc - opt_index, argv + opt_index);

-   talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
+/* in the future support for this environment variable may
+ * be supplemented or replaced by command line arguments
+ * --leak-report and/or --leak-report-full */

-   /* this relies on the previous call to
-* talloc_enable_null_tracking */
+talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");

-   if (talloc_report && strcmp (talloc_report, "") != 0) {
-   FILE *report = fopen (talloc_report, "w");
-   talloc_report_full (NULL, report);
-   }
+/* this relies on the previous call to
+ * talloc_enable_null_tracking */

-   return ret;
-   }
+if (talloc_report && strcmp (talloc_report, "") != 0) {
+   FILE *report = fopen (talloc_report, "w");
+   talloc_report_full (NULL, report);
 }

-fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
-argv[1]);
-
 talloc_free (local);

-return 1;
+return ret;
 }
-- 
1.7.10.4



[PATCH 2/6] cli: make notmuch_config_open() "is new" parameter input only

2013-01-29 Thread Jani Nikula
Use the notmuch_config_is_new() function instead.
---
 notmuch-client.h |2 +-
 notmuch-config.c |   32 +++-
 notmuch-count.c  |2 +-
 notmuch-dump.c   |2 +-
 notmuch-new.c|2 +-
 notmuch-reply.c  |2 +-
 notmuch-restore.c|2 +-
 notmuch-search.c |2 +-
 notmuch-setup.c  |7 +++
 notmuch-show.c   |2 +-
 notmuch-tag.c|2 +-
 notmuch.c|5 ++---
 test/random-corpus.c |2 +-
 13 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 07367e0..b3dcb21 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -248,7 +248,7 @@ typedef struct _notmuch_config notmuch_config_t;
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
-notmuch_bool_t *is_new_ret);
+notmuch_bool_t create_new);

 void
 notmuch_config_close (notmuch_config_t *config);
diff --git a/notmuch-config.c b/notmuch-config.c
index e733e92..247fbe4 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -233,10 +233,9 @@ get_username_from_passwd_file (void *ctx)
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
-notmuch_bool_t *is_new_ret)
+notmuch_bool_t create_new)
 {
 GError *error = NULL;
-int is_new = 0;
 size_t tmp;
 char *notmuch_config_env = NULL;
 int file_had_database_group;
@@ -245,9 +244,6 @@ notmuch_config_open (void *ctx,
 int file_had_maildir_group;
 int file_had_search_group;

-if (is_new_ret)
-   *is_new_ret = 0;
-
 notmuch_config_t *config = talloc (ctx, notmuch_config_t);
 if (config == NULL) {
fprintf (stderr, "Out of memory.\n");
@@ -286,17 +282,16 @@ notmuch_config_open (void *ctx,
 G_KEY_FILE_KEEP_COMMENTS,
 ))
 {
-   /* If the caller passed a non-NULL value for is_new_ret, then
-* the caller is prepared for a default configuration file in
-* the case of FILE NOT FOUND. Otherwise, any read failure is
-* an error.
+   /* If create_new is true, then the caller is prepared for a
+* default configuration file in the case of FILE NOT
+* FOUND. Otherwise, any read failure is an error.
 */
-   if (is_new_ret &&
+   if (create_new &&
error->domain == G_FILE_ERROR &&
error->code == G_FILE_ERROR_NOENT)
{
g_error_free (error);
-   is_new = 1;
+   config->is_new = TRUE;
}
else
{
@@ -379,7 +374,7 @@ notmuch_config_open (void *ctx,
 }

 if (notmuch_config_get_search_exclude_tags (config, ) == NULL) {
-   if (is_new) {
+   if (config->is_new) {
const char *tags[] = { "deleted", "spam" };
notmuch_config_set_search_exclude_tags (config, tags, 2);
} else {
@@ -399,7 +394,7 @@ notmuch_config_open (void *ctx,
 /* 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. */
-if (is_new)
+if (config->is_new)
 {
g_key_file_set_comment (config->key_file, NULL, NULL,
toplevel_config_comment, NULL);
@@ -434,11 +429,6 @@ notmuch_config_open (void *ctx,
search_config_comment, NULL);
 }

-if (is_new_ret)
-   *is_new_ret = is_new;
-
-config->is_new = is_new;
-
 return config;
 }

@@ -719,7 +709,7 @@ notmuch_config_command_get (void *ctx, char *item)
 {
 notmuch_config_t *config;

-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;

@@ -781,7 +771,7 @@ notmuch_config_command_set (void *ctx, char *item, int 
argc, char *argv[])
 if (_item_split (item, , ))
return 1;

-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;

@@ -818,7 +808,7 @@ notmuch_config_command_list (void *ctx)
 char **groups;
 size_t g, groups_length;

-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;

diff --git a/notmuch-count.c b/notmuch-count.c
index 2f98128..61722ed 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -62,7 +62,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
return 1;
 }

-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;

diff --git a/notmuch-dump.c b/notmuch-dump.c
index a3244e0..845a67e 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -34,7 +34,7 

[PATCH 1/6] cli: keep track of whether the config is newly created

2013-01-29 Thread Jani Nikula
Add notmuch_config_is_new() accessor function to check this.
---
 notmuch-client.h |3 +++
 notmuch-config.c |   11 +++
 2 files changed, 14 insertions(+)

diff --git a/notmuch-client.h b/notmuch-client.h
index 5f28836..07367e0 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -256,6 +256,9 @@ notmuch_config_close (notmuch_config_t *config);
 int
 notmuch_config_save (notmuch_config_t *config);

+notmuch_bool_t
+notmuch_config_is_new (notmuch_config_t *config);
+
 const char *
 notmuch_config_get_database_path (notmuch_config_t *config);

diff --git a/notmuch-config.c b/notmuch-config.c
index b5c2066..e733e92 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -104,6 +104,7 @@ static const char search_config_comment[] =
 struct _notmuch_config {
 char *filename;
 GKeyFile *key_file;
+notmuch_bool_t is_new;

 char *database_path;
 char *user_name;
@@ -266,6 +267,7 @@ notmuch_config_open (void *ctx,

 config->key_file = g_key_file_new ();

+config->is_new = FALSE;
 config->database_path = NULL;
 config->user_name = NULL;
 config->user_primary_email = NULL;
@@ -435,6 +437,8 @@ notmuch_config_open (void *ctx,
 if (is_new_ret)
*is_new_ret = is_new;

+config->is_new = is_new;
+
 return config;
 }

@@ -482,6 +486,13 @@ notmuch_config_save (notmuch_config_t *config)
 return 0;
 }

+notmuch_bool_t
+notmuch_config_is_new (notmuch_config_t *config)
+{
+return config->is_new;
+}
+
+
 static const char **
 _config_get_list (notmuch_config_t *config,
  const char *section, const char *key,
-- 
1.7.10.4



[PATCH 0/6] notmuch cli config changes

2013-01-29 Thread Jani Nikula
Hi all, the goal here is to add support for --config=FILE option at the
notmuch top level (e.g. 'notmuch --config=FILE search foo'). In order to
achieve this neatly, I ended up moving config open/close to main() from
subcommands. This isn't a bad thing, because all notmuch commands opened
the config file anyway.

As an added bonus, after this it should be trivial to 1) add top level
command line arguments to override config, or 2) add global command line
parameters passed on to subcommands via config (even if not stored in
the config file).

In the end this results in a net reduction of code.

BR,
Jani.


Jani Nikula (6):
  cli: keep track of whether the config is newly created
  cli: make notmuch_config_open() "is new" parameter input only
  cli: abstract subcommand finding into a new function
  cli: plug main notmuch command into subcommand machinery
  cli: move config open/close to main() from subcommands
  cli: add top level --config=FILE option

 notmuch-client.h |   35 ++---
 notmuch-config.c |   73 +-
 notmuch-count.c  |   11 ++--
 notmuch-dump.c   |7 +--
 notmuch-new.c|   17 +++
 notmuch-reply.c  |   15 ++
 notmuch-restore.c|   11 ++--
 notmuch-search.c |   15 ++
 notmuch-setup.c  |   22 
 notmuch-show.c   |   15 ++
 notmuch-tag.c|   15 ++
 notmuch.c|  138 +++---
 test/random-corpus.c |2 +-
 13 files changed, 159 insertions(+), 217 deletions(-)

-- 
1.7.10.4



[PATCH 2/2] NEWS: News for 0.15.2

2013-01-29 Thread da...@tethera.net
From: David Bremner 

Another couple of build fixes.
---
 NEWS |   14 ++
 1 file changed, 14 insertions(+)

diff --git a/NEWS b/NEWS
index 97f2305..3ba5a50 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,17 @@
+Notmuch 0.15.2 (2013-01-29)
+===
+
+Build fixes
+---
+
+Update dependencies to avoid problems when building in parallel.
+
+Internal test framework changes
+---
+
+Adjust Emacs test watchdog mechanism to cope with `process-attributes`
+being unimplimented.
+
 Notmuch 0.15.1 (2013-01-24)
 =

-- 
1.7.10.4



[PATCH 1/2] test: delay watchdog checks in emacs.

2013-01-29 Thread da...@tethera.net
From: David Bremner 

Instead of checking immediately for the watched process, delay a
minute, or in the case that process-attributes returns nil, for two
minutes.  This is intended to cope with the case that
process-attributes is unimplimented, and returns always returns nil.
In this case, the watchdog check is the same as the two minute limit
imposed by timeout.
---
 test/test-lib.el |   13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/test/test-lib.el b/test/test-lib.el
index dece811..d26b49f 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -77,12 +77,19 @@ invisible text."
(setq start next-pos)))
 str))

-(defun orphan-watchdog (pid)
+(defun orphan-watchdog-check (pid)
   "Periodically check that the process with id PID is still
 running, quit if it terminated."
   (if (not (process-attributes pid))
-  (kill-emacs)
-(run-at-time "1 min" nil 'orphan-watchdog pid)))
+  (kill-emacs)))
+
+(defun orphan-watchdog (pid)
+  "Initiate orphan watchdog check."
+  ; If process-attributes returns nil right away, that probably means
+  ; it is unimplimented. So we delay two minutes before killing emacs.
+  (if (process-attributes pid)
+  (run-at-time 60 60 'orphan-watchdog-check pid)
+(run-at-time 120 60 'orphan-watchdog-check pid)))

 (defun hook-counter (hook)
   "Count how many times a hook is called.  Increments
-- 
1.7.10.4



another bug fix release: 0.15.2, in progress.

2013-01-29 Thread da...@tethera.net
I plan to do another quick bug fix release, with aidecoe's parallel
build fix and a patch originally from Tomi to make the Emacs tests not
commit suicide right away on certain OSes.

I didn't include the parallel building patch here since it's already
in master.



[PATCH 1/2] man: document NOTMUCH_TALLOC_REPORT environment variable

2013-01-29 Thread David Bremner
Jameson Graef Rollins  writes:

>
> Not for this series, but it might be nice to document usage of the
> NOTMUCH_DEBUG_QUERY env var as well.
>

Not a bad idea. This should (also?) be documented in the library
documentation, since it is handled there, and also available e.g. to
bindings users.

d


minor fixes for talloc leak logging

2013-01-29 Thread Tomi Ollila
On Tue, Jan 29 2013, david at tethera.net wrote:

> These are the remaining unapplied patches from 
>
>   id:1358619958-21209-1-git-send-email-david at tethera.net
>
> They are rebased to omit the actual command line argument, as suggested by 
>
>  id:87d2wzwmd9.fsf at servo.finestructure.net


LGTM.

Tomi


It's good to be "back"!

2013-01-29 Thread Carl Worth
Elsewhere, in a non-hijacked thread, Carl Worth wrote:
> Is there any existing thread-breaking? There wasn't the last time I
> looked at the code closely, (but admittedly, that was a while ago).

Hi folks,

I've been away from any active involvement in the notmuch community for
far too long.

It turns out that even with an email system as sophisticated as notmuch,
it's possible to slip into bad habits that allow one to get behind with
email. So I got behind.

I also had some difficulty in accepting the fact that I wasn't able to
be as directly involved with notmuch as I was in the beginning. Early on
I would read every message sent to the list and try to ensure that every
question received at least some answer, (whether from me or for someone
else). But of course, I never succeeded at actually keeping up with
that, so my queues kept getting bigger and more intimidating, etc.

Anyway, it's been about 18 months since I've done anything real with
notmuch. I'm so delighted to see that the community that built up around
notmuch has been so independent, doing great things in my absence. I'm
excited to start looking close at the new features that I've not played
with (nmbug, date parsing, etc.), and maybe start implementing some of
those ancient features that I never got around to implementing in the
first place, (indexing of List-Id headers?).

So a huge thank you to all of you!

When I got over the psychological hurdles and decided to just archive
away the old, neglected mail queues, notmuch at least did make that
really easy. And I've now got an email workflow going really well for
me, that I think will be really useful. Notmuch allows the workflow
quite well, but doesn't guide me through it as smoothly as I would
like. More on that in a later message.

But for now, I should be reading the list much more regularly going
forward, and I'll be happy to have people CC me directly when they want
my particular attention for some specific reason.

And of course, all of the 12,000+ [*] messages I missed in the last
18 months[*] are still present in my archives. So new replies to old
messages might bring things to my attention. People can use that
intentionally if it will be useful.

I don't know how much code I'll be committing on a regular basis. But I
will definitely be "around" now much more.

Thanks again for all you've done over the last while. And thanks in
advance for what I know will be a warm welcome.

-Carl

[*] Hurrah for date searches! It's wonderful to have this feature!!
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20130129/3705c869/attachment.pgp>


Reply all - issue

2013-01-29 Thread Carl Worth
Robert Mast  writes:
> Your point on patch-breaking related to gmail and my proposal isn't
> completely clear to me, but I've probably addressed it well with my new
> approach.

The issue here is that many developers tend to develop a patch series
(perhaps with dozens of patches) as a single conceptual unit. When these
are emailed out, they are often sent as one thread with a new subject
for every patch. In particular, users of git and "git send-email" often
send patches this way. For what it's worth, it's my preferred way to
send and receive patches via email.

It's extremely useful for messages like this to be presented as a
single thread. This means that the dozens of messages don't clutter the
inbox, and it also allows for an operation to act on all of the messages
at once, (for example, notmuch provides "C-u |" which can apply all of
the received patches to a code repository in a single operation).

So, those of us accustomed to sending, receiving, reviewing, and
applying patches emailed in this way would be basically unable to use an
email program that split threads unconditionally on subject changes.

So it may be tricky to find a single behavior that would make everyone
happy. Perhaps a configuration option for splitting threads on subject
changes.

> I'll study the code for adding the option of unconditional (stripped)
> subject breaking on top of the existing thread-breaking.

Is there any existing thread-breaking? There wasn't the last time I
looked at the code closely, (but admittedly, that was a while ago).

-Carl

-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20130129/260dbc18/attachment.pgp>


[PATCH 1/2] man: document NOTMUCH_TALLOC_REPORT environment variable

2013-01-29 Thread Jameson Graef Rollins
On Tue, Jan 29 2013, david at tethera.net wrote:
> +.B NOTMUCH_TALLOC_REPORT
> +Location to write a talloc memory usage report. See
> +.B talloc_enable_leak_report_full
> +in \fBtalloc\fR(3)
> +for more information.

Not for this series, but it might be nice to document usage of the
NOTMUCH_DEBUG_QUERY env var as well.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20130129/fdfd19b8/attachment.pgp>


[PATCH 2/2] CLI: add simple error handling for talloc logging

2013-01-29 Thread da...@tethera.net
From: David Bremner 

This really should have been there before. I think it's better to do
the actual operation and then possibly fail writing the memory log,
but it would not be too hard to change it to abort earlier.
---
 notmuch.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index a674481..cfb009b 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -294,10 +294,6 @@ main (int argc, char *argv[])

ret = (command->function)(local, argc - opt_index, argv + 
opt_index);

-   /* in the future support for this environment variable may
-* be supplemented or replaced by command line arguments
-* --leak-report and/or --leak-report-full */
-
talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");

/* this relies on the previous call to
@@ -305,7 +301,13 @@ main (int argc, char *argv[])

if (talloc_report && strcmp (talloc_report, "") != 0) {
FILE *report = fopen (talloc_report, "w");
-   talloc_report_full (NULL, report);
+   if (report) {
+   talloc_report_full (NULL, report);
+   } else {
+   ret = 1;
+   fprintf (stderr, "ERROR: unable to write talloc log. ");
+   perror (talloc_report);
+   }
}

return ret;
-- 
1.7.10.4



[PATCH 1/2] man: document NOTMUCH_TALLOC_REPORT environment variable

2013-01-29 Thread da...@tethera.net
From: David Bremner 

---
 man/man1/notmuch.1 |8 
 1 file changed, 8 insertions(+)

diff --git a/man/man1/notmuch.1 b/man/man1/notmuch.1
index 0805be8..55e2d16 100644
--- a/man/man1/notmuch.1
+++ b/man/man1/notmuch.1
@@ -147,6 +147,14 @@ behavior of notmuch.
 .B NOTMUCH_CONFIG
 Specifies the location of the notmuch configuration file. Notmuch will
 use ${HOME}/.notmuch\-config if this variable is not set.
+
+.TP
+.B NOTMUCH_TALLOC_REPORT
+Location to write a talloc memory usage report. See
+.B talloc_enable_leak_report_full
+in \fBtalloc\fR(3)
+for more information.
+
 .SH SEE ALSO

 \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-- 
1.7.10.4



minor fixes for talloc leak logging

2013-01-29 Thread da...@tethera.net
These are the remaining unapplied patches from 

  id:1358619958-21209-1-git-send-email-david at tethera.net

They are rebased to omit the actual command line argument, as suggested by 

 id:87d2wzwmd9.fsf at servo.finestructure.net



[PATCH 2/2] CLI: add simple error handling for talloc logging

2013-01-29 Thread david
From: David Bremner brem...@debian.org

This really should have been there before. I think it's better to do
the actual operation and then possibly fail writing the memory log,
but it would not be too hard to change it to abort earlier.
---
 notmuch.c |   12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index a674481..cfb009b 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -294,10 +294,6 @@ main (int argc, char *argv[])
 
ret = (command-function)(local, argc - opt_index, argv + 
opt_index);
 
-   /* in the future support for this environment variable may
-* be supplemented or replaced by command line arguments
-* --leak-report and/or --leak-report-full */
-
talloc_report = getenv (NOTMUCH_TALLOC_REPORT);
 
/* this relies on the previous call to
@@ -305,7 +301,13 @@ main (int argc, char *argv[])
 
if (talloc_report  strcmp (talloc_report, ) != 0) {
FILE *report = fopen (talloc_report, w);
-   talloc_report_full (NULL, report);
+   if (report) {
+   talloc_report_full (NULL, report);
+   } else {
+   ret = 1;
+   fprintf (stderr, ERROR: unable to write talloc log. );
+   perror (talloc_report);
+   }
}
 
return ret;
-- 
1.7.10.4

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


Re: minor fixes for talloc leak logging

2013-01-29 Thread Tomi Ollila
On Tue, Jan 29 2013, da...@tethera.net wrote:

 These are the remaining unapplied patches from 

   id:1358619958-21209-1-git-send-email-da...@tethera.net

 They are rebased to omit the actual command line argument, as suggested by 

  id:87d2wzwmd9@servo.finestructure.net


LGTM.

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


Re: [PATCH 1/2] man: document NOTMUCH_TALLOC_REPORT environment variable

2013-01-29 Thread Jameson Graef Rollins
On Tue, Jan 29 2013, da...@tethera.net wrote:
 +.B NOTMUCH_TALLOC_REPORT
 +Location to write a talloc memory usage report. See
 +.B talloc_enable_leak_report_full
 +in \fBtalloc\fR(3)
 +for more information.

Not for this series, but it might be nice to document usage of the
NOTMUCH_DEBUG_QUERY env var as well.

jamie.


pgpz6xHKAlY8m.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/2] man: document NOTMUCH_TALLOC_REPORT environment variable

2013-01-29 Thread David Bremner
Jameson Graef Rollins jroll...@finestructure.net writes:


 Not for this series, but it might be nice to document usage of the
 NOTMUCH_DEBUG_QUERY env var as well.


Not a bad idea. This should (also?) be documented in the library
documentation, since it is handled there, and also available e.g. to
bindings users.

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


[PATCH 0/6] notmuch cli config changes

2013-01-29 Thread Jani Nikula
Hi all, the goal here is to add support for --config=FILE option at the
notmuch top level (e.g. 'notmuch --config=FILE search foo'). In order to
achieve this neatly, I ended up moving config open/close to main() from
subcommands. This isn't a bad thing, because all notmuch commands opened
the config file anyway.

As an added bonus, after this it should be trivial to 1) add top level
command line arguments to override config, or 2) add global command line
parameters passed on to subcommands via config (even if not stored in
the config file).

In the end this results in a net reduction of code.

BR,
Jani.


Jani Nikula (6):
  cli: keep track of whether the config is newly created
  cli: make notmuch_config_open() is new parameter input only
  cli: abstract subcommand finding into a new function
  cli: plug main notmuch command into subcommand machinery
  cli: move config open/close to main() from subcommands
  cli: add top level --config=FILE option

 notmuch-client.h |   35 ++---
 notmuch-config.c |   73 +-
 notmuch-count.c  |   11 ++--
 notmuch-dump.c   |7 +--
 notmuch-new.c|   17 +++
 notmuch-reply.c  |   15 ++
 notmuch-restore.c|   11 ++--
 notmuch-search.c |   15 ++
 notmuch-setup.c  |   22 
 notmuch-show.c   |   15 ++
 notmuch-tag.c|   15 ++
 notmuch.c|  138 +++---
 test/random-corpus.c |2 +-
 13 files changed, 159 insertions(+), 217 deletions(-)

-- 
1.7.10.4

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


[PATCH 1/6] cli: keep track of whether the config is newly created

2013-01-29 Thread Jani Nikula
Add notmuch_config_is_new() accessor function to check this.
---
 notmuch-client.h |3 +++
 notmuch-config.c |   11 +++
 2 files changed, 14 insertions(+)

diff --git a/notmuch-client.h b/notmuch-client.h
index 5f28836..07367e0 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -256,6 +256,9 @@ notmuch_config_close (notmuch_config_t *config);
 int
 notmuch_config_save (notmuch_config_t *config);
 
+notmuch_bool_t
+notmuch_config_is_new (notmuch_config_t *config);
+
 const char *
 notmuch_config_get_database_path (notmuch_config_t *config);
 
diff --git a/notmuch-config.c b/notmuch-config.c
index b5c2066..e733e92 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -104,6 +104,7 @@ static const char search_config_comment[] =
 struct _notmuch_config {
 char *filename;
 GKeyFile *key_file;
+notmuch_bool_t is_new;
 
 char *database_path;
 char *user_name;
@@ -266,6 +267,7 @@ notmuch_config_open (void *ctx,
 
 config-key_file = g_key_file_new ();
 
+config-is_new = FALSE;
 config-database_path = NULL;
 config-user_name = NULL;
 config-user_primary_email = NULL;
@@ -435,6 +437,8 @@ notmuch_config_open (void *ctx,
 if (is_new_ret)
*is_new_ret = is_new;
 
+config-is_new = is_new;
+
 return config;
 }
 
@@ -482,6 +486,13 @@ notmuch_config_save (notmuch_config_t *config)
 return 0;
 }
 
+notmuch_bool_t
+notmuch_config_is_new (notmuch_config_t *config)
+{
+return config-is_new;
+}
+
+
 static const char **
 _config_get_list (notmuch_config_t *config,
  const char *section, const char *key,
-- 
1.7.10.4

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


[PATCH 2/6] cli: make notmuch_config_open() is new parameter input only

2013-01-29 Thread Jani Nikula
Use the notmuch_config_is_new() function instead.
---
 notmuch-client.h |2 +-
 notmuch-config.c |   32 +++-
 notmuch-count.c  |2 +-
 notmuch-dump.c   |2 +-
 notmuch-new.c|2 +-
 notmuch-reply.c  |2 +-
 notmuch-restore.c|2 +-
 notmuch-search.c |2 +-
 notmuch-setup.c  |7 +++
 notmuch-show.c   |2 +-
 notmuch-tag.c|2 +-
 notmuch.c|5 ++---
 test/random-corpus.c |2 +-
 13 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index 07367e0..b3dcb21 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -248,7 +248,7 @@ typedef struct _notmuch_config notmuch_config_t;
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
-notmuch_bool_t *is_new_ret);
+notmuch_bool_t create_new);
 
 void
 notmuch_config_close (notmuch_config_t *config);
diff --git a/notmuch-config.c b/notmuch-config.c
index e733e92..247fbe4 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -233,10 +233,9 @@ get_username_from_passwd_file (void *ctx)
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
-notmuch_bool_t *is_new_ret)
+notmuch_bool_t create_new)
 {
 GError *error = NULL;
-int is_new = 0;
 size_t tmp;
 char *notmuch_config_env = NULL;
 int file_had_database_group;
@@ -245,9 +244,6 @@ notmuch_config_open (void *ctx,
 int file_had_maildir_group;
 int file_had_search_group;
 
-if (is_new_ret)
-   *is_new_ret = 0;
-
 notmuch_config_t *config = talloc (ctx, notmuch_config_t);
 if (config == NULL) {
fprintf (stderr, Out of memory.\n);
@@ -286,17 +282,16 @@ notmuch_config_open (void *ctx,
 G_KEY_FILE_KEEP_COMMENTS,
 error))
 {
-   /* If the caller passed a non-NULL value for is_new_ret, then
-* the caller is prepared for a default configuration file in
-* the case of FILE NOT FOUND. Otherwise, any read failure is
-* an error.
+   /* If create_new is true, then the caller is prepared for a
+* default configuration file in the case of FILE NOT
+* FOUND. Otherwise, any read failure is an error.
 */
-   if (is_new_ret 
+   if (create_new 
error-domain == G_FILE_ERROR 
error-code == G_FILE_ERROR_NOENT)
{
g_error_free (error);
-   is_new = 1;
+   config-is_new = TRUE;
}
else
{
@@ -379,7 +374,7 @@ notmuch_config_open (void *ctx,
 }
 
 if (notmuch_config_get_search_exclude_tags (config, tmp) == NULL) {
-   if (is_new) {
+   if (config-is_new) {
const char *tags[] = { deleted, spam };
notmuch_config_set_search_exclude_tags (config, tags, 2);
} else {
@@ -399,7 +394,7 @@ notmuch_config_open (void *ctx,
 /* 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. */
-if (is_new)
+if (config-is_new)
 {
g_key_file_set_comment (config-key_file, NULL, NULL,
toplevel_config_comment, NULL);
@@ -434,11 +429,6 @@ notmuch_config_open (void *ctx,
search_config_comment, NULL);
 }
 
-if (is_new_ret)
-   *is_new_ret = is_new;
-
-config-is_new = is_new;
-
 return config;
 }
 
@@ -719,7 +709,7 @@ notmuch_config_command_get (void *ctx, char *item)
 {
 notmuch_config_t *config;
 
-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;
 
@@ -781,7 +771,7 @@ notmuch_config_command_set (void *ctx, char *item, int 
argc, char *argv[])
 if (_item_split (item, group, key))
return 1;
 
-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;
 
@@ -818,7 +808,7 @@ notmuch_config_command_list (void *ctx)
 char **groups;
 size_t g, groups_length;
 
-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;
 
diff --git a/notmuch-count.c b/notmuch-count.c
index 2f98128..61722ed 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -62,7 +62,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
return 1;
 }
 
-config = notmuch_config_open (ctx, NULL, NULL);
+config = notmuch_config_open (ctx, NULL, FALSE);
 if (config == NULL)
return 1;
 
diff --git a/notmuch-dump.c b/notmuch-dump.c
index a3244e0..845a67e 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ 

[PATCH 3/6] cli: abstract subcommand finding into a new function

2013-01-29 Thread Jani Nikula
Clean up code.
---
 notmuch.c |   68 +++--
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index b413b53..c47b998 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -70,6 +70,18 @@ static command_t commands[] = {
   This message, or more detailed help for the named command. }
 };
 
+static command_t *
+find_command (const char *name)
+{
+size_t i;
+
+for (i = 0; i  ARRAY_SIZE (commands); i++)
+   if (strcmp (name, commands[i].name) == 0)
+   return commands[i];
+
+return NULL;
+}
+
 int notmuch_format_version;
 
 static void
@@ -139,7 +151,6 @@ static int
 notmuch_help_command (void *ctx, int argc, char *argv[])
 {
 command_t *command;
-unsigned int i;
 
 argc--; argv++; /* Ignore help */
 
@@ -158,13 +169,10 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
return 0;
 }
 
-for (i = 0; i  ARRAY_SIZE (commands); i++) {
-   command = commands[i];
-
-   if (strcmp (argv[0], command-name) == 0) {
-   char *page = talloc_asprintf (ctx, notmuch-%s, command-name);
-   exec_man (page);
-   }
+command = find_command (argv[0]);
+if (command) {
+   char *page = talloc_asprintf (ctx, notmuch-%s, command-name);
+   exec_man (page);
 }
 
 if (strcmp (argv[0], search-terms) == 0) {
@@ -246,10 +254,11 @@ int
 main (int argc, char *argv[])
 {
 void *local;
+char *talloc_report;
 command_t *command;
-unsigned int i;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
+int ret = 0;
 
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_BOOLEAN, print_help, help, 'h', 0 },
@@ -284,37 +293,30 @@ main (int argc, char *argv[])
return 0;
 }
 
-for (i = 0; i  ARRAY_SIZE (commands); i++) {
-   command = commands[i];
-
-   if (strcmp (argv[opt_index], command-name) == 0) {
-   int ret;
-   char *talloc_report;
-
-   ret = (command-function)(local, argc - opt_index, argv + 
opt_index);
+command = find_command (argv[opt_index]);
+if (!command) {
+   fprintf (stderr, Error: Unknown command '%s' (see \notmuch help\)\n,
+argv[opt_index]);
+   return 1;
+}
 
-   /* in the future support for this environment variable may
-* be supplemented or replaced by command line arguments
-* --leak-report and/or --leak-report-full */
+ret = (command-function)(local, argc - opt_index, argv + opt_index);
 
-   talloc_report = getenv (NOTMUCH_TALLOC_REPORT);
+/* in the future support for this environment variable may
+ * be supplemented or replaced by command line arguments
+ * --leak-report and/or --leak-report-full */
 
-   /* this relies on the previous call to
-* talloc_enable_null_tracking */
+talloc_report = getenv (NOTMUCH_TALLOC_REPORT);
 
-   if (talloc_report  strcmp (talloc_report, ) != 0) {
-   FILE *report = fopen (talloc_report, w);
-   talloc_report_full (NULL, report);
-   }
+/* this relies on the previous call to
+ * talloc_enable_null_tracking */
 
-   return ret;
-   }
+if (talloc_report  strcmp (talloc_report, ) != 0) {
+   FILE *report = fopen (talloc_report, w);
+   talloc_report_full (NULL, report);
 }
 
-fprintf (stderr, Error: Unknown command '%s' (see \notmuch help\)\n,
-argv[1]);
-
 talloc_free (local);
 
-return 1;
+return ret;
 }
-- 
1.7.10.4

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


[PATCH 4/6] cli: plug main notmuch command into subcommand machinery

2013-01-29 Thread Jani Nikula
This also allows the main notmuch command to have arguments (though
they are not used).
---
 notmuch.c |   26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/notmuch.c b/notmuch.c
index c47b998..67d5772 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -34,7 +34,13 @@ typedef struct command {
 static int
 notmuch_help_command (void *ctx, int argc, char *argv[]);
 
+static int
+notmuch_command (void *ctx, int argc, char *argv[]);
+
 static command_t commands[] = {
+{ NULL, notmuch_command,
+  NULL,
+  Notmuch main command. },
 { setup, notmuch_setup_command,
   NULL,
   Interactively setup notmuch for first use. },
@@ -76,7 +82,8 @@ find_command (const char *name)
 size_t i;
 
 for (i = 0; i  ARRAY_SIZE (commands); i++)
-   if (strcmp (name, commands[i].name) == 0)
+   if ((!name  !commands[i].name) ||
+   (name  commands[i].name  strcmp (name, commands[i].name) == 0))
return commands[i];
 
 return NULL;
@@ -101,8 +108,8 @@ usage (FILE *out)
 for (i = 0; i  ARRAY_SIZE (commands); i++) {
command = commands[i];
 
-   fprintf (out,   %-11s  %s\n,
-command-name, command-summary);
+   if (command-name)
+   fprintf (out,   %-11s  %s\n, command-name, command-summary);
 }
 
 fprintf (out, \n);
@@ -192,7 +199,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
  * to be more clever about this in the future.
  */
 static int
-notmuch (void *ctx)
+notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))
 {
 notmuch_config_t *config;
 char *db_path;
@@ -255,6 +262,7 @@ main (int argc, char *argv[])
 {
 void *local;
 char *talloc_report;
+const char *command_name = NULL;
 command_t *command;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -276,9 +284,6 @@ main (int argc, char *argv[])
 /* Globally default to the current output format version. */
 notmuch_format_version = NOTMUCH_FORMAT_CUR;
 
-if (argc == 1)
-   return notmuch (local);
-
 opt_index = parse_arguments (argc, argv, options, 1);
 if (opt_index  0) {
/* diagnostics already printed */
@@ -293,10 +298,13 @@ main (int argc, char *argv[])
return 0;
 }
 
-command = find_command (argv[opt_index]);
+if (opt_index  argc)
+   command_name = argv[opt_index];
+
+command = find_command (command_name);
 if (!command) {
fprintf (stderr, Error: Unknown command '%s' (see \notmuch help\)\n,
-argv[opt_index]);
+command_name);
return 1;
 }
 
-- 
1.7.10.4

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


[PATCH 6/6] cli: add top level --config=FILE option

2013-01-29 Thread Jani Nikula
Let the user specify the config file on the command line.
---
 notmuch.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/notmuch.c b/notmuch.c
index f4bfeaa..71cd0d6 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -258,6 +258,7 @@ main (int argc, char *argv[])
 char *talloc_report;
 const char *command_name = NULL;
 command_t *command;
+char *config_file_name = NULL;
 notmuch_config_t *config;
 notmuch_bool_t print_help=FALSE, print_version=FALSE;
 int opt_index;
@@ -266,6 +267,7 @@ main (int argc, char *argv[])
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_BOOLEAN, print_help, help, 'h', 0 },
{ NOTMUCH_OPT_BOOLEAN, print_version, version, 'v', 0 },
+   { NOTMUCH_OPT_STRING, config_file_name, config, 'c', 0 },
{ 0, 0, 0, 0, 0 }
 };
 
@@ -303,7 +305,7 @@ main (int argc, char *argv[])
return 1;
 }
 
-config = notmuch_config_open (local, NULL, command-create_config);
+config = notmuch_config_open (local, config_file_name, 
command-create_config);
 if (!config)
return 1;
 
-- 
1.7.10.4

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


[PATCH 5/6] cli: move config open/close to main() from subcommands

2013-01-29 Thread Jani Nikula
This allows specifying config file as a top level argument to notmuch,
and generally makes it possible to override config file options in
main(), without having to touch the subcommands.

This also makes notmuch config the talloc context for subcommands.
---
 notmuch-client.h  |   30 +++---
 notmuch-config.c  |   40 +++
 notmuch-count.c   |   11 +++---
 notmuch-dump.c|7 +-
 notmuch-new.c |   17 ++-
 notmuch-reply.c   |   15 +
 notmuch-restore.c |   11 +++---
 notmuch-search.c  |   15 +
 notmuch-setup.c   |   17 ++-
 notmuch-show.c|   15 +
 notmuch-tag.c |   15 +
 notmuch.c |   61 +++--
 12 files changed, 91 insertions(+), 163 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index b3dcb21..45749a6 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -150,6 +150,8 @@ chomp_newline (char *str)
  */
 extern int notmuch_format_version;
 
+typedef struct _notmuch_config notmuch_config_t;
+
 /* Commands that support structured output should support the
  * following argument
  *  { NOTMUCH_OPT_INT, notmuch_format_version, format-version, 0, 0 }
@@ -169,40 +171,34 @@ int
 notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
 
 int
-notmuch_count_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_dump_command (void *ctx, int argc, char *argv[]);
+notmuch_count_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_new_command (void *ctx, int argc, char *argv[]);
+notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_reply_command (void *ctx, int argc, char *argv[]);
+notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_restore_command (void *ctx, int argc, char *argv[]);
+notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_search_command (void *ctx, int argc, char *argv[]);
+notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_setup_command (void *ctx, int argc, char *argv[]);
+notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_show_command (void *ctx, int argc, char *argv[]);
+notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_tag_command (void *ctx, int argc, char *argv[]);
+notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
+notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);
 
 int
-notmuch_cat_command (void *ctx, int argc, char *argv[]);
-
-int
-notmuch_config_command (void *ctx, int argc, char *argv[]);
+notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);
 
 const char *
 notmuch_time_relative_date (const void *ctx, time_t then);
@@ -243,8 +239,6 @@ json_quote_str (const void *ctx, const char *str);
 
 /* notmuch-config.c */
 
-typedef struct _notmuch_config notmuch_config_t;
-
 notmuch_config_t *
 notmuch_config_open (void *ctx,
 const char *filename,
diff --git a/notmuch-config.c b/notmuch-config.c
index 247fbe4..48312e3 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -705,14 +705,8 @@ _item_split (char *item, char **group, char **key)
 }
 
 static int
-notmuch_config_command_get (void *ctx, char *item)
+notmuch_config_command_get (notmuch_config_t *config, char *item)
 {
-notmuch_config_t *config;
-
-config = notmuch_config_open (ctx, NULL, FALSE);
-if (config == NULL)
-   return 1;
-
 if (strcmp(item, database.path) == 0) {
printf (%s\n, notmuch_config_get_database_path (config));
 } else if (strcmp(item, user.name) == 0) {
@@ -756,25 +750,17 @@ notmuch_config_command_get (void *ctx, char *item)
g_strfreev (value);
 }
 
-notmuch_config_close (config);
-
 return 0;
 }
 
 static int
-notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[])
+notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, 
char *argv[])
 {
-notmuch_config_t *config;
 char *group, *key;
-int ret;
 
 if (_item_split (item, group, key))
return 1;
 
-config = notmuch_config_open (ctx, NULL, FALSE);
-if (config == NULL)
-   return 1;
-
 /* With only the name of an item, we clear it from the
  * configuration file.
  *
@@ -795,23 +781,15 @@ notmuch_config_command_set (void *ctx, char *item, int 
argc, char *argv[])
break;
 }
 
-ret = notmuch_config_save (config);
-notmuch_config_close (config);
-
-return ret;
+return notmuch_config_save (config);
 }
 
 static int
-notmuch_config_command_list (void *ctx)
+notmuch_config_command_list (notmuch_config_t *config)
 {
-notmuch_config_t *config;
 char **groups;
 size_t g, 

[PATCH 1/2] test: delay watchdog checks in emacs.

2013-01-29 Thread david
From: David Bremner brem...@debian.org

Instead of checking immediately for the watched process, delay a
minute, or in the case that process-attributes returns nil, for two
minutes.  This is intended to cope with the case that
process-attributes is unimplimented, and returns always returns nil.
In this case, the watchdog check is the same as the two minute limit
imposed by timeout.
---
 test/test-lib.el |   13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/test/test-lib.el b/test/test-lib.el
index dece811..d26b49f 100644
--- a/test/test-lib.el
+++ b/test/test-lib.el
@@ -77,12 +77,19 @@ invisible text.
(setq start next-pos)))
 str))
 
-(defun orphan-watchdog (pid)
+(defun orphan-watchdog-check (pid)
   Periodically check that the process with id PID is still
 running, quit if it terminated.
   (if (not (process-attributes pid))
-  (kill-emacs)
-(run-at-time 1 min nil 'orphan-watchdog pid)))
+  (kill-emacs)))
+
+(defun orphan-watchdog (pid)
+  Initiate orphan watchdog check.
+  ; If process-attributes returns nil right away, that probably means
+  ; it is unimplimented. So we delay two minutes before killing emacs.
+  (if (process-attributes pid)
+  (run-at-time 60 60 'orphan-watchdog-check pid)
+(run-at-time 120 60 'orphan-watchdog-check pid)))
 
 (defun hook-counter (hook)
   Count how many times a hook is called.  Increments
-- 
1.7.10.4

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


[PATCH 2/2] NEWS: News for 0.15.2

2013-01-29 Thread david
From: David Bremner brem...@debian.org

Another couple of build fixes.
---
 NEWS |   14 ++
 1 file changed, 14 insertions(+)

diff --git a/NEWS b/NEWS
index 97f2305..3ba5a50 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,17 @@
+Notmuch 0.15.2 (2013-01-29)
+===
+
+Build fixes
+---
+
+Update dependencies to avoid problems when building in parallel.
+
+Internal test framework changes
+---
+
+Adjust Emacs test watchdog mechanism to cope with `process-attributes`
+being unimplimented.
+
 Notmuch 0.15.1 (2013-01-24)
 =
 
-- 
1.7.10.4

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


another bug fix release: 0.15.2, in progress.

2013-01-29 Thread david
I plan to do another quick bug fix release, with aidecoe's parallel
build fix and a patch originally from Tomi to make the Emacs tests not
commit suicide right away on certain OSes.

I didn't include the parallel building patch here since it's already
in master.

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


Re: another bug fix release: 0.15.2, in progress.

2013-01-29 Thread Tomi Ollila
On Wed, Jan 30 2013, da...@tethera.net wrote:

 I plan to do another quick bug fix release, with aidecoe's parallel
 build fix and a patch originally from Tomi to make the Emacs tests not
 commit suicide right away on certain OSes.

LGTM.

 I didn't include the parallel building patch here since it's already
 in master.

(moved lgtm up for obvious reasons ;)

Tomi

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