* [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags @ 2016-06-04 12:45 David Bremner 2016-06-04 12:53 ` David Bremner ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: David Bremner @ 2016-06-04 12:45 UTC (permalink / raw) To: notmuch [-- Attachment #0: Type: message/rfc822, Size: 7099 bytes --] From: Jameson Graef Rollins <jrollins@finestructure.net> To: Debian Bug Tracking System <submit@bugs.debian.org> Subject: Bug#826280: notmuch: shortcut to list tags Date: Fri, 03 Jun 2016 13:51:37 -0700 Message-ID: <146498709797.16348.3163286438619529823.reportbug@servo.finestructure.net> Package: notmuch Version: 0.22-1 Severity: wishlist I occaissionally want to grep through all tags used in my store: notmuch search --output=tags '*' | grep .... It would be nice if there was a shortcut to output all tags to stdout: notmuch tag | grep ... Just utilizing the notmuch tag command when called with no arguments would be the most intiuitive (just like git) and simplest. Thanks. jamie. -- System Information: Debian Release: stretch/sid APT prefers testing APT policy: (600, 'testing'), (200, 'unstable'), (101, 'experimental') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.5.0-1-amd64 (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) Versions of packages notmuch depends on: ii libc6 2.22-7 ii libglib2.0-0 2.48.1-1 ii libgmime-2.6-0 2.6.20-1+b1 ii libnotmuch4 0.22-1 ii libtalloc2 2.1.6-1 ii zlib1g 1:1.2.8.dfsg-2+b1 Versions of packages notmuch recommends: ii alot 0.3.6-1 ii gnupg-agent 2.1.11-7 ii gpgsm 2.1.11-7 ii notmuch-emacs 0.22-1 ii notmuch-mutt 0.22-1 ii notmuch-vim 0.22-1 notmuch suggests no packages. -- no debconf information ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags 2016-06-04 12:45 [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags David Bremner @ 2016-06-04 12:53 ` David Bremner [not found] ` <CAMEnOBLrmjhERgGRJ2UC8ZSPQOEPCtr7_4pqq+Uot201G2fDcA@mail.gmail.com> 2016-06-05 9:51 ` Tomi Ollila 2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner 2 siblings, 1 reply; 7+ messages in thread From: David Bremner @ 2016-06-04 12:53 UTC (permalink / raw) To: notmuch David Bremner <david@tethera.net> writes: > > I occaissionally want to grep through all tags used in my store: > > notmuch search --output=tags '*' | grep .... > > It would be nice if there was a shortcut to output all tags to stdout: > > notmuch tag | grep ... > > Just utilizing the notmuch tag command when called with no arguments > would be the most intiuitive (just like git) and simplest. I haven't looked at how much work this would be (the notmuch-tag command line parsing is slightly more complicated than some of the other commands), but a related issue is that it seems sensible for notmuch query commands (show/search) to interpret a missing query string as '*', in the same way that dump does. d ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAMEnOBLrmjhERgGRJ2UC8ZSPQOEPCtr7_4pqq+Uot201G2fDcA@mail.gmail.com>]
* Re: [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags [not found] ` <CAMEnOBLrmjhERgGRJ2UC8ZSPQOEPCtr7_4pqq+Uot201G2fDcA@mail.gmail.com> @ 2016-06-04 17:52 ` David Bremner 0 siblings, 0 replies; 7+ messages in thread From: David Bremner @ 2016-06-04 17:52 UTC (permalink / raw) To: Davide Mancusi; +Cc: notmuch Davide Mancusi <arekfu@yahoo.it> writes: > 2016-06-04 14:53 GMT+02:00 David Bremner <david@tethera.net>: >> I haven't looked at how much work this would be (the notmuch-tag command >> line parsing is slightly more complicated than some of the other >> commands) > > How about a `-l' switch for notmuch tag (in a way similar to what `git > tag -l' does)? Currently there are no short options for notmuch commands. A simple matter of programming, like so much else. d ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags 2016-06-04 12:45 [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags David Bremner 2016-06-04 12:53 ` David Bremner @ 2016-06-05 9:51 ` Tomi Ollila 2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner 2 siblings, 0 replies; 7+ messages in thread From: Tomi Ollila @ 2016-06-05 9:51 UTC (permalink / raw) To: David Bremner, notmuch On Sat, Jun 04 2016, David Bremner <david@tethera.net> wrote: > From: Jameson Graef Rollins <jrollins@finestructure.net> > Subject: Bug#826280: notmuch: shortcut to list tags > To: Debian Bug Tracking System <submit@bugs.debian.org> > Date: Fri, 03 Jun 2016 13:51:37 -0700 > > Package: notmuch > Version: 0.22-1 > Severity: wishlist > > I occaissionally want to grep through all tags used in my store: > > notmuch search --output=tags '*' | grep .... > > It would be nice if there was a shortcut to output all tags to stdout: > > notmuch tag | grep ... > > Just utilizing the notmuch tag command when called with no arguments > would be the most intiuitive (just like git) and simplest. we have this command "notmuch search-tags"... $ notmuch search-tags Error: Unknown command 'search-tags' (see "notmuch help") zsh: exit 1 notmuch search-tags Oh no, this deprecated commands was removed w/o mentionig that in NEWS >;/ Tomi > > Thanks. > > jamie. > > -- System Information: > Debian Release: stretch/sid > APT prefers testing > APT policy: (600, 'testing'), (200, 'unstable'), (101, 'experimental') > Architecture: amd64 (x86_64) > Foreign Architectures: i386 > > Kernel: Linux 4.5.0-1-amd64 (SMP w/4 CPU cores) > Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) > Shell: /bin/sh linked to /bin/dash > Init: systemd (via /run/systemd/system) > > Versions of packages notmuch depends on: > ii libc6 2.22-7 > ii libglib2.0-0 2.48.1-1 > ii libgmime-2.6-0 2.6.20-1+b1 > ii libnotmuch4 0.22-1 > ii libtalloc2 2.1.6-1 > ii zlib1g 1:1.2.8.dfsg-2+b1 > > Versions of packages notmuch recommends: > ii alot 0.3.6-1 > ii gnupg-agent 2.1.11-7 > ii gpgsm 2.1.11-7 > ii notmuch-emacs 0.22-1 > ii notmuch-mutt 0.22-1 > ii notmuch-vim 0.22-1 > > notmuch suggests no packages. > > -- no debconf information > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch ^ permalink raw reply [flat|nested] 7+ messages in thread
* RFC: do what jamie wants with notmuch tag 2016-06-04 12:45 [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags David Bremner 2016-06-04 12:53 ` David Bremner 2016-06-05 9:51 ` Tomi Ollila @ 2016-06-30 8:40 ` David Bremner 2016-06-30 8:40 ` [PATCH 1/2] WIP: refactor tag search into library routine David Bremner 2016-06-30 8:40 ` [PATCH 2/2] WIP: treat notmuch tag without operations as query David Bremner 2 siblings, 2 replies; 7+ messages in thread From: David Bremner @ 2016-06-30 8:40 UTC (permalink / raw) To: David Bremner, notmuch The second patch in particular could be cleaned up; there is definitely some duplication between the two code paths, so opening the database and creating a query could/should be refactored. It seems somewhat reasonable to have notmuch_query_search_tags in the API. I would say just document the limitation of ignoring excludes when querying for all tags, otherwise that optimization (which is a huge speed improvement) will mostly be useless. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] WIP: refactor tag search into library routine 2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner @ 2016-06-30 8:40 ` David Bremner 2016-06-30 8:40 ` [PATCH 2/2] WIP: treat notmuch tag without operations as query David Bremner 1 sibling, 0 replies; 7+ messages in thread From: David Bremner @ 2016-06-30 8:40 UTC (permalink / raw) To: David Bremner, notmuch --- lib/notmuch.h | 13 +++++++++++++ lib/query.cc | 35 +++++++++++++++++++++++++++++++++++ notmuch-search.c | 24 ++++-------------------- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index 2faa146..927ea3c 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -927,6 +927,19 @@ notmuch_messages_t * notmuch_query_search_messages (notmuch_query_t *query); /** + * Execute a query for tags, outputing a notmuch_tags_t object + * which can be used to iterate over the results. The output + * tags object is owned by the query and as such, will only be + * valid until notmuch_query_destroy. + * + * @param[in] query the query to collect tags for + * @param[out] out the return tags list + * + */ +notmuch_status_t +notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **out); + +/** * Destroy a notmuch_query_t along with any associated resources. * * This will in turn destroy any notmuch_threads_t and diff --git a/lib/query.cc b/lib/query.cc index 7eb73a1..7245b12 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -310,6 +310,41 @@ _notmuch_query_search_documents (notmuch_query_t *query, } } +notmuch_status_t +notmuch_query_search_tags (notmuch_query_t *query, notmuch_tags_t **tags) +{ + notmuch_messages_t *messages = NULL; + notmuch_database_t *notmuch = notmuch_query_get_database (query); + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + const char *query_string = notmuch_query_get_query_string (query); + + if (tags == NULL) + return NOTMUCH_STATUS_NULL_POINTER; + + /* Special-case query of "*" or '' for better performance. */ + if (strcmp (query_string, "*") == 0 || *query_string == '\0') { + *tags = notmuch_database_get_all_tags (notmuch); + if (*tags == NULL) + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + } else { + notmuch_status_t status; + status = notmuch_query_search_messages_st (query, &messages); + if (status) + goto DONE; + + *tags = notmuch_messages_collect_tags (messages); + talloc_steal (query, *tags); + if (*tags == NULL) + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + } + + DONE: + if (messages) + notmuch_messages_destroy (messages); + + return status; +} + notmuch_bool_t _notmuch_mset_messages_valid (notmuch_messages_t *messages) { diff --git a/notmuch-search.c b/notmuch-search.c index 8c65d5a..8722735 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -611,31 +611,18 @@ do_search_messages (search_context_t *ctx) 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) + if (print_status_query ("notmuch search", + query, + notmuch_query_search_tags (query, &tags))) return 1; format->begin_list (format); @@ -653,9 +640,6 @@ do_search_tags (const search_context_t *ctx) notmuch_tags_destroy (tags); - if (messages) - notmuch_messages_destroy (messages); - format->end (format); return 0; -- 2.8.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] WIP: treat notmuch tag without operations as query 2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner 2016-06-30 8:40 ` [PATCH 1/2] WIP: refactor tag search into library routine David Bremner @ 2016-06-30 8:40 ` David Bremner 1 sibling, 0 replies; 7+ messages in thread From: David Bremner @ 2016-06-30 8:40 UTC (permalink / raw) To: David Bremner, notmuch e.g. % notmuch tag # dump all tags % notmuch tag subject:foo # all tags of messages with foo in the subject --- notmuch-tag.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/notmuch-tag.c b/notmuch-tag.c index 18d78dd..941c653 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -186,6 +186,50 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags, return ret || warn; } +static int +_dump_tags (notmuch_config_t *config, const char *query_string) +{ + notmuch_database_t *notmuch; + notmuch_tags_t *tags; + const char *tag; + char *status_string; + + notmuch_query_t *query; + + if (notmuch_database_open_verbose (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY, + ¬much, &status_string)) { + if (status_string) { + fputs (status_string, stderr); + free (status_string); + } + return EXIT_FAILURE; + } + + query = notmuch_query_create (notmuch, query_string); + if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return EXIT_FAILURE; + } + + if (print_status_query ("notmuch tag", + query, + notmuch_query_search_tags (query, &tags))) + return 1; + + for (; + notmuch_tags_valid (tags); + notmuch_tags_move_to_next (tags)) + { + tag = notmuch_tags_get (tags); + + printf ("%s\n", tag); + } + + notmuch_tags_destroy (tags); + return EXIT_SUCCESS; +} + int notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -196,6 +240,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) tag_op_flag_t tag_flags = TAG_FLAG_NONE; notmuch_bool_t batch = FALSE; notmuch_bool_t remove_all = FALSE; + notmuch_bool_t with_ops = FALSE; FILE *input = stdin; char *input_file_name = NULL; int opt_index; @@ -248,17 +293,18 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]) &query_string, tag_ops)) return EXIT_FAILURE; - if (tag_op_list_size (tag_ops) == 0 && ! remove_all) { - fprintf (stderr, "Error: 'notmuch tag' requires at least one tag to add or remove.\n"); - return EXIT_FAILURE; - } + if (tag_op_list_size (tag_ops) == 0 && ! remove_all) + with_ops = FALSE; - if (*query_string == '\0') { - fprintf (stderr, "Error: notmuch tag requires at least one search term.\n"); + if (with_ops && *query_string == '\0') { + fprintf (stderr, "Error: notmuch tag with operations requires at least one search term.\n"); return EXIT_FAILURE; } } + if (! with_ops) + return _dump_tags (config, query_string); + if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) return EXIT_FAILURE; -- 2.8.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-06-30 8:40 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-06-04 12:45 [Jameson Graef Rollins] Bug#826280: notmuch: shortcut to list tags David Bremner 2016-06-04 12:53 ` David Bremner [not found] ` <CAMEnOBLrmjhERgGRJ2UC8ZSPQOEPCtr7_4pqq+Uot201G2fDcA@mail.gmail.com> 2016-06-04 17:52 ` David Bremner 2016-06-05 9:51 ` Tomi Ollila 2016-06-30 8:40 ` RFC: do what jamie wants with notmuch tag David Bremner 2016-06-30 8:40 ` [PATCH 1/2] WIP: refactor tag search into library routine David Bremner 2016-06-30 8:40 ` [PATCH 2/2] WIP: treat notmuch tag without operations as query David Bremner
Code repositories for project(s) associated with this public inbox https://yhetil.org/notmuch.git/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).