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