]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-search.c
cli: refactor "notmuch tag" data structures for tagging operations
[notmuch] / notmuch-search.c
index 8867aabcea9dc12b7359cda0abe79a5d8a990bf3..f6061e4ec08920273450bfba954473812110504f 100644 (file)
@@ -90,6 +90,9 @@ format_thread_json (const void *ctx,
                    const int total,
                    const char *authors,
                    const char *subject);
+
+/* Any changes to the JSON format should be reflected in the file
+ * devel/schemata. */
 static const search_format_t format_json = {
     "[",
        "{",
@@ -207,6 +210,9 @@ do_search_threads (const search_format_t *format,
     int first_thread = 1;
     int i;
 
+    if (output == OUTPUT_THREADS)
+       notmuch_query_set_omit_excluded_messages (query, TRUE);
+
     if (offset < 0) {
        offset += notmuch_query_count_threads (query);
        if (offset < 0)
@@ -297,6 +303,8 @@ do_search_messages (const search_format_t *format,
     int first_message = 1;
     int i;
 
+    notmuch_query_set_omit_excluded_messages (query, TRUE);
+
     if (offset < 0) {
        offset += notmuch_query_count_messages (query);
        if (offset < 0)
@@ -368,6 +376,10 @@ do_search_tags (notmuch_database_t *notmuch,
     const char *tag;
     int first_tag = 1;
 
+    notmuch_query_set_omit_excluded_messages (query, TRUE);
+    /* should the following only special case if no excluded terms
+     * specified? */
+
     /* Special-case query of "*" for better performance. */
     if (strcmp (notmuch_query_get_query_string (query), "*") == 0) {
        tags = notmuch_database_get_all_tags (notmuch);
@@ -423,8 +435,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
     output_t output = OUTPUT_SUMMARY;
     int offset = 0;
     int limit = -1; /* unlimited */
-    const char **auto_exclude_tags;
-    size_t auto_exclude_tags_length;
+    notmuch_bool_t no_exclude = FALSE;
     unsigned int i;
 
     enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
@@ -446,6 +457,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
                                  { "files", OUTPUT_FILES },
                                  { "tags", OUTPUT_TAGS },
                                  { 0, 0 } } },
+       { NOTMUCH_OPT_BOOLEAN, &no_exclude, "no-exclude", 'd', 0 },
        { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
        { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },
        { 0, 0, 0, 0, 0 }
@@ -493,10 +505,15 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
 
     notmuch_query_set_sort (query, sort);
 
-    auto_exclude_tags = notmuch_config_get_auto_exclude_tags
-       (config, &auto_exclude_tags_length);
-    for (i = 0; i < auto_exclude_tags_length; i++)
-       notmuch_query_add_tag_exclude (query, auto_exclude_tags[i]);
+    if (!no_exclude) {
+       const char **search_exclude_tags;
+       size_t search_exclude_tags_length;
+
+       search_exclude_tags = notmuch_config_get_search_exclude_tags
+           (config, &search_exclude_tags_length);
+       for (i = 0; i < search_exclude_tags_length; i++)
+           notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);
+    }
 
     switch (output) {
     default: