From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 2/6] cli: extract count printing to a separate function in notmuch count
Date: Sat, 9 Mar 2013 17:12:22 +0200 [thread overview]
Message-ID: <fd3f0f94e505cd4e35b04efe6a9cac394caa61c6.1362841844.git.jani@nikula.org> (raw)
In-Reply-To: <cover.1362841844.git.jani@nikula.org>
In-Reply-To: <cover.1362841844.git.jani@nikula.org>
Make count printing on a query string reusable. No functional changes.
---
notmuch-count.c | 59 +++++++++++++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 23 deletions(-)
diff --git a/notmuch-count.c b/notmuch-count.c
index c2f1b7d..630f036 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -32,16 +32,47 @@ enum {
EXCLUDE_FALSE,
};
+static int
+print_count (notmuch_database_t *notmuch, const char *query_str,
+ const char **exclude_tags, size_t exclude_tags_length, int output)
+{
+ notmuch_query_t *query;
+ size_t i;
+
+ query = notmuch_query_create (notmuch, query_str);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ return 1;
+ }
+
+ for (i = 0; i < exclude_tags_length; i++)
+ notmuch_query_add_tag_exclude (query, exclude_tags[i]);
+
+ switch (output) {
+ case OUTPUT_MESSAGES:
+ printf ("%u\n", notmuch_query_count_messages (query));
+ break;
+ case OUTPUT_THREADS:
+ printf ("%u\n", notmuch_query_count_threads (query));
+ break;
+ }
+
+ notmuch_query_destroy (query);
+
+ return 0;
+}
+
int
notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
{
notmuch_database_t *notmuch;
- notmuch_query_t *query;
char *query_str;
int opt_index;
int output = OUTPUT_MESSAGES;
int exclude = EXCLUDE_TRUE;
- unsigned int i;
+ const char **search_exclude_tags = NULL;
+ size_t search_exclude_tags_length = 0;
+ int ret;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
@@ -71,33 +102,15 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
return 1;
}
- query = notmuch_query_create (notmuch, query_str);
- if (query == NULL) {
- fprintf (stderr, "Out of memory\n");
- return 1;
- }
-
if (exclude == EXCLUDE_TRUE) {
- 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) {
- case OUTPUT_MESSAGES:
- printf ("%u\n", notmuch_query_count_messages (query));
- break;
- case OUTPUT_THREADS:
- printf ("%u\n", notmuch_query_count_threads (query));
- break;
- }
+ ret = print_count (notmuch, query_str, search_exclude_tags,
+ search_exclude_tags_length, output);
- notmuch_query_destroy (query);
notmuch_database_destroy (notmuch);
- return 0;
+ return ret;
}
--
1.7.10.4
next prev parent reply other threads:[~2013-03-09 15:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-09 15:12 [PATCH v2 0/6] batch count for notmuch-hello speedup Jani Nikula
2013-03-09 15:12 ` [PATCH v2 1/6] cli: remove useless strdup Jani Nikula
2013-03-09 15:12 ` Jani Nikula [this message]
2013-03-09 15:12 ` [PATCH v2 3/6] cli: add --batch option to notmuch count Jani Nikula
2013-03-21 13:34 ` Jameson Graef Rollins
2013-03-26 20:05 ` Jani Nikula
2013-03-30 13:59 ` Jani Nikula
2013-03-09 15:12 ` [PATCH v2 4/6] man: document notmuch count --batch and --input options Jani Nikula
2013-03-09 15:12 ` [PATCH v2 5/6] test: " Jani Nikula
2013-03-09 15:12 ` [PATCH v2 6/6] emacs: hello: use batch count Jani Nikula
2013-03-31 1:45 ` [PATCH v2 0/6] batch count for notmuch-hello speedup Jameson Graef Rollins
2013-03-31 7:39 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fd3f0f94e505cd4e35b04efe6a9cac394caa61c6.1362841844.git.jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).