--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 1664B431FB6\r
+ for <notmuch@notmuchmail.org>; Wed, 22 Oct 2014 03:44:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, 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 GORAoli-E1LV for <notmuch@notmuchmail.org>;\r
+ Wed, 22 Oct 2014 03:44:20 -0700 (PDT)\r
+Received: from mail1.qmul.ac.uk (mail1.qmul.ac.uk [138.37.6.7])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id CC156431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 22 Oct 2014 03:44:19 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail1.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1XgtOm-0003ZZ-Bs; Wed, 22 Oct 2014 11:44:14 +0100\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1XgtOm-0007vI-0u; Wed, 22 Oct 2014 11:44:12 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 1/4] cli: Refactor option passing in the search command\r
+In-Reply-To: <1413150093-8383-2-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <87zjd51phx.fsf@steelpick.2x.cz>\r
+ <1413150093-8383-1-git-send-email-sojkam1@fel.cvut.cz>\r
+ <1413150093-8383-2-git-send-email-sojkam1@fel.cvut.cz>\r
+User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Wed, 22 Oct 2014 11:44:11 +0100\r
+Message-ID: <87ppdkbczo.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 59cf02e9d54476dd4ee74ecb45112bca (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.1\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -0.1 points.\r
+ Summary of the scoring: \r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.1 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Wed, 22 Oct 2014 10:44:28 -0000\r
+\r
+On Sun, 12 Oct 2014, Michal Sojka <sojkam1@fel.cvut.cz> wrote:\r
+> Many functions that implement the search command need to access command\r
+> line options. Instead of passing each option in a separate variable, put\r
+> them in a structure and pass only this structure.\r
+>\r
+> This will become handy in the following patches.\r
+\r
+Hi\r
+\r
+This basically looks good to me. I have some style queries/preferences\r
+mentioned below but am happy to be overruled by you or others.\r
+\r
+> ---\r
+> notmuch-search.c | 122 ++++++++++++++++++++++++++++---------------------------\r
+> 1 file changed, 62 insertions(+), 60 deletions(-)\r
+>\r
+> diff --git a/notmuch-search.c b/notmuch-search.c\r
+> index bc9be45..5ac2a26 100644\r
+> --- a/notmuch-search.c\r
+> +++ b/notmuch-search.c\r
+> @@ -30,6 +30,16 @@ typedef enum {\r
+> OUTPUT_TAGS\r
+> } output_t;\r
+> \r
+> +typedef struct {\r
+> + sprinter_t *format;\r
+> + notmuch_query_t *query;\r
+> + notmuch_sort_t sort;\r
+> + output_t output;\r
+> + int offset;\r
+> + int limit;\r
+> + int dupe;\r
+> +} search_options_t;\r
+> +\r
+\r
+I don't think of format as being a "search option", whereas I do think\r
+of all the others as search options. So I would prefer to omit format\r
+from search_options_t and pass it explicitly.\r
+\r
+> /* Return two stable query strings that identify exactly the matched\r
+> * and unmatched messages currently in thread. If there are no\r
+> * matched or unmatched messages, the returned buffers will be\r
+> @@ -70,46 +80,42 @@ get_thread_query (notmuch_thread_t *thread,\r
+> }\r
+> \r
+> static int\r
+> -do_search_threads (sprinter_t *format,\r
+> - notmuch_query_t *query,\r
+> - notmuch_sort_t sort,\r
+> - output_t output,\r
+> - int offset,\r
+> - int limit)\r
+> +do_search_threads (search_options_t *o)\r
+\r
+Personally, I prefer longer variable names (and names which aren't 'o'):\r
+even just opt would be a definite improvement in my opinion.\r
+\r
+> {\r
+> notmuch_thread_t *thread;\r
+> notmuch_threads_t *threads;\r
+> notmuch_tags_t *tags;\r
+> + sprinter_t *format = o->format;\r
+> time_t date;\r
+> int i;\r
+> \r
+> - if (offset < 0) {\r
+> - offset += notmuch_query_count_threads (query);\r
+> - if (offset < 0)\r
+> - offset = 0;\r
+> + if (o->offset < 0) {\r
+> + o->offset += notmuch_query_count_threads (o->query);\r
+> + if (o->offset < 0)\r
+> + o->offset = 0;\r
+> }\r
+> \r
+> - threads = notmuch_query_search_threads (query);\r
+> + threads = notmuch_query_search_threads (o->query);\r
+> if (threads == NULL)\r
+> return 1;\r
+> \r
+> format->begin_list (format);\r
+> \r
+> for (i = 0;\r
+> - notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);\r
+> + notmuch_threads_valid (threads) && (o->limit < 0 || i < o->offset + o->limit);\r
+> notmuch_threads_move_to_next (threads), i++)\r
+> {\r
+> thread = notmuch_threads_get (threads);\r
+> \r
+> - if (i < offset) {\r
+> + if (i < o->offset) {\r
+> notmuch_thread_destroy (thread);\r
+> continue;\r
+> }\r
+> \r
+> - if (output == OUTPUT_THREADS) {\r
+> + if (o->output == OUTPUT_THREADS) {\r
+> format->set_prefix (format, "thread");\r
+> format->string (format,\r
+> - notmuch_thread_get_thread_id (thread));\r
+> + notmuch_thread_get_thread_id (thread));\r
+> format->separator (format);\r
+> } else { /* output == OUTPUT_SUMMARY */\r
+> void *ctx_quote = talloc_new (thread);\r
+> @@ -123,7 +129,7 @@ do_search_threads (sprinter_t *format,\r
+> \r
+> format->begin_map (format);\r
+> \r
+> - if (sort == NOTMUCH_SORT_OLDEST_FIRST)\r
+> + if (o->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
+> date = notmuch_thread_get_oldest_date (thread);\r
+> else\r
+> date = notmuch_thread_get_newest_date (thread);\r
+> @@ -215,40 +221,36 @@ do_search_threads (sprinter_t *format,\r
+> }\r
+> \r
+> static int\r
+> -do_search_messages (sprinter_t *format,\r
+> - notmuch_query_t *query,\r
+> - output_t output,\r
+> - int offset,\r
+> - int limit,\r
+> - int dupe)\r
+> +do_search_messages (search_options_t *o)\r
+> {\r
+> notmuch_message_t *message;\r
+> notmuch_messages_t *messages;\r
+> notmuch_filenames_t *filenames;\r
+> + sprinter_t *format = o->format;\r
+> int i;\r
+> \r
+> - if (offset < 0) {\r
+> - offset += notmuch_query_count_messages (query);\r
+> - if (offset < 0)\r
+> - offset = 0;\r
+> + if (o->offset < 0) {\r
+> + o->offset += notmuch_query_count_messages (o->query);\r
+> + if (o->offset < 0)\r
+> + o->offset = 0;\r
+> }\r
+> \r
+> - messages = notmuch_query_search_messages (query);\r
+> + messages = notmuch_query_search_messages (o->query);\r
+> if (messages == NULL)\r
+> return 1;\r
+> \r
+> format->begin_list (format);\r
+> \r
+> for (i = 0;\r
+> - notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit);\r
+> + notmuch_messages_valid (messages) && (o->limit < 0 || i < o->offset + o->limit);\r
+> notmuch_messages_move_to_next (messages), i++)\r
+> {\r
+> - if (i < offset)\r
+> + if (i < o->offset)\r
+> continue;\r
+> \r
+> message = notmuch_messages_get (messages);\r
+> \r
+> - if (output == OUTPUT_FILES) {\r
+> + if (o->output == OUTPUT_FILES) {\r
+> int j;\r
+> filenames = notmuch_message_get_filenames (message);\r
+> \r
+> @@ -256,7 +258,7 @@ do_search_messages (sprinter_t *format,\r
+> notmuch_filenames_valid (filenames);\r
+> notmuch_filenames_move_to_next (filenames), j++)\r
+> {\r
+> - if (dupe < 0 || dupe == j) {\r
+> + if (o->dupe < 0 || o->dupe == j) {\r
+> format->string (format, notmuch_filenames_get (filenames));\r
+> format->separator (format);\r
+> }\r
+> @@ -333,16 +335,16 @@ int\r
+> notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> {\r
+> notmuch_database_t *notmuch;\r
+> - notmuch_query_t *query;\r
+> + search_options_t o = {\r
+> + .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
+> + .output = OUTPUT_SUMMARY,\r
+> + .offset = 0,\r
+> + .limit = -1, /* unlimited */\r
+> + .dupe = -1,\r
+> + };\r
+> char *query_str;\r
+> - notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;\r
+> - sprinter_t *format = NULL;\r
+> int opt_index, ret;\r
+> - output_t output = OUTPUT_SUMMARY;\r
+> - int offset = 0;\r
+> - int limit = -1; /* unlimited */\r
+> notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE;\r
+> - int dupe = -1;\r
+> unsigned int i;\r
+> \r
+> enum {\r
+> @@ -353,7 +355,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> } format_sel = NOTMUCH_FORMAT_TEXT;\r
+> \r
+> notmuch_opt_desc_t options[] = {\r
+> - { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',\r
+> + { NOTMUCH_OPT_KEYWORD, &o.sort, "sort", 's',\r
+> (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
+> { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
+> { 0, 0 } } },\r
+> @@ -364,7 +366,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+> { 0, 0 } } },\r
+> { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },\r
+> - { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',\r
+> + { NOTMUCH_OPT_KEYWORD, &o.output, "output", 'o',\r
+> (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
+> { "threads", OUTPUT_THREADS },\r
+> { "messages", OUTPUT_MESSAGES },\r
+> @@ -377,9 +379,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> { "flag", NOTMUCH_EXCLUDE_FLAG },\r
+> { "all", NOTMUCH_EXCLUDE_ALL },\r
+> { 0, 0 } } },\r
+> - { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },\r
+> - { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 },\r
+> - { NOTMUCH_OPT_INT, &dupe, "duplicate", 'D', 0 },\r
+> + { NOTMUCH_OPT_INT, &o.offset, "offset", 'O', 0 },\r
+> + { NOTMUCH_OPT_INT, &o.limit, "limit", 'L', 0 },\r
+> + { NOTMUCH_OPT_INT, &o.dupe, "duplicate", 'D', 0 },\r
+> { 0, 0, 0, 0, 0 }\r
+> };\r
+> \r
+> @@ -389,20 +391,20 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> \r
+> switch (format_sel) {\r
+> case NOTMUCH_FORMAT_TEXT:\r
+> - format = sprinter_text_create (config, stdout);\r
+> + o.format = sprinter_text_create (config, stdout);\r
+> break;\r
+> case NOTMUCH_FORMAT_TEXT0:\r
+> - if (output == OUTPUT_SUMMARY) {\r
+> + if (o.output == OUTPUT_SUMMARY) {\r
+> fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
+> return EXIT_FAILURE;\r
+> }\r
+> - format = sprinter_text0_create (config, stdout);\r
+> + o.format = sprinter_text0_create (config, stdout);\r
+> break;\r
+> case NOTMUCH_FORMAT_JSON:\r
+> - format = sprinter_json_create (config, stdout);\r
+> + o.format = sprinter_json_create (config, stdout);\r
+> break;\r
+> case NOTMUCH_FORMAT_SEXP:\r
+> - format = sprinter_sexp_create (config, stdout);\r
+> + o.format = sprinter_sexp_create (config, stdout);\r
+> break;\r
+> default:\r
+> /* this should never happen */\r
+> @@ -425,15 +427,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> return EXIT_FAILURE;\r
+> }\r
+> \r
+> - query = notmuch_query_create (notmuch, query_str);\r
+> - if (query == NULL) {\r
+> + o.query = notmuch_query_create (notmuch, query_str);\r
+> + if (o.query == NULL) {\r
+> fprintf (stderr, "Out of memory\n");\r
+> return EXIT_FAILURE;\r
+> }\r
+> \r
+> - notmuch_query_set_sort (query, sort);\r
+> + notmuch_query_set_sort (o.query, o.sort);\r
+> \r
+> - if (exclude == NOTMUCH_EXCLUDE_FLAG && output != OUTPUT_SUMMARY) {\r
+> + if (exclude == NOTMUCH_EXCLUDE_FLAG && o.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
+> @@ -448,29 +450,29 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+> search_exclude_tags = notmuch_config_get_search_exclude_tags\r
+> (config, &search_exclude_tags_length);\r
+> for (i = 0; i < search_exclude_tags_length; i++)\r
+> - notmuch_query_add_tag_exclude (query, search_exclude_tags[i]);\r
+> - notmuch_query_set_omit_excluded (query, exclude);\r
+> + notmuch_query_add_tag_exclude (o.query, search_exclude_tags[i]);\r
+> + notmuch_query_set_omit_excluded (o.query, exclude);\r
+> }\r
+> \r
+> - switch (output) {\r
+> + switch (o.output) {\r
+> default:\r
+> case OUTPUT_SUMMARY:\r
+> case OUTPUT_THREADS:\r
+> - ret = do_search_threads (format, query, sort, output, offset, limit);\r
+> + ret = do_search_threads (&o);\r
+> break;\r
+> case OUTPUT_MESSAGES:\r
+> case OUTPUT_FILES:\r
+> - ret = do_search_messages (format, query, output, offset, limit, dupe);\r
+> + ret = do_search_messages (&o);\r
+> break;\r
+> case OUTPUT_TAGS:\r
+> - ret = do_search_tags (notmuch, format, query);\r
+> + ret = do_search_tags (notmuch, o.format, o.query);\r
+\r
+It feels slightly strange to me to have do_search_tags taking a\r
+different argument style than the other two do_search_* functions so I\r
+would slightly prefer making it do_search_tags (&o).\r
+\r
+Obviously all of these are trivialities, so as I said above, I am happy\r
+to be overruled.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+\r
+> break;\r
+> }\r
+> \r
+> - notmuch_query_destroy (query);\r
+> + notmuch_query_destroy (o.query);\r
+> notmuch_database_destroy (notmuch);\r
+> \r
+> - talloc_free (format);\r
+> + talloc_free (o.format);\r
+> \r
+> return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
+> }\r
+> -- \r
+> 2.1.1\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r