1 Return-Path: <markwalters1009@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id B25CA431FB6
\r
6 for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id HKvkPHQNbpDD for <notmuch@notmuchmail.org>;
\r
18 Tue, 10 Apr 2012 10:04:58 -0700 (PDT)
\r
19 Received: from mail-wg0-f41.google.com (mail-wg0-f41.google.com
\r
20 [74.125.82.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 D30F0431FAF for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:57 -0700
\r
24 Received: by wgbds1 with SMTP id ds1so3394255wgb.2
\r
25 for <notmuch@notmuchmail.org>; Tue, 10 Apr 2012 10:04:56 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;
\r
28 bh=RPrshy2e/jjpTCkMrtT1GxzO9wJrz1BfVWQ9Jq4wPbc=;
\r
29 b=muKXekGqZf3AlA8ELw1pl0uY0hXn2auaZSh7GdnCB52erX+qBkmFAW56emBrhzyALI
\r
30 P+4hiPiD0UMcwwZC6SLiJ8L1xVCylcqoe8IPQEAQq6moUXnE3SGrji4BfNTGuAlJgg5e
\r
31 2Ra3gAqmi5Y+DyFyRnEqqd9Mojpy7t7AZqMTIfkeQdBamx8lR3JcbEEAH5uU3QD8vxby
\r
32 KLzRLNzmDMRG3ASl1jeJYZWyW1yu+ve5sVUBlrlU1kCwvamhxZbQXQGrLN/CN86LaKLY
\r
33 J+5vcq0MM/8CxXyZoXP0TiIu/X3Ebb0Tl/TQ+XcwujwDPzVWpsDZuu+/0nS1Rbeo66yk
\r
35 Received: by 10.180.80.104 with SMTP id q8mr8773395wix.14.1334077496565;
\r
36 Tue, 10 Apr 2012 10:04:56 -0700 (PDT)
\r
37 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.
\r
38 [94.192.233.223]) by mx.google.com with ESMTPS id
\r
39 n20sm62917290wiw.5.2012.04.10.10.04.55 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Tue, 10 Apr 2012 10:04:55 -0700 (PDT)
\r
41 From: Mark Walters <markwalters1009@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH 1/2] cli: make --entire-thread=false work for format=json.
\r
44 Date: Tue, 10 Apr 2012 18:04:55 +0100
\r
45 Message-Id: <1334077496-9172-2-git-send-email-markwalters1009@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.9.1
\r
47 In-Reply-To: <1334077496-9172-1-git-send-email-markwalters1009@gmail.com>
\r
48 References: <1334077496-9172-1-git-send-email-markwalters1009@gmail.com>
\r
49 X-BeenThere: notmuch@notmuchmail.org
\r
50 X-Mailman-Version: 2.1.13
\r
52 List-Id: "Use and development of the notmuch mail system."
\r
53 <notmuch.notmuchmail.org>
\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
57 List-Post: <mailto:notmuch@notmuchmail.org>
\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
61 X-List-Received-Date: Tue, 10 Apr 2012 17:05:00 -0000
\r
63 The --entire-thread option in notmuch-show.c defaults to true when
\r
64 format=json. Previously there was no way to turn this off. This patch
\r
65 makes it respect --entire-thread=false.
\r
67 The one subtlety is that we initialise a notmuch_bool_t to -1 to
\r
68 indicate that the option parsing has not set it. This allows the code
\r
69 to distinguish between the option being omitted from the command line,
\r
70 and the option being set to false on the command line.
\r
72 Finally, all formats except Json can output empty messages for non
\r
73 entire-thread, but in Json format we need to output {} to keep the
\r
74 other elements (e.g. the replies to this message) in the correct
\r
77 notmuch-show.c | 33 ++++++++++++++++++++++++++++-----
\r
78 1 files changed, 28 insertions(+), 5 deletions(-)
\r
80 diff --git a/notmuch-show.c b/notmuch-show.c
\r
81 index 7af8e64..5d58bfd 100644
\r
82 --- a/notmuch-show.c
\r
83 +++ b/notmuch-show.c
\r
84 @@ -809,6 +809,16 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
\r
87 static notmuch_status_t
\r
88 +show_null_message (const notmuch_show_format_t *format)
\r
90 + /* For all formats except json an empty message output is valid;
\r
91 + * for json we need the braces.*/
\r
92 + if (format == &format_json)
\r
94 + return NOTMUCH_STATUS_SUCCESS;
\r
97 +static notmuch_status_t
\r
98 show_message (void *ctx,
\r
99 const notmuch_show_format_t *format,
\r
100 notmuch_message_t *message,
\r
101 @@ -895,10 +905,11 @@ show_messages (void *ctx,
\r
102 if (status && !res)
\r
104 next_indent = indent + 1;
\r
106 + status = show_null_message (format);
\r
109 - fputs (format->message_set_sep, stdout);
\r
112 + fputs (format->message_set_sep, stdout);
\r
114 status = show_messages (ctx,
\r
116 @@ -1013,7 +1024,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
117 char *query_string;
\r
118 int opt_index, ret;
\r
119 const notmuch_show_format_t *format = &format_text;
\r
120 - notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };
\r
122 + /* We abuse the notmuch_bool_t variable params.entire-thread by
\r
123 + * setting it to -1 to denote that the command line parsing has
\r
124 + * not set it. We ensure it is set to TRUE or FALSE before passing
\r
125 + * it to any other function.*/
\r
126 + notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };
\r
128 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
\r
129 notmuch_bool_t verify = FALSE;
\r
130 int exclude = EXCLUDE_TRUE;
\r
131 @@ -1053,7 +1070,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
132 switch (format_sel) {
\r
133 case NOTMUCH_FORMAT_JSON:
\r
134 format = &format_json;
\r
135 - params.entire_thread = TRUE;
\r
136 + /* JSON defaults to entire-thread TRUE */
\r
137 + if (params.entire_thread == -1)
\r
138 + params.entire_thread = TRUE;
\r
140 case NOTMUCH_FORMAT_TEXT:
\r
141 format = &format_text;
\r
142 @@ -1075,6 +1094,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
146 + /* Default is entire-thread = FALSE except for format=json which
\r
147 + * is dealt with above. */
\r
148 + if (params.entire_thread == -1)
\r
149 + params.entire_thread = FALSE;
\r
151 if (params.decrypt || verify) {
\r
152 #ifdef GMIME_ATLEAST_26
\r