[PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-30 Thread Jani Nikula
On Tue, 26 Mar 2013, Jani Nikula  wrote:
> On Thu, 21 Mar 2013, Jameson Graef Rollins  
> wrote:
>> On Sat, Mar 09 2013, Jani Nikula  wrote:
>>> Add support for reading queries from stdin, one per line, and writing
>>> results to stdin, one per line.
>>
>> I assume this is meant to be "to stdout".
>
> Oops, I got that comment the last time too. :(

BTW just to be clear, I'm not sending another version of this patch
(series) just to fix this mistake; I'll wait for more review
comments. (And if all looks good and David is in a good mood, perhaps he
can tweak the commit message. ;)

BR,
Jani.


Re: [PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-30 Thread Jani Nikula
On Tue, 26 Mar 2013, Jani Nikula j...@nikula.org wrote:
 On Thu, 21 Mar 2013, Jameson Graef Rollins jroll...@finestructure.net wrote:
 On Sat, Mar 09 2013, Jani Nikula j...@nikula.org wrote:
 Add support for reading queries from stdin, one per line, and writing
 results to stdin, one per line.

 I assume this is meant to be to stdout.

 Oops, I got that comment the last time too. :(

BTW just to be clear, I'm not sending another version of this patch
(series) just to fix this mistake; I'll wait for more review
comments. (And if all looks good and David is in a good mood, perhaps he
can tweak the commit message. ;)

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


[PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-26 Thread Jani Nikula
On Thu, 21 Mar 2013, Jameson Graef Rollins  
wrote:
> On Sat, Mar 09 2013, Jani Nikula  wrote:
>> Add support for reading queries from stdin, one per line, and writing
>> results to stdin, one per line.
>
> I assume this is meant to be "to stdout".

Oops, I got that comment the last time too. :(

BR,
Jani.


Re: [PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-26 Thread Jani Nikula
On Thu, 21 Mar 2013, Jameson Graef Rollins jroll...@finestructure.net wrote:
 On Sat, Mar 09 2013, Jani Nikula j...@nikula.org wrote:
 Add support for reading queries from stdin, one per line, and writing
 results to stdin, one per line.

 I assume this is meant to be to stdout.

Oops, I got that comment the last time too. :(

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


[PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-21 Thread Jameson Graef Rollins
On Sat, Mar 09 2013, Jani Nikula  wrote:
> Add support for reading queries from stdin, one per line, and writing
> results to stdin, one per line.

I assume this is meant to be "to stdout".

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Re: [PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-21 Thread Jameson Graef Rollins
On Sat, Mar 09 2013, Jani Nikula j...@nikula.org wrote:
 Add support for reading queries from stdin, one per line, and writing
 results to stdin, one per line.

I assume this is meant to be to stdout.

jamie.


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


[PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-09 Thread Jani Nikula
Add support for reading queries from stdin, one per line, and writing
results to stdin, one per line.

This will bring considerable performance improvements when utilized in
Emacs notmuch-hello, especially so when running remote notmuch.
---
 notmuch-count.c |   52 ++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index 630f036..8772cff 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 return 0;
 }

+static int
+count_file (notmuch_database_t *notmuch, FILE *input, const char 
**exclude_tags,
+   size_t exclude_tags_length, int output)
+{
+char *line = NULL;
+ssize_t line_len;
+size_t line_size;
+int ret = 0;
+
+while (!ret && (line_len = getline (, _size, input)) != -1) {
+   chomp_newline (line);
+   ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
+  output);
+}
+
+if (line)
+   free (line);
+
+return ret;
+}
+
 int
 notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
 {
@@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
 int exclude = EXCLUDE_TRUE;
 const char **search_exclude_tags = NULL;
 size_t search_exclude_tags_length = 0;
+notmuch_bool_t batch = FALSE;
+FILE *input = stdin;
+char *input_file_name = NULL;
 int ret;

 notmuch_opt_desc_t options[] = {
@@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
  (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE },
  { "false", EXCLUDE_FALSE },
  { 0, 0 } } },
+   { NOTMUCH_OPT_BOOLEAN, , "batch", 0, 0 },
+   { NOTMUCH_OPT_STRING, _file_name, "input", 'i', 0 },
{ 0, 0, 0, 0, 0 }
 };

@@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
return 1;
 }

+if (input_file_name) {
+   batch = TRUE;
+   input = fopen (input_file_name, "r");
+   if (input == NULL) {
+   fprintf (stderr, "Error opening %s for reading: %s\n",
+input_file_name, strerror (errno));
+   return 1;
+   }
+}
+
+if (batch && opt_index != argc) {
+   fprintf (stderr, "--batch and query string are not compatible\n");
+   return 1;
+}
+
 if (notmuch_database_open (notmuch_config_get_database_path (config),
   NOTMUCH_DATABASE_MODE_READ_ONLY, ))
return 1;
@@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int 
argc, char *argv[])
(config, _exclude_tags_length);
 }

-ret = print_count (notmuch, query_str, search_exclude_tags,
-  search_exclude_tags_length, output);
+if (batch)
+   ret = count_file (notmuch, input, search_exclude_tags,
+ search_exclude_tags_length, output);
+else
+   ret = print_count (notmuch, query_str, search_exclude_tags,
+  search_exclude_tags_length, output);

 notmuch_database_destroy (notmuch);

+if (input != stdin)
+   fclose (input);
+
 return ret;
 }
-- 
1.7.10.4



[PATCH v2 3/6] cli: add --batch option to notmuch count

2013-03-09 Thread Jani Nikula
Add support for reading queries from stdin, one per line, and writing
results to stdin, one per line.

This will bring considerable performance improvements when utilized in
Emacs notmuch-hello, especially so when running remote notmuch.
---
 notmuch-count.c |   52 ++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/notmuch-count.c b/notmuch-count.c
index 630f036..8772cff 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -62,6 +62,27 @@ print_count (notmuch_database_t *notmuch, const char 
*query_str,
 return 0;
 }
 
+static int
+count_file (notmuch_database_t *notmuch, FILE *input, const char 
**exclude_tags,
+   size_t exclude_tags_length, int output)
+{
+char *line = NULL;
+ssize_t line_len;
+size_t line_size;
+int ret = 0;
+
+while (!ret  (line_len = getline (line, line_size, input)) != -1) {
+   chomp_newline (line);
+   ret = print_count (notmuch, line, exclude_tags, exclude_tags_length,
+  output);
+}
+
+if (line)
+   free (line);
+
+return ret;
+}
+
 int
 notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
 {
@@ -72,6 +93,9 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
 int exclude = EXCLUDE_TRUE;
 const char **search_exclude_tags = NULL;
 size_t search_exclude_tags_length = 0;
+notmuch_bool_t batch = FALSE;
+FILE *input = stdin;
+char *input_file_name = NULL;
 int ret;
 
 notmuch_opt_desc_t options[] = {
@@ -83,6 +107,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
  (notmuch_keyword_t []){ { true, EXCLUDE_TRUE },
  { false, EXCLUDE_FALSE },
  { 0, 0 } } },
+   { NOTMUCH_OPT_BOOLEAN, batch, batch, 0, 0 },
+   { NOTMUCH_OPT_STRING, input_file_name, input, 'i', 0 },
{ 0, 0, 0, 0, 0 }
 };
 
@@ -92,6 +118,21 @@ notmuch_count_command (notmuch_config_t *config, int argc, 
char *argv[])
return 1;
 }
 
+if (input_file_name) {
+   batch = TRUE;
+   input = fopen (input_file_name, r);
+   if (input == NULL) {
+   fprintf (stderr, Error opening %s for reading: %s\n,
+input_file_name, strerror (errno));
+   return 1;
+   }
+}
+
+if (batch  opt_index != argc) {
+   fprintf (stderr, --batch and query string are not compatible\n);
+   return 1;
+}
+
 if (notmuch_database_open (notmuch_config_get_database_path (config),
   NOTMUCH_DATABASE_MODE_READ_ONLY, notmuch))
return 1;
@@ -107,10 +148,17 @@ notmuch_count_command (notmuch_config_t *config, int 
argc, char *argv[])
(config, search_exclude_tags_length);
 }
 
-ret = print_count (notmuch, query_str, search_exclude_tags,
-  search_exclude_tags_length, output);
+if (batch)
+   ret = count_file (notmuch, input, search_exclude_tags,
+ search_exclude_tags_length, output);
+else
+   ret = print_count (notmuch, query_str, search_exclude_tags,
+  search_exclude_tags_length, output);
 
 notmuch_database_destroy (notmuch);
 
+if (input != stdin)
+   fclose (input);
+
 return ret;
 }
-- 
1.7.10.4

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