From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Nieder Subject: [PATCH 03/10 v2] parse-options: move NODASH sanity checks to parse_options_check Date: Thu, 2 Dec 2010 00:05:05 -0600 Message-ID: <20101202060505.GC32125@burratino> References: <20101201232728.GA31815@burratino> <20101201232950.GD31815@burratino> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Stephen Boyd , =?utf-8?B?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= Duy , Pierre Habouzit To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Thu Dec 02 07:05:25 2010 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PO2IG-00009n-IG for gcvg-git-2@lo.gmane.org; Thu, 02 Dec 2010 07:05:25 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755826Ab0LBGFR (ORCPT ); Thu, 2 Dec 2010 01:05:17 -0500 Received: from mail-gw0-f46.google.com ([74.125.83.46]:41092 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753596Ab0LBGFQ (ORCPT ); Thu, 2 Dec 2010 01:05:16 -0500 Received: by gwj20 with SMTP id 20so3905966gwj.19 for ; Wed, 01 Dec 2010 22:05:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=s6Pteb6D0LOX0W5jR7nsGCaVHbO7Is/1sGq1Ll4+1S8=; b=QhXk9lV1nWwh/z0BsdlZgTczaoEpWu4VowrWbO7RZIrrLz+llq+6EwtptuK0y22sP/ pZaP4lXZqjHsY8WXbJLKYGd5gCNAIvDdzhEwPAiZb1Cq2Xwjwk3h+6f3JXWN3eV4VOrw nWwu9/CaJAkE+11vxU/3wi9VgEAdFJECwBSq8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=txSivDSNLZp4GNz//1ZT56Vh9ZAv9oagk/8lgo3oK5Ay0MMaXwJbBnHh+pSogmOmJO jBIuWqfUjhGcakEyuRS5fF6R5ehNQDStac63T6NCp5RI6sMB8YDrzrwa6k4cLZhVb/nj JJAg6srm5k8peyN+X6ULrtFOkfoMuL6So5W4c= Received: by 10.91.7.15 with SMTP id k15mr628768agi.167.1291269915159; Wed, 01 Dec 2010 22:05:15 -0800 (PST) Received: from burratino (adsl-68-255-109-73.dsl.chcgil.sbcglobal.net [68.255.109.73]) by mx.google.com with ESMTPS id y11sm99015yhc.8.2010.12.01.22.05.13 (version=SSLv3 cipher=RC4-MD5); Wed, 01 Dec 2010 22:05:14 -0800 (PST) Content-Disposition: inline In-Reply-To: <20101201232950.GD31815@burratino> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: A dashless switch (like '(' passed to 'git grep') cannot be negated, cannot be attached to an argument, and cannot have a long form. Currently parse-options runs the related sanity checks when the dashless option is used; better to always check them at the start of option parsing, so mistakes can be caught more quickly. The error message at the new call site is less specific about the nature of the error, for simplicity. On the other hand, it prints which switch was problematic. Before: fatal: BUG: dashless options can't be long After: error: BUG: switch '(' uses feature not supported for dashless options Signed-off-by: Jonathan Nieder --- Change since v1: - rebase on top of patch 2 v2. parse-options.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/parse-options.c b/parse-options.c index 97d7ff7..9f6d305 100644 --- a/parse-options.c +++ b/parse-options.c @@ -288,13 +288,6 @@ static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg, for (; options->type != OPTION_END; options++) { if (!(options->flags & PARSE_OPT_NODASH)) continue; - if ((options->flags & PARSE_OPT_OPTARG) || - !(options->flags & PARSE_OPT_NOARG)) - die("BUG: dashless options don't support arguments"); - if (!(options->flags & PARSE_OPT_NONEG)) - die("BUG: dashless options don't support negation"); - if (options->long_name) - die("BUG: dashless options can't be long"); if (options->short_name == arg[0] && arg[1] == '\0') return get_value(p, options, OPT_SHORT); } @@ -330,6 +323,13 @@ static void parse_options_check(const struct option *opts) (opts->flags & PARSE_OPT_OPTARG)) err |= optbug(opts, "uses incompatible flags " "LASTARG_DEFAULT and OPTARG"); + if (opts->flags & PARSE_OPT_NODASH && + ((opts->flags & PARSE_OPT_OPTARG) || + !(opts->flags & PARSE_OPT_NOARG) || + !(opts->flags & PARSE_OPT_NONEG) || + opts->long_name)) + err |= optbug(opts, "uses feature " + "not supported for dashless options"); } if (err) exit(128); -- 1.7.2.3