static int do_search_tags (notmuch_database_t *notmuch, const search_format_t *format, notmuch_query_t *query) { notmuch_messages_t *messages = NULL; notmuch_tags_t *tags; const char *tag; int first_tag = 1; /* Special-case query of "*" for better performance. */ if (strcmp (notmuch_query_get_query_string (query), "*") == 0) { tags = notmuch_database_get_all_tags (notmuch); } else { messages = notmuch_query_search_messages (query); if (messages == NULL) return 1; tags = notmuch_messages_collect_tags (messages); } if (tags == NULL) return 1; fputs (format->results_start, stdout); for (; notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags); if (! first_tag) fputs (format->item_sep, stdout); format->item_id (tags, "", tag); first_tag = 0; } notmuch_tags_destroy (tags); if (messages) notmuch_messages_destroy (messages); if (first_tag) fputs (format->results_null, stdout); else fputs (format->results_end, stdout); return 0; }
static int do_search_tags (const search_context_t *ctx) { notmuch_messages_t *messages = NULL; notmuch_tags_t *tags; const char *tag; sprinter_t *format = ctx->format; notmuch_query_t *query = ctx->query; notmuch_database_t *notmuch = ctx->notmuch; /* 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); } else { notmuch_status_t status; status = notmuch_query_search_messages_st (query, &messages); if (print_status_query ("notmuch search", query, status)) return 1; tags = notmuch_messages_collect_tags (messages); } if (tags == NULL) return 1; format->begin_list (format); for (; notmuch_tags_valid (tags); notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags); format->string (format, tag); format->separator (format); } notmuch_tags_destroy (tags); if (messages) notmuch_messages_destroy (messages); format->end (format); return 0; }
/* * call-seq: DB.get_all_tags() => TAGS * * Returns a list of all tags found in the database. */ VALUE notmuch_rb_database_get_all_tags (VALUE self) { notmuch_database_t *db; notmuch_tags_t *tags; Data_Get_Notmuch_Database (self, db); tags = notmuch_database_get_all_tags (db); if (!tags) { const char *msg = notmuch_database_status_string (db); if (!msg) msg = "Unknown notmuch error"; rb_raise (notmuch_rb_eBaseError, "%s", msg); } return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags); }