]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch search: Add --first and --max-threads options for incremental search.
authorCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 04:47:12 +0000 (20:47 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 04:47:12 +0000 (20:47 -0800)
This time, things are actually tested. The current results aren't
exactly the same as previous results since the incremental search
doesn't necessarily see all the new messages that pertain to the
thread. This means that some author names are missing.

I plan to fix this by doing an additional database search for all
messages in each thread. Of course, this will also be different than
before since now the result will display *all* authors in the thread
(rather than only those that matched the search) but that's probably
what we really want to display anyway.

notmuch-client.h
notmuch-search.c

index f3396d0df721f5dd8bfa03b3a406d26d8a859412..1081a159db573cc0bcfc23bf7593822a8532f26d 100644 (file)
@@ -66,6 +66,9 @@
 
 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
 
+#define STRNCMP_LITERAL(var, literal) \
+    strncmp ((var), (literal), sizeof (literal) - 1)
+
 typedef int (*command_function_t) (void *ctx, int argc, char *argv[]);
 
 typedef struct command {
index 41e317a221961ebdab9d82ada88a9f4dc0935fae..85f3514ee099b4142097dde4cd1e0895c979c3af 100644 (file)
@@ -32,6 +32,33 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
     char *query_str;
     const char *relative_date;
     time_t date;
+    int i, first = 0, max_threads = -1;
+    char *opt, *end;
+
+    for (i = 0; i < argc && argv[i][0] == '-'; i++) {
+       if (strcmp (argv[i], "--") == 0) {
+           i++;
+           break;
+       }
+       if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {
+           opt = argv[i] + sizeof ("--first=") - 1;
+           first = strtoul (opt, &end, 10);
+           if (*opt == '\0' || *end != '\0') {
+               fprintf (stderr, "Invalid value for --first: %s\n", opt);
+               return 1;
+           }
+       } else if (STRNCMP_LITERAL (argv[i], "--max-threads=") == 0) {
+           opt = argv[i] + sizeof ("--max-threads=") - 1;
+           max_threads = strtoul (opt, &end, 10);
+           if (*opt == '\0' || *end != '\0') {
+               fprintf (stderr, "Invalid value for --max-threads: %s\n", opt);
+               return 1;
+           }
+       }
+    }
+
+    argc -= i;
+    argv += i;
 
     config = notmuch_config_open (ctx, NULL, NULL);
     if (config == NULL)
@@ -53,7 +80,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
        return 1;
     }
 
-    for (threads = notmuch_query_search_threads (query, 0, -1);
+    for (threads = notmuch_query_search_threads (query, first, max_threads);
         notmuch_threads_has_more (threads);
         notmuch_threads_advance (threads))
     {