From: Austin Clements Date: Tue, 24 Apr 2012 01:47:53 +0000 (+2000) Subject: Re: [PATCH v3 1/2] cli: make --entire-thread=false work for format=json. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=437b6bc2719ee4a1c75a9864aa75555d1ac6135f;p=notmuch-archives.git Re: [PATCH v3 1/2] cli: make --entire-thread=false work for format=json. --- diff --git a/05/71942e5ad5c8cc25090fea51d6f8e5cf082a58 b/05/71942e5ad5c8cc25090fea51d6f8e5cf082a58 new file mode 100644 index 000000000..a0375edba --- /dev/null +++ b/05/71942e5ad5c8cc25090fea51d6f8e5cf082a58 @@ -0,0 +1,188 @@ +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 D5379431FAF + for ; Mon, 23 Apr 2012 18:47:57 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 HANXb8D-7IG6 for ; + Mon, 23 Apr 2012 18:47:57 -0700 (PDT) +Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU + [18.7.68.34]) + by olra.theworths.org (Postfix) with ESMTP id 1BF43431FAE + for ; Mon, 23 Apr 2012 18:47:57 -0700 (PDT) +X-AuditID: 12074422-b7fd66d0000008f9-b8-4f96064ba3c2 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP + id 42.B5.02297.B46069F4; Mon, 23 Apr 2012 21:47:55 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3O1ltuf005880; + Mon, 23 Apr 2012 21:47:55 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3O1ls3u028479 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Mon, 23 Apr 2012 21:47:54 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SMUrB-0004An-Qz; Mon, 23 Apr 2012 21:47:53 -0400 +Date: Mon, 23 Apr 2012 21:47:53 -0400 +From: Austin Clements +To: Mark Walters +Subject: Re: [PATCH v3 1/2] cli: make --entire-thread=false work for + format=json. +Message-ID: <20120424014753.GI17810@mit.edu> +References: <1334999750-21811-1-git-send-email-markwalters1009@gmail.com> + <1334999750-21811-2-git-send-email-markwalters1009@gmail.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1334999750-21811-2-git-send-email-markwalters1009@gmail.com> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42IRYrdT1/Vmm+ZvMOeGlsXquTwW12/OZHZg + 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MibcX8BW8FehomfWTcYGxn2SXYycHBICJhKr + P09ngrDFJC7cW8/WxcjFISSwj1Fi/u+Z7BDOBkaJGW+amEGqhAROMkmsOmkCkVjCKPHq2R8W + kASLgKrE6q1fWUFsNgENiW37lzOC2CICOhK3Dy1gB7GZBaQlvv1uBlsnLBAs8XntWrB6XqCa + vQ3zGSGGdjJKLF5+hA0iIShxcuYTFohmLYkb/14CNXOADVr+jwMkzCngJfH1ym+w+aICKhJT + Tm5jm8AoNAtJ9ywk3bMQuhcwMq9ilE3JrdLNTczMKU5N1i1OTszLSy3SNdXLzSzRS00p3cQI + DmsXpR2MPw8qHWIU4GBU4uHNTJ/qL8SaWFZcmXuIUZKDSUmUl591mr8QX1J+SmVGYnFGfFFp + TmrxIUYJDmYlEd5H/4HKeVMSK6tSi/JhUtIcLErivOpa7/yEBNITS1KzU1MLUotgsjIcHEoS + vPEgQwWLUtNTK9Iyc0oQ0kwcnCDDeYCGTwGp4S0uSMwtzkyHyJ9i1OW49uXoFUYhlrz8vFQp + cd5CkCIBkKKM0jy4ObB09IpRHOgtYd5YkCoeYCqDm/QKaAkT0JKEmEkgS0oSEVJSDYwTav1L + 3MPqsv4WrrAxDj7SeOiD1vankQ1fTjD89fjfnNlUY1BX3MbLv4At8ewGCRm3vrbHKQKsW78t + 3zPnpP/N8Fy9m4sbjdf8658U5i+dZbPvAbPEserCFwJdrYseTzkicfi2QkT25AaZC6uTvDzD + Pb5mGLumWBcemXE8XKlUMsXg0SxbASWW4oxEQy3mouJEAP73LbYiAwAA +Cc: notmuch@notmuchmail.org +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, 24 Apr 2012 01:47:58 -0000 + +Quoth Mark Walters on Apr 21 at 10:15 am: +> 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 | 34 +++++++++++++++++++++++++++++----- +> 1 files changed, 29 insertions(+), 5 deletions(-) +> +> diff --git a/notmuch-show.c b/notmuch-show.c +> index da4a797..327c263 100644 +> --- a/notmuch-show.c +> +++ b/notmuch-show.c +> @@ -800,6 +800,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) + +This should probably be specified as a field in the format, rather +than using a hard-coded dispatch. It could even be a plain string +field that you could fputs in show_messages. + +> + printf ("{}"); + +This is a definite improvement over the current strangeness, but I +think 'null' would be better than an empty object. null is a clearly +distinguished value, rather than something that initially has a +message-like type, but then isn't a message. + +You should also update devel/schemata to reflect this change. + +> + return NOTMUCH_STATUS_SUCCESS; +> +} +> + +> +static notmuch_status_t +> show_message (void *ctx, +> const notmuch_show_format_t *format, +> notmuch_message_t *message, +> @@ -862,11 +872,13 @@ show_messages (void *ctx, +> if (status && !res) +> res = status; +> next_indent = indent + 1; +> - +> - if (!status && format->message_set_sep) +> - fputs (format->message_set_sep, stdout); +> + } else { +> + status = show_null_message (format); +> } +> +> + if (!status && format->message_set_sep) +> + fputs (format->message_set_sep, stdout); +> + +> status = show_messages (ctx, +> format, +> notmuch_message_get_replies (message), + +I believe the stuff above could be a separate patch from the stuff +below. + +> @@ -984,7 +996,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; +> @@ -1024,7 +1042,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; +> @@ -1046,6 +1066,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