[notmuch] [PATCH 4/4] notmuch-new: New cmdline option --tag=.

2009-11-25 Thread Jan Janak
Hi Karl,

On Wed, Nov 25, 2009 at 7:21 AM, Karl Wiberg  wrote:
> On Tue, Nov 24, 2009 at 11:10 PM, Jan Janak  wrote:
>> The list of tags to be applied by 'notmuch new' can be configured in
>> the configuration file. This command line option can be used to
>> override the list of tags from the coonfiguration file on the command
>> line. You may repeat the option several times if you want to apply
>> more than one tag:
>>
>> ?notmuch new --tag=apple --tag=orange
>
> This leaves no way to skip the tags in the config file without adding
> at least one tag on the command line, right?

Right.

> It might be more flexible
> to e.g. have the commandline tags applied in _addition_ to the tags in
> the config, and have a --no-config-tags flag to skip the tags in the
> config when desired.

Yeah, I think that's a very good idea. I'll submit another patch for
that. Thanks for the suggestion!

  -- Jan


[notmuch] [PATCH 4/4] notmuch-new: New cmdline option --tag=.

2009-11-25 Thread Karl Wiberg
On Tue, Nov 24, 2009 at 11:10 PM, Jan Janak  wrote:
> The list of tags to be applied by 'notmuch new' can be configured in
> the configuration file. This command line option can be used to
> override the list of tags from the coonfiguration file on the command
> line. You may repeat the option several times if you want to apply
> more than one tag:
>
> ?notmuch new --tag=apple --tag=orange

This leaves no way to skip the tags in the config file without adding
at least one tag on the command line, right? It might be more flexible
to e.g. have the commandline tags applied in _addition_ to the tags in
the config, and have a --no-config-tags flag to skip the tags in the
config when desired. Or, if that seems more convenient, have a
--config-tags=yes|no flag that defaults to yes when no --tag is given,
and to no when at least one --tag is given.

-- 
Karl Wiberg, kha at treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle


[notmuch] [PATCH 4/4] notmuch-new: New cmdline option --tag=.

2009-11-24 Thread Jan Janak
The list of tags to be applied by 'notmuch new' can be configured in
the configuration file. This command line option can be used to
override the list of tags from the coonfiguration file on the command
line. You may repeat the option several times if you want to apply
more than one tag:

  notmuch new --tag=apple --tag=orange

This is useful, for example, if you have an archive of messages you
would like to add to the database with a special tag so that they can
be easily identified later. To do that, you could simply copy the files
from the archive to the database directory and then index them all with:

  notmuch new --tag=prehistory

Tags to be applied every time 'notmuch new' is run can be specified in
the configuration file. One-time tags for individual runs can be
specified on the command line with this new option.

Signed-off-by: Jan Janak 
---
 notmuch-new.c |   40 ++--
 notmuch.c |8 +++-
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 10745e8..94036da 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -26,6 +26,9 @@ static volatile sig_atomic_t do_add_files_print_progress = 0;

 static notmuch_config_t *config = NULL;

+static char **cmdline_tags = NULL;
+static unsigned int cmdline_tags_count = 0;
+
 static void
 handle_sigalrm (unused (int signal))
 {
@@ -76,12 +79,19 @@ apply_tags (notmuch_message_t *message)
 char** tags;
 unsigned int count, i;

-if ((tags = notmuch_config_get_new_tags (config, )) == NULL)
-   return;
+if (cmdline_tags_count) {
+   for (i = 0; i < cmdline_tags_count; i++) {
+   if (cmdline_tags[i])
+   notmuch_message_add_tag (message, cmdline_tags[i]);
+   }
+} else {
+   if ((tags = notmuch_config_get_new_tags (config, )) == NULL)
+   return;

-for (i = 0; i < count; i++) {
-   if (tags[i])
-   notmuch_message_add_tag (message, tags[i]);
+   for (i = 0; i < count; i++) {
+   if (tags[i])
+   notmuch_message_add_tag (message, tags[i]);
+   }
 }
 }

@@ -413,7 +423,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
 int ret = 0;
 struct stat st;
 const char *db_path;
-char *dot_notmuch_path;
+char *dot_notmuch_path, *opt;
+char **tmp;
 struct sigaction action;
 int i;

@@ -423,6 +434,23 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
 for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {
add_files_state.verbose = 1;
+   } else if (STRNCMP_LITERAL (argv[i], "--tag=") == 0) {
+   opt = argv[i] + sizeof ("--tag=") - 1;
+   /* FIXME: We should check for leading and trailing white-space in
+* option value here and remove it.
+*/
+   if (*opt == '\0') {
+   fprintf (stderr, "Option value missing: %s\n", argv[i]);
+   return 1;
+   }
+   tmp = talloc_realloc (ctx, cmdline_tags, char*,
+ cmdline_tags_count + 1);
+   if (tmp == NULL) {
+   fprintf (stderr, "Notmuch ran out of memory.\n");
+   return 1;
+   }
+   tmp[cmdline_tags_count++] = opt;
+   cmdline_tags = tmp;
} else {
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
diff --git a/notmuch.c b/notmuch.c
index b84e284..fb0c2a7 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -123,7 +123,7 @@ command_t commands[] = {
   "\t\tInvoking notmuch with no command argument will run setup if\n"
   "\t\tthe setup command has not previously been completed." },
 { "new", notmuch_new_command,
-  "[--verbose]",
+  "[--verbose] [--tag=]",
   "\t\tFind and import new messages to the notmuch database.",
   "\t\tScans all sub-directories of the mail directory, performing\n"
   "\t\tfull-text indexing on new messages that are found. Each new\n"
@@ -145,6 +145,12 @@ command_t commands[] = {
   "\t\t\tVerbose operation. Shows paths of message files as\n"
   "\t\t\tthey are being indexed.\n"
   "\n"
+  "\t\t--tag=\n"
+  "\n"
+  "\t\t\tAdd the tag  to all messages newly added to the\n"
+  "\t\t\tdatabase. You may repeat this option several times if\n"
+  "\t\t\tyou want to add more tags.\n"
+  "\n"
   "\t\tNote: \"notmuch new\" runs (other than the first run) will\n"
   "\t\tskip any read-only directories, so you can use that to mark\n"
   "\t\tdirectories that will not receive any new mail (and make\n"
-- 
1.6.3.3