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 7614C431FBC for ; Sat, 26 May 2012 02:25:52 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 9Zq92mnC86tJ for ; Sat, 26 May 2012 02:25:50 -0700 (PDT) Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 37828431FB6 for ; Sat, 26 May 2012 02:25:50 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1SYDFo-0005Bz-PL; Sat, 26 May 2012 10:25:45 +0100 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1SYDFo-00036t-Dp; Sat, 26 May 2012 10:25:44 +0100 From: Mark Walters To: Peter Wang , notmuch@notmuchmail.org Subject: Re: [PATCH v4 2/4] cli: make --entire-thread=false work for format=json. In-Reply-To: <20120526121556.GA2328@hili.localdomain> References: <1335258675-29439-1-git-send-email-markwalters1009@gmail.com> <1335258675-29439-3-git-send-email-markwalters1009@gmail.com> <20120526121556.GA2328@hili.localdomain> User-Agent: Notmuch/0.13+38~g35cb1c9 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Sat, 26 May 2012 09:28:20 +0100 Message-ID: <87txz3cpnf.fsf@qmul.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 94.192.233.223 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: 8e0b804157069eb4539fffdf6b43ef77 (of first 20000 bytes) X-SpamAssassin-Score: -1.8 X-SpamAssassin-SpamBar: - X-SpamAssassin-Report: The QM spam filters have analysed this message to determine if it is spam. We require at least 5.0 points to mark a message as spam. This message scored -1.8 points. Summary of the scoring: * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, * medium trust * [138.37.6.40 listed in list.dnswl.org] * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider * (markwalters1009[at]gmail.com) * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay * domain * 0.5 AWL AWL: From: address is in the auto white-list X-QM-Scan-Virus: ClamAV says the message is clean 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: Sat, 26 May 2012 09:25:52 -0000 On Sat, 26 May 2012, Peter Wang wrote: > On Tue, 24 Apr 2012 10:11:13 +0100, Mark Walters wrote: >> 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. >> --- >> notmuch-show.c | 16 ++++++++++++++-- >> 1 files changed, 14 insertions(+), 2 deletions(-) >> >> diff --git a/notmuch-show.c b/notmuch-show.c >> index 0d21f1a..48551bb 100644 >> --- a/notmuch-show.c >> +++ b/notmuch-show.c >> @@ -996,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; > > Hi Mark, > > As an alternative to the abuse, could you just treat it as with exclude, > using an enum with three values (TRUE|FALSE|DEFAULT)? > Then set params.entire_thread afterwards. The reason I haven't done this is that the current command line parser does not allow keyword options to take default values: in other words --entire-thread without an "=" would not be allowed. It is easy to change the keyword parsing code to allow this: I include a first draft of such a patch below. This would allow the solution you suggest and thus avoid the hack/abuse. What do people think? Best wishes Mark --- command-line-arguments.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/command-line-arguments.c b/command-line-arguments.c index 76b185f..d40c7e6 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -11,10 +11,16 @@ */ static notmuch_bool_t -_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) { +_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) { const notmuch_keyword_t *keywords = arg_desc->keywords; + if (next == 0) { +/* No keyword given so return first option as default */ + *((int *)arg_desc->output_var) = keywords->value; + return TRUE; + } + while (keywords->name) { if (strcmp (arg_str, keywords->name) == 0) { if (arg_desc->output_var) { @@ -99,7 +105,8 @@ parse_option (const char *arg, */ if (next != '=' && next != ':' && next != 0) return FALSE; if (next == 0) { - if (try->opt_type != NOTMUCH_OPT_BOOLEAN) + if (try->opt_type != NOTMUCH_OPT_BOOLEAN && + try->opt_type != NOTMUCH_OPT_KEYWORD) return FALSE; } else { if (value[0] == 0) return FALSE; @@ -110,7 +117,7 @@ parse_option (const char *arg, switch (try->opt_type) { case NOTMUCH_OPT_KEYWORD: - return _process_keyword_arg (try, value); + return _process_keyword_arg (try, next, value); break; case NOTMUCH_OPT_BOOLEAN: return _process_boolean_arg (try, next, value); -- 1.7.9.1