--- /dev/null
+Return-Path: <sojkam1@fel.cvut.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 0580F429E3C\r
+ for <notmuch@notmuchmail.org>; Mon, 3 Nov 2014 15:50:59 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id OP4B65rPY69E for <notmuch@notmuchmail.org>;\r
+ Mon, 3 Nov 2014 15:50:54 -0800 (PST)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id C8E74429E29\r
+ for <notmuch@notmuchmail.org>; Mon, 3 Nov 2014 15:50:47 -0800 (PST)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 41CB15CD014\r
+ for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 00:50:47 +0100 (CET)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+ by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+ port 10044) with ESMTP id J1nRsW_lV2gy for <notmuch@notmuchmail.org>;\r
+ Tue, 4 Nov 2014 00:50:40 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id C8FF45CD009\r
+ for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 00:50:39 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1XlROM-0005WQ-2H; Tue, 04 Nov 2014 00:50:34 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 02/10] cli: search: Move more variables into\r
+ search_context_t\r
+Date: Tue, 4 Nov 2014 00:50:14 +0100\r
+Message-Id: <1415058622-21162-3-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 03 Nov 2014 23:50:59 -0000\r
+\r
+Just refactoring, no functional changes.\r
+---\r
+ notmuch-search.c | 49 ++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 26 insertions(+), 23 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 2c47b80..3d2012b 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -34,8 +34,18 @@ typedef enum {\r
+ \r
+ #define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)\r
+ \r
++typedef enum {\r
++ NOTMUCH_FORMAT_JSON,\r
++ NOTMUCH_FORMAT_TEXT,\r
++ NOTMUCH_FORMAT_TEXT0,\r
++ NOTMUCH_FORMAT_SEXP\r
++} format_sel_t;\r
++\r
+ typedef struct {\r
++ notmuch_database_t *notmuch;\r
++ format_sel_t format_sel;\r
+ sprinter_t *format;\r
++ notmuch_exclude_t exclude;\r
+ notmuch_query_t *query;\r
+ notmuch_sort_t sort;\r
+ output_t output;\r
+@@ -413,14 +423,14 @@ do_search_messages (search_context_t *ctx)\r
+ }\r
+ \r
+ static int\r
+-do_search_tags (notmuch_database_t *notmuch,\r
+- const search_context_t *ctx)\r
++do_search_tags (const search_context_t *ctx)\r
+ {\r
+ notmuch_messages_t *messages = NULL;\r
+ notmuch_tags_t *tags;\r
+ const char *tag;\r
+ sprinter_t *format = ctx->format;\r
+ notmuch_query_t *query = ctx->query;\r
++ notmuch_database_t *notmuch = ctx->notmuch;\r
+ \r
+ /* should the following only special case if no excluded terms\r
+ * specified? */\r
+@@ -464,8 +474,9 @@ do_search_tags (notmuch_database_t *notmuch,\r
+ int\r
+ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+- notmuch_database_t *notmuch;\r
+ search_context_t ctx = {\r
++ .format_sel = NOTMUCH_FORMAT_TEXT,\r
++ .exclude = NOTMUCH_EXCLUDE_TRUE,\r
+ .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
+ .output = 0,\r
+ .offset = 0,\r
+@@ -474,22 +485,14 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ };\r
+ char *query_str;\r
+ int opt_index, ret;\r
+- notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;\r
+ unsigned int i;\r
+ \r
+- enum {\r
+- NOTMUCH_FORMAT_JSON,\r
+- NOTMUCH_FORMAT_TEXT,\r
+- NOTMUCH_FORMAT_TEXT0,\r
+- NOTMUCH_FORMAT_SEXP\r
+- } format_sel = NOTMUCH_FORMAT_TEXT;\r
+-\r
+ notmuch_opt_desc_t options[] = {\r
+ { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',\r
+ (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
+ { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
+ { 0, 0 } } },\r
+- { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',\r
++ { NOTMUCH_OPT_KEYWORD, &ctx.format_sel, "format", 'f',\r
+ (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },\r
+ { "sexp", NOTMUCH_FORMAT_SEXP },\r
+ { "text", NOTMUCH_FORMAT_TEXT },\r
+@@ -505,7 +508,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ { "files", OUTPUT_FILES },\r
+ { "tags", OUTPUT_TAGS },\r
+ { 0, 0 } } },\r
+- { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x',\r
++ { NOTMUCH_OPT_KEYWORD, &ctx.exclude, "exclude", 'x',\r
+ (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },\r
+ { "false", NOTMUCH_EXCLUDE_FALSE },\r
+ { "flag", NOTMUCH_EXCLUDE_FLAG },\r
+@@ -530,7 +533,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ return EXIT_FAILURE;\r
+ }\r
+ \r
+- switch (format_sel) {\r
++ switch (ctx.format_sel) {\r
+ case NOTMUCH_FORMAT_TEXT:\r
+ ctx.format = sprinter_text_create (config, stdout);\r
+ break;\r
+@@ -555,10 +558,10 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ notmuch_exit_if_unsupported_format ();\r
+ \r
+ if (notmuch_database_open (notmuch_config_get_database_path (config),\r
+- NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))\r
++ NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx.notmuch))\r
+ return EXIT_FAILURE;\r
+ \r
+- query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);\r
++ query_str = query_string_from_args (ctx.notmuch, argc-opt_index, argv+opt_index);\r
+ if (query_str == NULL) {\r
+ fprintf (stderr, "Out of memory.\n");\r
+ return EXIT_FAILURE;\r
+@@ -568,7 +571,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ return EXIT_FAILURE;\r
+ }\r
+ \r
+- ctx.query = notmuch_query_create (notmuch, query_str);\r
++ ctx.query = notmuch_query_create (ctx.notmuch, query_str);\r
+ if (ctx.query == NULL) {\r
+ fprintf (stderr, "Out of memory\n");\r
+ return EXIT_FAILURE;\r
+@@ -576,15 +579,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ \r
+ notmuch_query_set_sort (ctx.query, ctx.sort);\r
+ \r
+- if (exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {\r
++ if (ctx.exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {\r
+ /* If we are not doing summary output there is nowhere to\r
+ * print the excluded flag so fall back on including the\r
+ * excluded messages. */\r
+ fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");\r
+- exclude = NOTMUCH_EXCLUDE_FALSE;\r
++ ctx.exclude = NOTMUCH_EXCLUDE_FALSE;\r
+ }\r
+ \r
+- if (exclude != NOTMUCH_EXCLUDE_FALSE) {\r
++ if (ctx.exclude != NOTMUCH_EXCLUDE_FALSE) {\r
+ const char **search_exclude_tags;\r
+ size_t search_exclude_tags_length;\r
+ \r
+@@ -592,7 +595,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ (config, &search_exclude_tags_length);\r
+ for (i = 0; i < search_exclude_tags_length; i++)\r
+ notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);\r
+- notmuch_query_set_omit_excluded (ctx.query, exclude);\r
++ notmuch_query_set_omit_excluded (ctx.query, ctx.exclude);\r
+ }\r
+ \r
+ if (ctx.output == OUTPUT_SUMMARY ||\r
+@@ -603,14 +606,14 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))\r
+ ret = do_search_messages (&ctx);\r
+ else if (ctx.output == OUTPUT_TAGS)\r
+- ret = do_search_tags (notmuch, &ctx);\r
++ ret = do_search_tags (&ctx);\r
+ else {\r
+ fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
+ ret = 1;\r
+ }\r
+ \r
+ notmuch_query_destroy (ctx.query);\r
+- notmuch_database_destroy (notmuch);\r
++ notmuch_database_destroy (ctx.notmuch);\r
+ \r
+ talloc_free (ctx.format);\r
+ \r
+-- \r
+2.1.1\r
+\r