[PATCH 01/10] cli: search: Rename options to context
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 2 Nov 2014 00:49:51 +0000 (01:49 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:06:03 +0000 (10:06 -0800)
c6/5ae51dc69009c7555542f33959e4547fe3ace2 [new file with mode: 0644]

diff --git a/c6/5ae51dc69009c7555542f33959e4547fe3ace2 b/c6/5ae51dc69009c7555542f33959e4547fe3ace2
new file mode 100644 (file)
index 0000000..0b30621
--- /dev/null
@@ -0,0 +1,432 @@
+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 77A45431FD7\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 17:50:18 -0700 (PDT)\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 HcBMHicGj9ag for <notmuch@notmuchmail.org>;\r
+       Sat,  1 Nov 2014 17:50:13 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 8048C431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 17:50:12 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id E4A9B5CD296\r
+       for <notmuch@notmuchmail.org>; Sun,  2 Nov 2014 01:50:10 +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 jolsYzbIJnZ3 for <notmuch@notmuchmail.org>;\r
+       Sun,  2 Nov 2014 01:50:06 +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 16D5C5CD288\r
+       for <notmuch@notmuchmail.org>; Sun,  2 Nov 2014 01:50:05 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1XkjMq-00084n-DY; Sun, 02 Nov 2014 01:50:04 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 01/10] cli: search: Rename options to context\r
+Date: Sun,  2 Nov 2014 01:49:51 +0100\r
+Message-Id: <1414889400-30977-2-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414889400-30977-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1414889400-30977-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: Sun, 02 Nov 2014 00:50:18 -0000\r
+\r
+Just text replacement, no other changes.\r
+---\r
+ notmuch-search.c | 136 +++++++++++++++++++++++++++----------------------------\r
+ 1 file changed, 68 insertions(+), 68 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 671fe41..c354ddc 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -42,7 +42,7 @@ typedef struct {\r
+     int offset;\r
+     int limit;\r
+     int dupe;\r
+-} search_options_t;\r
++} search_context_t;\r
\r
+ typedef struct {\r
+     const char *name;\r
+@@ -89,39 +89,39 @@ get_thread_query (notmuch_thread_t *thread,\r
+ }\r
\r
+ static int\r
+-do_search_threads (search_options_t *opt)\r
++do_search_threads (search_context_t *ctx)\r
+ {\r
+     notmuch_thread_t *thread;\r
+     notmuch_threads_t *threads;\r
+     notmuch_tags_t *tags;\r
+-    sprinter_t *format = opt->format;\r
++    sprinter_t *format = ctx->format;\r
+     time_t date;\r
+     int i;\r
\r
+-    if (opt->offset < 0) {\r
+-      opt->offset += notmuch_query_count_threads (opt->query);\r
+-      if (opt->offset < 0)\r
+-          opt->offset = 0;\r
++    if (ctx->offset < 0) {\r
++      ctx->offset += notmuch_query_count_threads (ctx->query);\r
++      if (ctx->offset < 0)\r
++          ctx->offset = 0;\r
+     }\r
\r
+-    threads = notmuch_query_search_threads (opt->query);\r
++    threads = notmuch_query_search_threads (ctx->query);\r
+     if (threads == NULL)\r
+       return 1;\r
\r
+     format->begin_list (format);\r
\r
+     for (i = 0;\r
+-       notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
++       notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);\r
+        notmuch_threads_move_to_next (threads), i++)\r
+     {\r
+       thread = notmuch_threads_get (threads);\r
\r
+-      if (i < opt->offset) {\r
++      if (i < ctx->offset) {\r
+           notmuch_thread_destroy (thread);\r
+           continue;\r
+       }\r
\r
+-      if (opt->output == OUTPUT_THREADS) {\r
++      if (ctx->output == OUTPUT_THREADS) {\r
+           format->set_prefix (format, "thread");\r
+           format->string (format,\r
+                           notmuch_thread_get_thread_id (thread));\r
+@@ -138,7 +138,7 @@ do_search_threads (search_options_t *opt)\r
\r
+           format->begin_map (format);\r
\r
+-          if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
++          if (ctx->sort == NOTMUCH_SORT_OLDEST_FIRST)\r
+               date = notmuch_thread_get_oldest_date (thread);\r
+           else\r
+               date = notmuch_thread_get_newest_date (thread);\r
+@@ -230,11 +230,11 @@ do_search_threads (search_options_t *opt)\r
+ }\r
\r
+ static void\r
+-print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
++print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)\r
+ {\r
+     const char *name = mailbox->name;\r
+     const char *addr = mailbox->addr;\r
+-    sprinter_t *format = opt->format;\r
++    sprinter_t *format = ctx->format;\r
+     InternetAddress *ia = internet_address_mailbox_new (name, addr);\r
+     char *name_addr;\r
\r
+@@ -263,7 +263,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)\r
\r
+ /* Print addresses from InternetAddressList.  */\r
+ static void\r
+-process_address_list (const search_options_t *opt, InternetAddressList *list)\r
++process_address_list (const search_context_t *ctx, InternetAddressList *list)\r
+ {\r
+     InternetAddress *address;\r
+     int i;\r
+@@ -279,7 +279,7 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)\r
+           if (group_list == NULL)\r
+               continue;\r
\r
+-          process_address_list (opt, group_list);\r
++          process_address_list (ctx, group_list);\r
+       } else {\r
+           InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
+           mailbox_t mbx = {\r
+@@ -287,14 +287,14 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)\r
+               .addr = internet_address_mailbox_get_addr (mailbox),\r
+           };\r
\r
+-          print_mailbox (opt, &mbx);\r
++          print_mailbox (ctx, &mbx);\r
+       }\r
+     }\r
+ }\r
\r
+ /* Print addresses from a message header.  */\r
+ static void\r
+-process_address_header (const search_options_t *opt, const char *value)\r
++process_address_header (const search_context_t *ctx, const char *value)\r
+ {\r
+     InternetAddressList *list;\r
\r
+@@ -305,42 +305,42 @@ process_address_header (const search_options_t *opt, const char *value)\r
+     if (list == NULL)\r
+       return;\r
\r
+-    process_address_list (opt, list);\r
++    process_address_list (ctx, list);\r
\r
+     g_object_unref (list);\r
+ }\r
\r
+ static int\r
+-do_search_messages (search_options_t *opt)\r
++do_search_messages (search_context_t *ctx)\r
+ {\r
+     notmuch_message_t *message;\r
+     notmuch_messages_t *messages;\r
+     notmuch_filenames_t *filenames;\r
+-    sprinter_t *format = opt->format;\r
++    sprinter_t *format = ctx->format;\r
+     int i;\r
\r
+-    if (opt->offset < 0) {\r
+-      opt->offset += notmuch_query_count_messages (opt->query);\r
+-      if (opt->offset < 0)\r
+-          opt->offset = 0;\r
++    if (ctx->offset < 0) {\r
++      ctx->offset += notmuch_query_count_messages (ctx->query);\r
++      if (ctx->offset < 0)\r
++          ctx->offset = 0;\r
+     }\r
\r
+-    messages = notmuch_query_search_messages (opt->query);\r
++    messages = notmuch_query_search_messages (ctx->query);\r
+     if (messages == NULL)\r
+       return 1;\r
\r
+     format->begin_list (format);\r
\r
+     for (i = 0;\r
+-       notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);\r
++       notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);\r
+        notmuch_messages_move_to_next (messages), i++)\r
+     {\r
+-      if (i < opt->offset)\r
++      if (i < ctx->offset)\r
+           continue;\r
\r
+       message = notmuch_messages_get (messages);\r
\r
+-      if (opt->output == OUTPUT_FILES) {\r
++      if (ctx->output == OUTPUT_FILES) {\r
+           int j;\r
+           filenames = notmuch_message_get_filenames (message);\r
\r
+@@ -348,7 +348,7 @@ do_search_messages (search_options_t *opt)\r
+                notmuch_filenames_valid (filenames);\r
+                notmuch_filenames_move_to_next (filenames), j++)\r
+           {\r
+-              if (opt->dupe < 0 || opt->dupe == j) {\r
++              if (ctx->dupe < 0 || ctx->dupe == j) {\r
+                   format->string (format, notmuch_filenames_get (filenames));\r
+                   format->separator (format);\r
+               }\r
+@@ -356,27 +356,27 @@ do_search_messages (search_options_t *opt)\r
+           \r
+           notmuch_filenames_destroy( filenames );\r
\r
+-      } else if (opt->output == OUTPUT_MESSAGES) {\r
++      } else if (ctx->output == OUTPUT_MESSAGES) {\r
+           format->set_prefix (format, "id");\r
+           format->string (format,\r
+                           notmuch_message_get_message_id (message));\r
+           format->separator (format);\r
+       } else {\r
+-          if (opt->output & OUTPUT_SENDER) {\r
++          if (ctx->output & OUTPUT_SENDER) {\r
+               const char *addrs;\r
\r
+               addrs = notmuch_message_get_header (message, "from");\r
+-              process_address_header (opt, addrs);\r
++              process_address_header (ctx, addrs);\r
+           }\r
\r
+-          if (opt->output & OUTPUT_RECIPIENTS) {\r
++          if (ctx->output & OUTPUT_RECIPIENTS) {\r
+               const char *hdrs[] = { "to", "cc", "bcc" };\r
+               const char *addrs;\r
+               size_t j;\r
\r
+               for (j = 0; j < ARRAY_SIZE (hdrs); j++) {\r
+                   addrs = notmuch_message_get_header (message, hdrs[j]);\r
+-                  process_address_header (opt, addrs);\r
++                  process_address_header (ctx, addrs);\r
+               }\r
+           }\r
+       }\r
+@@ -393,13 +393,13 @@ do_search_messages (search_options_t *opt)\r
\r
+ static int\r
+ do_search_tags (notmuch_database_t *notmuch,\r
+-              const search_options_t *opt)\r
++              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 = opt->format;\r
+-    notmuch_query_t *query = opt->query;\r
++    sprinter_t *format = ctx->format;\r
++    notmuch_query_t *query = ctx->query;\r
\r
+     /* should the following only special case if no excluded terms\r
+      * specified? */\r
+@@ -444,7 +444,7 @@ int\r
+ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+     notmuch_database_t *notmuch;\r
+-    search_options_t opt = {\r
++    search_context_t ctx = {\r
+       .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
+       .output = 0,\r
+       .offset = 0,\r
+@@ -464,7 +464,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, &opt.sort, "sort", 's',\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
+@@ -475,7 +475,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+                                 { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+                                 { 0, 0 } } },\r
+       { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
+-      { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
++      { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx.output, "output", 'o',\r
+         (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
+                                 { "threads", OUTPUT_THREADS },\r
+                                 { "messages", OUTPUT_MESSAGES },\r
+@@ -490,9 +490,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, &opt.offset, "offset", 'O', 0 },\r
+-      { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0  },\r
+-      { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0  },\r
++      { NOTMUCH_OPT_INT, &ctx.offset, "offset", 'O', 0 },\r
++      { NOTMUCH_OPT_INT, &ctx.limit, "limit", 'L', 0  },\r
++      { NOTMUCH_OPT_INT, &ctx.dupe, "duplicate", 'D', 0  },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -500,25 +500,25 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+     if (opt_index < 0)\r
+       return EXIT_FAILURE;\r
\r
+-    if (! opt.output)\r
+-      opt.output = OUTPUT_SUMMARY;\r
++    if (! ctx.output)\r
++      ctx.output = OUTPUT_SUMMARY;\r
\r
+     switch (format_sel) {\r
+     case NOTMUCH_FORMAT_TEXT:\r
+-      opt.format = sprinter_text_create (config, stdout);\r
++      ctx.format = sprinter_text_create (config, stdout);\r
+       break;\r
+     case NOTMUCH_FORMAT_TEXT0:\r
+-      if (opt.output == OUTPUT_SUMMARY) {\r
++      if (ctx.output == OUTPUT_SUMMARY) {\r
+           fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
+           return EXIT_FAILURE;\r
+       }\r
+-      opt.format = sprinter_text0_create (config, stdout);\r
++      ctx.format = sprinter_text0_create (config, stdout);\r
+       break;\r
+     case NOTMUCH_FORMAT_JSON:\r
+-      opt.format = sprinter_json_create (config, stdout);\r
++      ctx.format = sprinter_json_create (config, stdout);\r
+       break;\r
+     case NOTMUCH_FORMAT_SEXP:\r
+-      opt.format = sprinter_sexp_create (config, stdout);\r
++      ctx.format = sprinter_sexp_create (config, stdout);\r
+       break;\r
+     default:\r
+       /* this should never happen */\r
+@@ -541,15 +541,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+       return EXIT_FAILURE;\r
+     }\r
\r
+-    opt.query = notmuch_query_create (notmuch, query_str);\r
+-    if (opt.query == NULL) {\r
++    ctx.query = notmuch_query_create (notmuch, query_str);\r
++    if (ctx.query == NULL) {\r
+       fprintf (stderr, "Out of memory\n");\r
+       return EXIT_FAILURE;\r
+     }\r
\r
+-    notmuch_query_set_sort (opt.query, opt.sort);\r
++    notmuch_query_set_sort (ctx.query, ctx.sort);\r
\r
+-    if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {\r
++    if (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
+@@ -564,28 +564,28 @@ 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 (opt.query, search_exclude_tags[i]);\r
+-      notmuch_query_set_omit_excluded (opt.query, exclude);\r
++          notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);\r
++      notmuch_query_set_omit_excluded (ctx.query, exclude);\r
+     }\r
\r
+-    if (opt.output == OUTPUT_SUMMARY ||\r
+-      opt.output == OUTPUT_THREADS)\r
+-      ret = do_search_threads (&opt);\r
+-    else if (opt.output == OUTPUT_MESSAGES ||\r
+-           opt.output == OUTPUT_FILES ||\r
+-           (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))\r
+-      ret = do_search_messages (&opt);\r
+-    else if (opt.output == OUTPUT_TAGS)\r
+-      ret = do_search_tags (notmuch, &opt);\r
++    if (ctx.output == OUTPUT_SUMMARY ||\r
++      ctx.output == OUTPUT_THREADS)\r
++      ret = do_search_threads (&ctx);\r
++    else if (ctx.output == OUTPUT_MESSAGES ||\r
++           ctx.output == OUTPUT_FILES ||\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
+     else {\r
+       fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
+       ret = 1;\r
+     }\r
\r
+-    notmuch_query_destroy (opt.query);\r
++    notmuch_query_destroy (ctx.query);\r
+     notmuch_database_destroy (notmuch);\r
\r
+-    talloc_free (opt.format);\r
++    talloc_free (ctx.format);\r
\r
+     return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
+ }\r
+-- \r
+2.1.1\r
+\r