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 7A4FF431FAF for ; Mon, 10 Dec 2012 12:55:50 -0800 (PST) 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 i6abP2XVGI9D for ; Mon, 10 Dec 2012 12:55:49 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id AC333431FAE for ; Mon, 10 Dec 2012 12:55:48 -0800 (PST) Received: by mail-lb0-f181.google.com with SMTP id ge1so2496075lbb.26 for ; Mon, 10 Dec 2012 12:55:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type:x-gm-message-state; bh=t6QTYV8wUx4QMjir4HXFW7csFS98jCjdzEupR11oFZY=; b=M3HuzKO3X9FUCyWWb9HA7cEnIkRQRRUupH8/AdXycISL74a7SmfznthxzbietyG8ZD YwKKbDPnGYxWLXws+DO6UpiMyI37ed/bjwXZkkVawE+PUimLoaHZ6PQsxxlXpU+kIw9f G0bkkAfD/dz1YDV3tPjnd9sZG78wxyhPV4k8a4YuF+EBEieY0XjKKHCm1PYFq+fnozoF X0FQMig/pYT5m3ejrxrJuyApevCSSKda0S19HZ+glvoSjFp6MqbdJ/mbGH7aiYzRG0If gic1k0tGxWQqjH3ZCxR64HiScJh/BjjxQF4s7RiC4aFEoSUXs/HXKS9VlzCrsTNrSdL9 rQpg== Received: by 10.152.114.66 with SMTP id je2mr746231lab.40.1355172945474; Mon, 10 Dec 2012 12:55:45 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id u9sm8403986lbf.5.2012.12.10.12.55.42 (version=SSLv3 cipher=OTHER); Mon, 10 Dec 2012 12:55:43 -0800 (PST) From: Jani Nikula To: david@tethera.net, notmuch@notmuchmail.org Subject: Re: [Patch v6 1/6] tag-util: factor out rules for illegal tags, use in parse_tag_line In-Reply-To: <1355096008-4544-2-git-send-email-david@tethera.net> References: <1355096008-4544-1-git-send-email-david@tethera.net> <1355096008-4544-2-git-send-email-david@tethera.net> User-Agent: Notmuch/0.14+138~g7041c56 (http://notmuchmail.org) Emacs/23.4.1 (i686-pc-linux-gnu) Date: Mon, 10 Dec 2012 22:55:38 +0200 Message-ID: <87mwxlaaph.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Gm-Message-State: ALoCoQkGcxQwA1nxCb36bv7uSKIzHFJe7vZmElv6Cs8hW/mkSdr8PvAF+3jBpWnUvkdVtB9/do7X Cc: David Bremner 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: Mon, 10 Dec 2012 20:55:50 -0000 On Mon, 10 Dec 2012, david@tethera.net wrote: > From: David Bremner > > This will allow us to be consistent between batch tagging and command > line tagging as far as what is an illegal tag. LGTM, with some nitpick and observations below. Jani. > --- > tag-util.c | 35 ++++++++++++++++++++++++++++++----- > 1 file changed, 30 insertions(+), 5 deletions(-) > > diff --git a/tag-util.c b/tag-util.c > index eab482f..c071ea8 100644 > --- a/tag-util.c > +++ b/tag-util.c > @@ -31,6 +31,29 @@ line_error (tag_parse_status_t status, > return status; > } > > +/* > + * Test tags for some forbidden cases. > + * > + * return: NULL if OK, > + * explanatory message otherwise. > + */ > + > +static const char * > +illegal_tag (const char *tag, notmuch_bool_t remove) { Add \n before opening brace. > + > + if (*tag == '\0' && !remove) > + return "adding empty tag"; > + > + /* This disallows adding the non-removable tag "-" and > + * enables notmuch tag to take long options more easily. > + */ Maybe make that: "This disallows adding tags starting with "-", including the non-removable tag "-", and enables ...", or similar? > + > + if (*tag == '-' && !remove) > + return "adding tag starting with -"; > + > + return NULL; > +} > + > tag_parse_status_t > parse_tag_line (void *ctx, char *line, > tag_op_flag_t flags, > @@ -95,11 +118,13 @@ parse_tag_line (void *ctx, char *line, > remove = (*tok == '-'); > tag = tok + 1; > > - /* Maybe refuse empty tags. */ > - if (! (flags & TAG_FLAG_BE_GENEROUS) && *tag == '\0') { > - ret = line_error (TAG_PARSE_INVALID, line_for_error, > - "empty tag"); > - goto DONE; > + /* Maybe refuse illegal tags. */ > + if (! (flags & TAG_FLAG_BE_GENEROUS)) { > + const char *msg = illegal_tag (tag, remove); > + if (msg) { > + ret = line_error (TAG_PARSE_INVALID, line_for_error, msg); > + goto DONE; > + } > } I guess I failed to notice during the dump/restore review that this function was (and still is until later in the series) always called with TAG_FLAG_BE_GENEROUS. I guess that's what we want with restore; otherwise we should warn about such tags during dump. > > /* Decode tag. */ > -- > 1.7.10.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch