[PATCH 1/2] cli: make --entire-thread=false work for format=json.
authorMark Walters <markwalters1009@gmail.com>
Tue, 10 Apr 2012 17:04:55 +0000 (18:04 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:13 +0000 (09:46 -0800)
1c/d9afb803bb79091b015877e4108f269b822740 [new file with mode: 0644]

diff --git a/1c/d9afb803bb79091b015877e4108f269b822740 b/1c/d9afb803bb79091b015877e4108f269b822740
new file mode 100644 (file)
index 0000000..27b5895
--- /dev/null
@@ -0,0 +1,155 @@
+Return-Path: <markwalters1009@gmail.com>\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 B25CA431FB6\r
+       for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:59 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] 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 HKvkPHQNbpDD for <notmuch@notmuchmail.org>;\r
+       Tue, 10 Apr 2012 10:04:58 -0700 (PDT)\r
+Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com\r
+ [74.125.82.41])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ D30F0431FAF   for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:57 -0700\r
+ (PDT)\r
+Received: by wgbds1 with SMTP id ds1so3394255wgb.2\r
+       for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:56 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=RPrshy2e/jjpTCkMrtT1GxzO9wJrz1BfVWQ9Jq4wPbc=;\r
+       b=muKXekGqZf3AlA8ELw1pl0uY0hXn2auaZSh7GdnCB52erX+qBkmFAW56emBrhzyALI\r
+       P+4hiPiD0UMcwwZC6SLiJ8L1xVCylcqoe8IPQEAQq6moUXnE3SGrji4BfNTGuAlJgg5e\r
+       2Ra3gAqmi5Y+DyFyRnEqqd9Mojpy7t7AZqMTIfkeQdBamx8lR3JcbEEAH5uU3QD8vxby\r
+       KLzRLNzmDMRG3ASl1jeJYZWyW1yu+ve5sVUBlrlU1kCwvamhxZbQXQGrLN/CN86LaKLY\r
+       J+5vcq0MM/8CxXyZoXP0TiIu/X3Ebb0Tl/TQ+XcwujwDPzVWpsDZuu+/0nS1Rbeo66yk\r
+       W/pw==\r
+Received: by 10.180.80.104 with SMTP id q8mr8773395wix.14.1334077496565;\r
+       Tue, 10 Apr 2012 10:04:56 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ n20sm62917290wiw.5.2012.04.10.10.04.55        (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 10 Apr 2012 10:04:55 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] cli: make --entire-thread=false work for format=json.\r
+Date: Tue, 10 Apr 2012 18:04:55 +0100\r
+Message-Id: <1334077496-9172-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1334077496-9172-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1334077496-9172-1-git-send-email-markwalters1009@gmail.com>\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: Tue, 10 Apr 2012 17:05:00 -0000\r
+\r
+The --entire-thread option in notmuch-show.c defaults to true when\r
+format=json. Previously there was no way to turn this off. This patch\r
+makes it respect --entire-thread=false.\r
+\r
+The one subtlety is that we initialise a notmuch_bool_t to -1 to\r
+indicate that the option parsing has not set it. This allows the code\r
+to distinguish between the option being omitted from the command line,\r
+and the option being set to false on the command line.\r
+\r
+Finally, all formats except Json can output empty messages for non\r
+entire-thread, but in Json format we need to output {} to keep the\r
+other elements (e.g. the replies to this message) in the correct\r
+place.\r
+---\r
+ notmuch-show.c |   33 ++++++++++++++++++++++++++++-----\r
+ 1 files changed, 28 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 7af8e64..5d58bfd 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -809,6 +809,16 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,\r
+ }\r
\r
+ static notmuch_status_t\r
++show_null_message (const notmuch_show_format_t *format)\r
++{\r
++    /* For all formats except json an empty message output is valid;\r
++     * for json we need the braces.*/\r
++    if (format == &format_json)\r
++      printf ("{}");\r
++    return NOTMUCH_STATUS_SUCCESS;\r
++}\r
++\r
++static notmuch_status_t\r
+ show_message (void *ctx,\r
+             const notmuch_show_format_t *format,\r
+             notmuch_message_t *message,\r
+@@ -895,10 +905,11 @@ show_messages (void *ctx,\r
+           if (status && !res)\r
+               res = status;\r
+           next_indent = indent + 1;\r
++      } else\r
++          status = show_null_message (format);\r
\r
+-          if (!status)\r
+-              fputs (format->message_set_sep, stdout);\r
+-      }\r
++      if (!status)\r
++          fputs (format->message_set_sep, stdout);\r
\r
+       status = show_messages (ctx,\r
+                               format,\r
+@@ -1013,7 +1024,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+     char *query_string;\r
+     int opt_index, ret;\r
+     const notmuch_show_format_t *format = &format_text;\r
+-    notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };\r
++\r
++    /* We abuse the notmuch_bool_t variable params.entire-thread by\r
++     * setting it to -1 to denote that the command line parsing has\r
++     * not set it. We ensure it is set to TRUE or FALSE before passing\r
++     * it to any other function.*/\r
++    notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };\r
++\r
+     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
+     notmuch_bool_t verify = FALSE;\r
+     int exclude = EXCLUDE_TRUE;\r
+@@ -1053,7 +1070,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+     switch (format_sel) {\r
+     case NOTMUCH_FORMAT_JSON:\r
+       format = &format_json;\r
+-      params.entire_thread = TRUE;\r
++      /* JSON defaults to entire-thread TRUE */\r
++      if (params.entire_thread == -1)\r
++          params.entire_thread = TRUE;\r
+       break;\r
+     case NOTMUCH_FORMAT_TEXT:\r
+       format = &format_text;\r
+@@ -1075,6 +1094,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+       params.raw = TRUE;\r
+       break;\r
+     }\r
++    /* Default is entire-thread = FALSE except for format=json which\r
++     * is dealt with above. */\r
++    if (params.entire_thread == -1)\r
++      params.entire_thread = FALSE;\r
\r
+     if (params.decrypt || verify) {\r
+ #ifdef GMIME_ATLEAST_26\r
+-- \r
+1.7.9.1\r
+\r