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 60EB1431FBC
\r
6 for <notmuch@notmuchmail.org>; Sat, 21 Apr 2012 02:15:51 -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 H5-9Ih9dea3B for <notmuch@notmuchmail.org>;
\r
18 Sat, 21 Apr 2012 02:15:50 -0700 (PDT)
\r
19 Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com
\r
20 [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id A9B58431FB6
\r
23 for <notmuch@notmuchmail.org>; Sat, 21 Apr 2012 02:15:50 -0700 (PDT)
\r
24 Received: by wibhm17 with SMTP id hm17so1500624wib.2
\r
25 for <notmuch@notmuchmail.org>; Sat, 21 Apr 2012 02:15:49 -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=cMEMkQl84hgqEEbGER3D0fDqDiVeLs34d5ODtVbxQEg=;
\r
29 b=H5LmwuR31VkR/1b2a4FW2nM0QMNI/DW5uvMFUJbBIPTWyweAnPiL89jFvfRnQe4TOy
\r
30 XEoLWVj3AtpZhjxC7+OGVGU2a1CnU4Uun8IgYl3r3n/IbkxIwsX2I9M4YW8aVmcmhrOP
\r
31 gzLQYUn2OfbQVlqqRzt60JOqSbsXr4Xt+YzQb0rLJm7eCH2evdVHwSYwGqQWdvPOZnY9
\r
32 BXT5OdFoTy1EOtS+e0NKOf/CGnwLG4L7iK7/3c42OSLnPSuHiSsjxkPFX0fW4LLwqEA1
\r
33 tky1VMB53DkWHaCq0iKzj6SFbdZu7391AVPeyUmzpnG7ta38eo0Cq0f2jWCcAer0z+xj
\r
35 Received: by 10.216.133.93 with SMTP id p71mr5848232wei.10.1334999749293;
\r
36 Sat, 21 Apr 2012 02:15:49 -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 fz9sm4076829wib.3.2012.04.21.02.15.48 (version=TLSv1/SSLv3 cipher=OTHER);
\r
40 Sat, 21 Apr 2012 02:15:48 -0700 (PDT)
\r
41 From: Mark Walters <markwalters1009@gmail.com>
\r
42 To: notmuch@notmuchmail.org
\r
43 Subject: [PATCH v3 1/2] cli: make --entire-thread=false work for format=json.
\r
44 Date: Sat, 21 Apr 2012 10:15:49 +0100
\r
45 Message-Id: <1334999750-21811-2-git-send-email-markwalters1009@gmail.com>
\r
46 X-Mailer: git-send-email 1.7.9.1
\r
47 In-Reply-To: <1334999750-21811-1-git-send-email-markwalters1009@gmail.com>
\r
48 References: <1334999750-21811-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: Sat, 21 Apr 2012 09:15:51 -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 | 34 +++++++++++++++++++++++++++++-----
\r
78 1 files changed, 29 insertions(+), 5 deletions(-)
\r
80 diff --git a/notmuch-show.c b/notmuch-show.c
\r
81 index da4a797..327c263 100644
\r
82 --- a/notmuch-show.c
\r
83 +++ b/notmuch-show.c
\r
84 @@ -800,6 +800,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 @@ -862,11 +872,13 @@ show_messages (void *ctx,
\r
102 if (status && !res)
\r
104 next_indent = indent + 1;
\r
106 - if (!status && format->message_set_sep)
\r
107 - fputs (format->message_set_sep, stdout);
\r
109 + status = show_null_message (format);
\r
112 + if (!status && format->message_set_sep)
\r
113 + fputs (format->message_set_sep, stdout);
\r
115 status = show_messages (ctx,
\r
117 notmuch_message_get_replies (message),
\r
118 @@ -984,7 +996,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
119 char *query_string;
\r
120 int opt_index, ret;
\r
121 const notmuch_show_format_t *format = &format_text;
\r
122 - notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };
\r
124 + /* We abuse the notmuch_bool_t variable params.entire-thread by
\r
125 + * setting it to -1 to denote that the command line parsing has
\r
126 + * not set it. We ensure it is set to TRUE or FALSE before passing
\r
127 + * it to any other function.*/
\r
128 + notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };
\r
130 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
\r
131 notmuch_bool_t verify = FALSE;
\r
132 int exclude = EXCLUDE_TRUE;
\r
133 @@ -1024,7 +1042,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
134 switch (format_sel) {
\r
135 case NOTMUCH_FORMAT_JSON:
\r
136 format = &format_json;
\r
137 - params.entire_thread = TRUE;
\r
138 + /* JSON defaults to entire-thread TRUE */
\r
139 + if (params.entire_thread == -1)
\r
140 + params.entire_thread = TRUE;
\r
142 case NOTMUCH_FORMAT_TEXT:
\r
143 format = &format_text;
\r
144 @@ -1046,6 +1066,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
148 + /* Default is entire-thread = FALSE except for format=json which
\r
149 + * is dealt with above. */
\r
150 + if (params.entire_thread == -1)
\r
151 + params.entire_thread = FALSE;
\r
153 if (params.decrypt || verify) {
\r
154 #ifdef GMIME_ATLEAST_26
\r