From patchwork Sat Nov 6 21:46:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FECAC433F5 for ; Sat, 6 Nov 2021 21:47:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27AAF6103E for ; Sat, 6 Nov 2021 21:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233748AbhKFVtt (ORCPT ); Sat, 6 Nov 2021 17:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbhKFVts (ORCPT ); Sat, 6 Nov 2021 17:49:48 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 169C7C061570 for ; Sat, 6 Nov 2021 14:47:07 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d5so19646029wrc.1 for ; Sat, 06 Nov 2021 14:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/p2Oazxs3/MssrwgrmhTrgMEYAcDmJKMl2mUyQvSz8o=; b=ivJOwnMeUQ/IyCpaZgpdaRYlgKCaNk/A+u8wzVe6RSVtJdrHHv4bjtkyPbLYmJhv0w rlwzF+TwP4NYJzBtdAQrWCIhV0pm8Ur0dSo5r0RsXznVrT8mx6sVR0XOrdR61sjQlczY pfT2NyvnKt4I+EIOzY0nIjWmzXaAay8N8qqF55ogZDY1agxSLe04yCa4DGcUEto+LXOx Q5QfTdyGceHXnUyw2lP/pYEq+yihjtOdkXaAkBbO+WfAL5PJzxMjMdfi50oZaXboBCZs yLg5xtLRebRfXmPh7cAUrXOMGWngadxiVHEISF7v2insCdpCPqOMLst6j/1yCtdnE8iP imFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/p2Oazxs3/MssrwgrmhTrgMEYAcDmJKMl2mUyQvSz8o=; b=xWquBGfiQDVgp52hZ8l4naNCF2QSmwIbJoATSY0QP5tD2PWyWwPxbfdgllxp/9/idC tc2gryqQPGq8Vm0kerxEnaOJsscDxPRKh2LlIm0rZZ2VVaAPzgiM64fYhTg8rggcG5Yi elijQQ0gLCESlW16TArJH3tqSD0fbZrMgQAqmcnGuCP8I46vbO1VMUAfyHLZZRbYR3P4 84zjlmKANpB8Phf1f9udGwkK9MdyfZeC0dZ24vcnGGffnO5Q18DDzJmqyLzb+idpfikr a+dhkz8xm1Mp9f+5RU4mu67PujNQVgbqNYkQuBayvqr+6VooQIX4CQqkTN2tw0ZO82Tv JCMw== X-Gm-Message-State: AOAM532pduRwDaj/vmTaveA5YpxO8JPdMuepxHpvh793/9VHVf3fSTQX S0G1xUgv3Ibi3kzFMkjN5NKwYZMqgGTYwg== X-Google-Smtp-Source: ABdhPJzN8MdyOxcyF/T2fjIB8TdC2b8TNhtr3lnuZVN6wU1g8/ukr12PYXexFNso7poHSW7AT45DLw== X-Received: by 2002:adf:f6cf:: with SMTP id y15mr39665635wrp.56.1636235225462; Sat, 06 Nov 2021 14:47:05 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 01/10] cat-file tests: test bad usage Date: Sat, 6 Nov 2021 22:46:53 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Stress test the usage emitted when options are combined in ways that isn't supported. Let's test various option combinations, some of these we buggily allow right now. E.g. this reveals a bug in 321459439e1 (cat-file: support --textconv/--filters in batch mode, 2016-09-09) that we'll fix in a subsequent commit. We're supposed to be emitting a relevant message when --batch-all-objects is combined with --textconv or --filters, but we don't. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1006-cat-file.sh | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 658628375c8..0ad00e1fe73 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -4,6 +4,96 @@ test_description='git cat-file' . ./test-lib.sh +test_cmdmode_usage() { + test_expect_code 129 "$@" 2>err && + grep "^error:.*is incompatible with" err +} + +test_expect_success 'usage: cmdmode' ' + test_cmdmode_usage git cat-file -e -p && + test_cmdmode_usage git cat-file -p -t && + test_cmdmode_usage git cat-file -t -s && + test_cmdmode_usage git cat-file -s --textconv && + test_cmdmode_usage git cat-file --textconv --filters +' + +test_incompatible_usage() { + test_expect_code 129 "$@" 2>err && + grep -E "^error:.*$switch.*needs" err +} + +for opt in --batch --batch-check +do + test_expect_success "usage: incompatible options: --path with $opt" ' + test_incompatible_usage git cat-file --path=foo $opt + ' +done + +short_modes="-e -p -t -s" +cw_modes="--textconv --filters" + +for opt in $cw_modes +do + test_expect_success "usage: $opt requires another option" ' + test_expect_code 129 git cat-file $opt + ' + + test_expect_failure "usage: incompatible options: --batch-all-objects with $opt" ' + test_incompatible_usage git cat-file --batch-all-objects $opt + ' +done + +for opt in $short_modes +do + test_expect_success "usage: $opt requires another option" ' + test_expect_code 129 git cat-file $opt + ' + + for opt2 in --batch \ + --batch-check \ + --follow-symlinks + do + test_expect_failure "usage: incompatible options: $opt and $opt2" ' + test_incompatible_usage git cat-file $opt $opt2 + ' + done + + opt2="--path=foo HEAD:some-path.txt" + test_expect_success "usage: incompatible options: $opt and $opt2" ' + test_incompatible_usage git cat-file $opt $opt2 + ' +done + +for opt in $short_modes $cw_modes +do + args="one two three" + test_expect_success "usage: too many arguments: $opt $args" ' + test_expect_code 129 git cat-file $opt $args + ' + + for opt2 in --buffer --follow-symlinks + do + test_expect_success "usage: incompatible arguments: $opt with batch option $opt2" ' + test_expect_code 129 git cat-file $opt $opt2 + ' + done +done + +for opt in --buffer \ + --follow-symlinks \ + --batch-all-objects +do + status=success + if test $opt = "--buffer" + then + status=failure + fi + test_expect_$status "usage: bad option combination: $opt without batch mode" ' + test_expect_code 129 git cat-file $opt && + test_expect_code 129 git cat-file $opt commit HEAD + ' +done + echo_without_newline () { printf '%s' "$*" } From patchwork Sat Nov 6 21:46:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31537C433F5 for ; Sat, 6 Nov 2021 21:47:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 168DD61027 for ; Sat, 6 Nov 2021 21:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234115AbhKFVtw (ORCPT ); Sat, 6 Nov 2021 17:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233921AbhKFVtt (ORCPT ); Sat, 6 Nov 2021 17:49:49 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF765C061570 for ; Sat, 6 Nov 2021 14:47:07 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso871479wml.1 for ; Sat, 06 Nov 2021 14:47:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i1ZKUWt+wGRF1lLN/HSVRlRSIyoxrnicq7H4+Bm75O4=; b=aWoNl8PG0tXagEqfBZSihdRkG4FolxRKXou7ypIOeJdlOrbCWCak5gjp05QpeHSD+d 6R6Hybm0USfr0HmgqthC4Uh7NHa0sCtDgVr7aTeMS1AYJyNg8w6slNjWP4UGcegWgXb0 rXtVCjiD8GOyGTclhIfH9CFpHlPtf2dRtG6gB3hZmAaQ2GqqEW3dIFNSg8B02REs9Fc8 65PUvfq3FB9dJFAksIhn0yhPRh+l8nA4/XKP3akUfIdWPfVWo27N4IGiivwd573saGU6 t68m54I6UHSFufVu94SQk3ENyKTinhTwuG0PD3pV82X7uHpjpaF3IX4KZT3vst+nMCh9 Zr3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i1ZKUWt+wGRF1lLN/HSVRlRSIyoxrnicq7H4+Bm75O4=; b=5cKKXHDtAWFflExyYqXLpKZ1bEgnPXpA1hvurVV5h6n7GDkIw9CrA2q3w41m3I6Io5 TPVF9Qwx1QQh8g9c0xIcVm8ioQLzwZXGvBwAmDXPMipyvY11CscQ/dxhmSMzTsGUazwE CCfTH1PyK92rRA/1kYOlvUO5C8OHWQEafuo+SwSXGQJ0ClmeJf9XYNE9lom4aSGSYC/a 2j9zT0H3NthzjX+2T2a+JvY3pKvIdUkb9HkeCiFGOn/kJp1NauQnBtpyjL+mLf/qdMkn jOLfRqKrJ6y1Q/tutGmoxnqsnyGlTHY4z0r83OBplB1Vp/mnUGDJtS2/mNbf0HwG8D63 4LUA== X-Gm-Message-State: AOAM530ezpEC5PCApJb22+K89CvitQnDboTMenXDGmfy82Qu57oUe7DR wtQ8C82hLJRC4bnGWkOPKBijhuF0n3Lv/g== X-Google-Smtp-Source: ABdhPJxFJrwjKSmFHxallJkV6sAGlLkfOVwd/hoiQ2poJtJEdXxYElSOyZIniEV1qca7yVzYOytuHQ== X-Received: by 2002:a7b:c109:: with SMTP id w9mr40902881wmi.114.1636235226242; Sat, 06 Nov 2021 14:47:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:05 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 02/10] cat-file tests: test messaging on bad objects/paths Date: Sat, 6 Nov 2021 22:46:54 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add tests for the output that's emitted when we disambiguate : in cat-file. This gives us a baseline for improving these messages. For e.g. "git blame" we'll emit: $ git blame HEAD:foo fatal: no such path 'HEAD:foo' in HEAD But cat-file doesn't disambiguate these two cases, and just gives the rather unhelpful: $ git cat-file --textconv HEAD:foo fatal: Not a valid object name HEAD:foo Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t8007-cat-file-textconv.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index eacd49ade63..45471cefe73 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -19,6 +19,32 @@ test_expect_success 'setup ' ' GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" ' +test_expect_success 'usage' ' + cat >expect <<-\EOF && + fatal: Not a valid object name HEAD2 + EOF + test_must_fail git cat-file --textconv HEAD2 2>actual && + test_cmp expect actual && + + cat >expect <<-\EOF && + fatal: Not a valid object name HEAD2:two.bin + EOF + test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual && + test_cmp expect actual && + + cat >expect <<-\EOF && + fatal: git cat-file --textconv HEAD: must be + EOF + test_must_fail git cat-file --textconv HEAD 2>actual && + test_cmp expect actual && + + cat >expect <<-\EOF && + fatal: Not a valid object name HEAD:two.bin + EOF + test_must_fail git cat-file --textconv HEAD:two.bin 2>actual && + test_cmp expect actual +' + cat >expected < X-Patchwork-Id: 12606611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA453C433EF for ; Sat, 6 Nov 2021 21:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C4DE6108D for ; Sat, 6 Nov 2021 21:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234151AbhKFVtx (ORCPT ); Sat, 6 Nov 2021 17:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbhKFVtu (ORCPT ); Sat, 6 Nov 2021 17:49:50 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89FF3C061714 for ; Sat, 6 Nov 2021 14:47:08 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u1so19599451wru.13 for ; Sat, 06 Nov 2021 14:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wGpunmhWTIGblwwNJnqv7uORoqqxob92N9CZAXEsfTo=; b=MttYNUy0kg3B5hRiWFNus+PaJIvrt28P9/CT6MegftAb0BYOCFrPCZaFZ+yRnjjFqD TWiKnVd3X8mXsx6Wlp8TGw5VHUgxKHHjTwheRvRWJJuA0b5RGYLZ5hmJKhZa8+fN3l3f btTIPlFy1JG37Olmxd+yWx2oAAP3Dgp0afWa1VXPZv0DSUtbqJ6EAqKNewRUvuSIQF6j KOm4tmG7FG03yupD3xUh2HepgIxkRilUHnA7gZ9SFHdbE+YBzFTBGRdUPH23b5Mak9v8 eY/7Sc5Kys0pPpGBgKBYJYCzjJ/N0/CDHz48ozZYMygOzWzZ/GLgNK+bAg2wP1X7HgB8 2+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wGpunmhWTIGblwwNJnqv7uORoqqxob92N9CZAXEsfTo=; b=WBM6P09Jl/IztrtDOHgXvQAESsE5h5sFj7D+9tmR6K4Yc1vnAh7UsC/nTbJ2bDZac6 agvXQUbGlMVHabfm6x2+/pReNVO1DJZSRVqMzsl0cbaVI6X44jNeJXHwawH8dQug58Ve lqf10B5sDlyOunRDkfmh08BdAS6NXVL8MebtaJKMbudacnLnIq+CtMOl/yxWyrAsBfWf tlDKOPo65UrswhUOWab770Niydrs9/Pzz7Y+K6ey3SNvR7hYJAhxfhAYr6KFs+YITG7o CQ0WXd7aw1r69+MDGQYLs5Gb8zpzUWJJ6P8/nZmWt5A1POs5jdyTxf2IHCFh9C76gdXd +7Eg== X-Gm-Message-State: AOAM533P1B7dIqpYuxHSxx31RWz2LkEgaoMO5iAPcWq4GUWj05aEDk7P KZGc9ygzKTQDQVTZ88f+nQfsfxj2sk5COQ== X-Google-Smtp-Source: ABdhPJySzKPbiOPHeoVy7W8ZCT/m/kAh6WEvHdo9SoY73+h/Q5nWllILGymKYBrb9Fn4hN3iYylk9A== X-Received: by 2002:adf:df0b:: with SMTP id y11mr60626674wrl.181.1636235226960; Sat, 06 Nov 2021 14:47:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:06 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 03/10] parse-options API: add a usage_msg_optf() Date: Sat, 6 Nov 2021 22:46:55 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a usage_msg_optf() as a shorthand for the sort of usage_msg_opt(xstrfmt(...)) used in builtin/stash.c. I'll make more use of this function in builtin/cat-file.c shortly. The disconnect between the "..." and "fmt" is a bit unusual, but it works just fine and this keeps it consistent with usage_msg_opt(), i.e. a caller of it can be moved to usage_msg_optf() and not have to have its arguments re-arranged. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/stash.c | 4 ++-- parse-options.c | 13 +++++++++++++ parse-options.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/builtin/stash.c b/builtin/stash.c index a0ccc8654df..e27ade3e821 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1749,8 +1749,8 @@ int cmd_stash(int argc, const char **argv, const char *prefix) else if (!strcmp(argv[0], "save")) return !!save_stash(argc, argv, prefix); else if (*argv[0] != '-') - usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]), - git_stash_usage, options); + usage_msg_optf(_("unknown subcommand: %s"), + git_stash_usage, options, argv[0]); /* Assume 'stash push' */ strvec_push(&args, "push"); diff --git a/parse-options.c b/parse-options.c index 9a0484c8831..3a8e46be255 100644 --- a/parse-options.c +++ b/parse-options.c @@ -1078,3 +1078,16 @@ void NORETURN usage_msg_opt(const char *msg, fprintf(stderr, "fatal: %s\n\n", msg); usage_with_options(usagestr, options); } + +void NORETURN usage_msg_optf(const char * const fmt, + const char * const *usagestr, + const struct option *options, ...) +{ + struct strbuf msg = STRBUF_INIT; + va_list ap; + va_start(ap, options); + strbuf_vaddf(&msg, fmt, ap); + va_end(ap); + + usage_msg_opt(msg.buf, usagestr, options); +} diff --git a/parse-options.h b/parse-options.h index bdea052c399..cd1ef584166 100644 --- a/parse-options.h +++ b/parse-options.h @@ -226,6 +226,16 @@ NORETURN void usage_msg_opt(const char *msg, const char * const *usagestr, const struct option *options); +/** + * usage_msg_optf() is like usage_msg_opt() except that the first + * argument is a format string, and optional format arguments follow + * after the 3rd option. + */ +__attribute__((format (printf,1,4))) +void NORETURN usage_msg_optf(const char *fmt, + const char * const *usagestr, + const struct option *options, ...); + /* * Use these assertions for callbacks that expect to be called with NONEG and * NOARG respectively, and do not otherwise handle the "unset" and "arg" From patchwork Sat Nov 6 21:46:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5983C4332F for ; Sat, 6 Nov 2021 21:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E15D611EE for ; Sat, 6 Nov 2021 21:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234176AbhKFVty (ORCPT ); Sat, 6 Nov 2021 17:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbhKFVtv (ORCPT ); Sat, 6 Nov 2021 17:49:51 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FE94C061746 for ; Sat, 6 Nov 2021 14:47:09 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id c71-20020a1c9a4a000000b0032cdcc8cbafso8944518wme.3 for ; Sat, 06 Nov 2021 14:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C2BvJ07ODMQc6mT0PcKKlVh6MLlitNEUGixbqbryvmk=; b=kK3NwLZSN3C1PL97QngFblxmgv0x4GbUiR6Oy+066u1mr5mQpiN+nQl6VPRyaWmx9f 1hRxb96+sbupyc2wdSOLQfopi6BJzJvUA8XmqYVxTjDHLMI52z8NsUpyUggIArc7kCBp 7eEs5B3buJLuj7L0OVh7G+nePXYjeFeL8uRqvjHU9W44/1WZeauUdPfOlbJm8x9f3a6J 2daG9Q5PRqNHylEAVQCGoX/1adG1vHzUmFuithdRnXfGT6hmyUQtbFr/6nol9NvDyhgy TvHuPdLJUbhOa4maTwFl97zhrtARO5VWJ0EQe0b/MCp40fj43ze8uLYiUSzEgX1yOTwV 23YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C2BvJ07ODMQc6mT0PcKKlVh6MLlitNEUGixbqbryvmk=; b=ikqIVStM3bVIIJDFawiH68fb0XaYkxQIo513QTLOD7NIX0gHenMv4t6CD8vj381pBo xTSk3+HANQrxKLpUEVzCT7lxS9PnALhPrESJRKEZ3FDOFIt3qIXy6O1whPBJL8ezG3/K s618P5QqeLewpbrY16xPf0mYtd0WV78HmcsufW6r3wrFvsyZrjUdPISI+uyOXE/5xgG5 qR2MnMBAF3/dM/FmEAsfuiWvAvhmzAl14OW1/ys0fgblIIYTXv9/FZjui8GMGYzt7bvh ec3l8ZqdxFtgB6JD9B0tBPuuuFku7BSmE6t4vrruZ11DC9hekjRELKI33u/uaV4Gmc4y zFwA== X-Gm-Message-State: AOAM531OoOfnImiimZ87ORboQxbDeJTC0TxOsWcIdeZ4Fqn0TEuI2aJU HrLXaF///DTyg0Z01uSnzNYdX2/9+NH1sg== X-Google-Smtp-Source: ABdhPJyS4bvw72EBAeofS/a/6krDyPkuyc8rRrg2JZ1UtZ9qy66hNM1jaRfFcb+wzwEhJbQwGJcPIA== X-Received: by 2002:a7b:c351:: with SMTP id l17mr41740188wmj.120.1636235227706; Sat, 06 Nov 2021 14:47:07 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 04/10] cat-file docs: fix SYNOPSIS and "-h" output Date: Sat, 6 Nov 2021 22:46:56 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There were various inaccuracies in the previous SYNOPSIS output, e.g. "--path" is not something that can optionally go with any options except --textconv or --filters, as the output implied. The opening line of the DESCRIPTION section is also "In its first form[...]", which refers to "git cat-file ", but the SYNOPSIS section wasn't showing that as the first form! That part of the documentation made sense in d83a42f34a6 (Documentation: minor grammatical fixes in git-cat-file.txt, 2009-03-22) when it was introduced, but since then various options that were added have made that intro make no sense in the context it was in. Now the two will match again. The usage output here is not properly aligned on "master" currently, but will be with my in-flight 4631cfc20bd (parse-options: properly align continued usage output, 2021-09-21), so let's indent things correctly in the C code in anticipation of that. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/git-cat-file.txt | 10 ++++++++-- builtin/cat-file.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index 27b27e2b300..73ebbc70ee2 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -9,8 +9,14 @@ git-cat-file - Provide content or type and size information for repository objec SYNOPSIS -------- [verse] -'git cat-file' (-t [--allow-unknown-type]| -s [--allow-unknown-type]| -e | -p | | --textconv | --filters ) [--path=] -'git cat-file' (--batch[=] | --batch-check[=]) [ --textconv | --filters ] [--follow-symlinks] +'git cat-file' +'git cat-file' (-e | -p) +'git cat-file' ( -t | -s ) [--allow-unknown-type] +'git cat-file' (--batch | --batch-check) [--batch-all-objects] + [--buffer] [--follow-symlinks] [--unordered] + [--textconv | --filters] +'git cat-file' (--textconv | --filters ) + [: | --path= ] DESCRIPTION ----------- diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 86fc03242b8..1df7f797cb6 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -619,8 +619,14 @@ static int batch_objects(struct batch_options *opt) } static const char * const cat_file_usage[] = { - N_("git cat-file (-t [--allow-unknown-type] | -s [--allow-unknown-type] | -e | -p | | --textconv | --filters) [--path=] "), - N_("git cat-file (--batch[=] | --batch-check[=]) [--follow-symlinks] [--textconv | --filters]"), + N_("git cat-file "), + N_("git cat-file (-e | -p) "), + N_("git cat-file ( -t | -s ) [--allow-unknown-type] "), + N_("git cat-file (--batch | --batch-check) [--batch-all-objects]\n" + " [--buffer] [--follow-symlinks] [--unordered]\n" + " [--textconv | --filters]"), + N_("git cat-file (--textconv | --filters )\n" + " [: | --path= ]"), NULL }; From patchwork Sat Nov 6 21:46:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E806C433F5 for ; Sat, 6 Nov 2021 21:47:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 422B06108D for ; Sat, 6 Nov 2021 21:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234197AbhKFVtz (ORCPT ); Sat, 6 Nov 2021 17:49:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234095AbhKFVtw (ORCPT ); Sat, 6 Nov 2021 17:49:52 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 077DFC061205 for ; Sat, 6 Nov 2021 14:47:10 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u18so19599523wrg.5 for ; Sat, 06 Nov 2021 14:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nAgveEnnTUZ1IrS9pNMlRlq/C4CLz8miJeoiSauvwz8=; b=DA14c668Tr6Bln7aJLBqGosqkGU/fFc9Idcrm3l6nFgyGFnj5SaoEwArcadNHbvMZv FjEA6GCSKF6I8QPZ67gNbfGhNFyrDOP0UfX6eJ2uaP/MDlH3OBW5tDP6cTg5wqAj1A8x XdapdbaewckGxTwZmFuN2gIXpzPZybNBWAlxneVCi7/gvVnwzvYsCdOp1gLtK03k2cB8 J38TjJJvfaBNKJZX5sVEQTrYm1kCfIyVHkrzWqnQJVkRniYwmeXngbYSKXm9xIIs+1VB dLwxYE7O8MFUdu3ZSm+tQcY5RkQlKWDNGTCP+MG4LW0I/MKTGQZhVshtcED5qE3gsWx8 wb+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nAgveEnnTUZ1IrS9pNMlRlq/C4CLz8miJeoiSauvwz8=; b=ZzEzlPW6i8kmihyfkZBwGttjO70iRxBSLYP/f59WFF0xnlfkCZPy2aAP1oSAiQbHAT R+W8pMzeMPwwBPQSrtD37woMz9vyGBZwtC5XbfCfSmJGE8a4M/Hp+pS3Qs8cE4i5NvJZ 1p2HDMQcJF9/aFuqmi+DU1YZrWJjo+22+qfseD5RwiStkQyv0j4uJFNM+TbLCDE/tXqS 3rKLCxA8p3WQjgQofh00XIxpGw5eiLNARxqlU7aCYMMThHnKsRO+zbUrqNuAyYjUHkl6 tLCsRdc/nd+jog8CN/bKhC9rsZn0f66tl7+VQ5e9nJA6L/ofi4C8LDuKqNFKnansV6v4 0rXg== X-Gm-Message-State: AOAM530G/KTXSSguFeGviGJBprb3Q6A2EZbSsQNOX8rDQCmMNNeupeLl tK+5Evbei3KvKBNIyJOmAc8l7lBNp5yHJg== X-Google-Smtp-Source: ABdhPJwa04q2mEpntYfQQ2TIvcxpR2tiMJOaJd7RCZrg5e44Su4SVAHre3cIyCwE8+sLOOoTAVFNiw== X-Received: by 2002:a5d:4e52:: with SMTP id r18mr57542449wrt.224.1636235228466; Sat, 06 Nov 2021 14:47:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 05/10] cat-file: move "usage" variable to cmd_cat_file() Date: Sat, 6 Nov 2021 22:46:57 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There's no benefit to defining this at a distance, and it makes the code harder to read as you've got to scroll up to see the usage that corresponds to the options. In subsequent commits I'll make use of usage_msg_opt(), which will be quite noisy if I have to use the long "cat_file_usage" variable, there's no other command being defined in this file, so let's rename it to just "usage". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 1df7f797cb6..6d0f645301b 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -618,18 +618,6 @@ static int batch_objects(struct batch_options *opt) return retval; } -static const char * const cat_file_usage[] = { - N_("git cat-file "), - N_("git cat-file (-e | -p) "), - N_("git cat-file ( -t | -s ) [--allow-unknown-type] "), - N_("git cat-file (--batch | --batch-check) [--batch-all-objects]\n" - " [--buffer] [--follow-symlinks] [--unordered]\n" - " [--textconv | --filters]"), - N_("git cat-file (--textconv | --filters )\n" - " [: | --path= ]"), - NULL -}; - static int git_cat_file_config(const char *var, const char *value, void *cb) { if (userdiff_config(var, value) < 0) @@ -664,6 +652,17 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) struct batch_options batch = {0}; int unknown_type = 0; + const char * const usage[] = { + N_("git cat-file "), + N_("git cat-file (-e | -p) "), + N_("git cat-file ( -t | -s ) [--allow-unknown-type] "), + N_("git cat-file (--batch | --batch-check) [--batch-all-objects]\n" + " [--buffer] [--follow-symlinks] [--unordered]\n" + " [--textconv | --filters]"), + N_("git cat-file (--textconv | --filters )\n" + " [: | --path= ]"), + NULL + }; const struct option options[] = { OPT_GROUP(N_(" can be one of: blob, tree, commit, tag")), OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'), @@ -700,7 +699,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) git_config(git_cat_file_config, NULL); batch.buffer_output = -1; - argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0); + argc = parse_options(argc, argv, prefix, options, usage, 0); if (opt) { if (batch.enabled && (opt == 'c' || opt == 'w')) @@ -708,35 +707,35 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) else if (argc == 1) obj_name = argv[0]; else - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); } if (!opt && !batch.enabled) { if (argc == 2) { exp_type = argv[0]; obj_name = argv[1]; } else - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); } if (batch.enabled) { if (batch.cmdmode != opt || argc) - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); if (batch.cmdmode && batch.all_objects) die("--batch-all-objects cannot be combined with " "--textconv nor with --filters"); } if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) { - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); } if (force_path && opt != 'c' && opt != 'w') { error("--path= needs --textconv or --filters"); - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); } if (force_path && batch.enabled) { error("--path= incompatible with --batch"); - usage_with_options(cat_file_usage, options); + usage_with_options(usage, options); } if (batch.buffer_output < 0) From patchwork Sat Nov 6 21:46:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83257C433EF for ; Sat, 6 Nov 2021 21:47:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C0E561027 for ; Sat, 6 Nov 2021 21:47:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbhKFVt4 (ORCPT ); Sat, 6 Nov 2021 17:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234106AbhKFVtw (ORCPT ); Sat, 6 Nov 2021 17:49:52 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1F8C061570 for ; Sat, 6 Nov 2021 14:47:10 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id i5so19646130wrb.2 for ; Sat, 06 Nov 2021 14:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UNeutd+7Q6QYKDENZjGNOsI17wHLb60tv+jNnqHwQVY=; b=Rhf6abBWNLFiI9XaSRVUINug0ES3mJcVuU730UU/nQcpWzvhdbwck8Mv+kCx/HN1FZ 4vYfzde2elsuuGjEn3LqQZQQ448PgSpN+SPBgN5DbnEi6ikZPMFAtZQqvGWOmCdf7+l3 6A4ZlZB/r3+HrrbvtKZe/GhFS9W6hzCWqtus1+NJ7+ggKf9eTmFqHyUC0vNQ1GCO6AQS PVm2ymPL360jVgfZqKfA95xtwrrvOsof1x94PPWFGpppR3rF4vERCpEbZLcg9AmzEDO+ dr2I/FR0qgyr5e2UaMd+Spkh27Q9UJ1hyhGRUZ5W+KvZLZkCIwwzAyAivo8+UhEbBKbI T6Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UNeutd+7Q6QYKDENZjGNOsI17wHLb60tv+jNnqHwQVY=; b=1QC1jNyzBE27QFFu+02CJld2dHbch0jPggQ9F5DzWlT25wHjNSgyYDDCrgzTzo99Ze +W16GTLs206xIbCMJygi4lLbBHlBImygWwq/7AAX/3ZWQLya5Zj4Jy9m2LpYkYHXIkEB o2LG+xJNmTRmLTLBbD+CiTVslZfsevY0efTox2aWm6ixFlXo0lT7UaVYNo2erVeUigcv NGH/CkKkYsZjUaPmIIR6pdNL/FufaTdGMFyVvRrogVXt+Ooz/rqJxByMf797nbhZUOgq Jm4m2wSzR21wGkDk7aDGUTknh7QJZvNqcizhQ0H9idC2mUxYhYMAH26H4Q/0ku9cecQS lgpQ== X-Gm-Message-State: AOAM530THbbjCR5JUE8SnYXKXg5zILVRBjSM+TuQtRKo19uFMg6RLLZM 4mhd3kJiOqUzsBATOObAV5wK4XdDuJdEMw== X-Google-Smtp-Source: ABdhPJwZntuGpbAK+T946bBTSv8PJDjO9TLKN25l6gyqpLDl3ep/RCMq284wH6QUf6q0xmhw4IV8jg== X-Received: by 2002:a05:6000:18a3:: with SMTP id b3mr36858875wri.343.1636235229104; Sat, 06 Nov 2021 14:47:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 06/10] cat-file: make --batch-all-objects a CMDMODE Date: Sat, 6 Nov 2021 22:46:58 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The usage of OPT_CMDMODE() in "cat-file"[1] was added in parallel with the development of[3] the --batch-all-objects option[4], so we've since grown[5] checks that it can't be combined with other command modes, when it should just be made a top-level command-mode instead. It doesn't combine with --filters, --textconv etc. By giving parse_options() information about what options are mutually exclusive with one another we can get the die9) message being removed here for free, we didn't even use that removed message in some cases, e.g. for both of: --batch-all-objects --textconv --batch-all-objects --filters We'd take the "goto usage" in the "if (opt)" branch, and never reach the previous message. Now we'll emit e.g.: $ git cat-file --batch-all-objects --filters error: option `filters' is incompatible with --batch-all-objects 1. b48158ac94c (cat-file: make the options mutually exclusive, 2015-05-03) 2. https://lore.kernel.org/git/xmqqtwspgusf.fsf@gitster.dls.corp.google.com/ 3. https://lore.kernel.org/git/20150622104559.GG14475@peff.net/ 4. 6a951937ae1 (cat-file: add --batch-all-objects option, 2015-06-22) 5. 321459439e1 (cat-file: support --textconv/--filters in batch mode, 2016-09-09) Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 25 +++++++++++-------------- t/t1006-cat-file.sh | 7 ++----- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 6d0f645301b..87356208134 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -674,6 +674,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) N_("for blob objects, run textconv on object's content"), 'c'), OPT_CMDMODE(0, "filters", &opt, N_("for blob objects, run filters on object's content"), 'w'), + OPT_CMDMODE(0, "batch-all-objects", &opt, + N_("show all objects with --batch or --batch-check"), 'b'), OPT_STRING(0, "path", &force_path, N_("blob"), N_("use a specific path for --textconv/--filters")), OPT_BOOL(0, "allow-unknown-type", &unknown_type, @@ -689,8 +691,6 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) batch_option_callback), OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks, N_("follow in-tree symlinks (used with --batch or --batch-check)")), - OPT_BOOL(0, "batch-all-objects", &batch.all_objects, - N_("show all objects with --batch or --batch-check")), OPT_BOOL(0, "unordered", &batch.unordered, N_("do not order --batch-all-objects output")), OPT_END() @@ -699,30 +699,27 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) git_config(git_cat_file_config, NULL); batch.buffer_output = -1; - argc = parse_options(argc, argv, prefix, options, usage, 0); - if (opt) { + argc = parse_options(argc, argv, prefix, options, usage, 0); + if (argc && batch.enabled) + usage_with_options(usage, options); + if (opt == 'b') { + batch.all_objects = 1; + } else if (opt) { if (batch.enabled && (opt == 'c' || opt == 'w')) batch.cmdmode = opt; else if (argc == 1) obj_name = argv[0]; else usage_with_options(usage, options); - } - if (!opt && !batch.enabled) { + } else if (!opt && !batch.enabled) { if (argc == 2) { exp_type = argv[0]; obj_name = argv[1]; } else usage_with_options(usage, options); - } - if (batch.enabled) { - if (batch.cmdmode != opt || argc) - usage_with_options(usage, options); - if (batch.cmdmode && batch.all_objects) - die("--batch-all-objects cannot be combined with " - "--textconv nor with --filters"); - } + } else if (batch.enabled && batch.cmdmode != opt) + usage_with_options(usage, options); if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) { usage_with_options(usage, options); diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 0ad00e1fe73..44285f749cd 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -14,7 +14,8 @@ test_expect_success 'usage: cmdmode' ' test_cmdmode_usage git cat-file -p -t && test_cmdmode_usage git cat-file -t -s && test_cmdmode_usage git cat-file -s --textconv && - test_cmdmode_usage git cat-file --textconv --filters + test_cmdmode_usage git cat-file --textconv --filters && + test_cmdmode_usage git cat-file --batch-all-objects -e ' test_incompatible_usage() { @@ -37,10 +38,6 @@ do test_expect_success "usage: $opt requires another option" ' test_expect_code 129 git cat-file $opt ' - - test_expect_failure "usage: incompatible options: --batch-all-objects with $opt" ' - test_incompatible_usage git cat-file --batch-all-objects $opt - ' done for opt in $short_modes From patchwork Sat Nov 6 21:46:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E321C433FE for ; Sat, 6 Nov 2021 21:47:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8209361027 for ; Sat, 6 Nov 2021 21:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234160AbhKFVt6 (ORCPT ); Sat, 6 Nov 2021 17:49:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234147AbhKFVtx (ORCPT ); Sat, 6 Nov 2021 17:49:53 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7235AC061714 for ; Sat, 6 Nov 2021 14:47:11 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so8949859wme.4 for ; Sat, 06 Nov 2021 14:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Ej5mKu/FFt2l0QuFb6RejAsBWBHoG6bttRnOnGFAAk=; b=TsrQQ65xiPrssGaTHTKabRhyGMjBwoQm7NiuA6hn6UomYs7p/k1Uzn6qeZiAe+WZPX OUInN3XsCe5RE/fnRWaHndUkx0xAu64HcWileQU6TlB0VhS4hVtEs/6e/Uax90qXRRs8 B1va6NSlFNIQ+h7FMgtMkPVvlYgG/Hp4bHnCZVBFNBXBDYlUPogbuPVIPfhUoBBfwxZL JCW+TzpeS5iAresIYGdBRswwtRfd5o5qvh1FtDCvp4eCm8F/BqCvTLDnmIyDNR8DOCgi lqIN4UXOO0LeufO/lxfEmjdIZcPwbC2RySw0GCMHbarhU/rvGSmmQwpw9e5Rn/dvQ1dX xBtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Ej5mKu/FFt2l0QuFb6RejAsBWBHoG6bttRnOnGFAAk=; b=ehkdvA8lQzGAhI9JTbtzRxZDunzE1I3ssvxfPIpekqmghTh4Qa5h7azSW0SheKzjRZ FcGQaioYBaeMUs8EjYlCbhzsCZLC0oi+qdxDVvVuBigQg6QjoZ+z80itGB1AJPrUfB3c zEBtjAwPBJnpny3yVc7WQbMf0sqcHlvT0BvfXa+5Sl5pIsy7OrYEHtK2A1lM68x0kfI7 VawY/tL7206aMDg7jh3F/6ZH6slFouvOJ+RwAVUuIZ9gM+sRcDd8BQEKonA8v4CzA749 VsatsbtM8qjNdZ9UAyVwjG2XeQ1Jy1PFrTsihU9H3SpWEk29eex450G/hKvcSzeloYgp MI2A== X-Gm-Message-State: AOAM530np9meKkhqK5xCgoT7y1XbjhBm+vwOjaIgqHwq+OawaCcI38Gv tH4nIUAmx8kzd0++Y7L5VleUpOYUO7a/QQ== X-Google-Smtp-Source: ABdhPJySD2rnEuj/OtFwnEcXVqKwOWtO8DKxlAdutrAt4XOKpmLeNEq2QGQ5tu/v5LXEH7AFnHMXLg== X-Received: by 2002:a05:600c:2156:: with SMTP id v22mr42775425wml.159.1636235229810; Sat, 06 Nov 2021 14:47:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:09 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 07/10] cat-file: fix remaining usage bugs Date: Sat, 6 Nov 2021 22:46:59 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With the migration of --batch-all-objects to OPT_CMDMODE() in the preceding commit one bug with combining it and other OPT_CMDMODE() options was solved, but we were still left with e.g. --buffer silently being discarded when not in batch mode. Fix all those bugs, and in addition emit errors telling the user specifically what options can't be combined with what other options, before this we'd usually just emit the cryptic usage text and leave the users to work it out by themselves. This change is rather large, because to do so we need to untangle the options processing so that we can not only error out, but emit sensible errors, and e.g. emit errors about options before errors about stray argc elements (as they might become valid if the option were removed). Some of the output changes ("error:" to "fatal:" with usage_msg_opt[f]()), but none of the exit codes change, except in those cases where we silently accepted bad option combinations before, now we'll error out. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 95 ++++++++++++++++++++++++++++++--------------- t/t1006-cat-file.sh | 41 +++++++++---------- 2 files changed, 84 insertions(+), 52 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 87356208134..f507e3ae46c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -648,6 +648,8 @@ static int batch_option_callback(const struct option *opt, int cmd_cat_file(int argc, const char **argv, const char *prefix) { int opt = 0; + int opt_cw = 0; + int opt_epts = 0; const char *exp_type = NULL, *obj_name = NULL; struct batch_options batch = {0}; int unknown_type = 0; @@ -701,45 +703,74 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) batch.buffer_output = -1; argc = parse_options(argc, argv, prefix, options, usage, 0); - if (argc && batch.enabled) - usage_with_options(usage, options); - if (opt == 'b') { - batch.all_objects = 1; - } else if (opt) { - if (batch.enabled && (opt == 'c' || opt == 'w')) - batch.cmdmode = opt; - else if (argc == 1) - obj_name = argv[0]; - else - usage_with_options(usage, options); - } else if (!opt && !batch.enabled) { - if (argc == 2) { - exp_type = argv[0]; - obj_name = argv[1]; - } else - usage_with_options(usage, options); - } else if (batch.enabled && batch.cmdmode != opt) - usage_with_options(usage, options); + opt_cw = (opt == 'c' || opt == 'w'); + opt_epts = (opt == 'e' || opt == 'p' || opt == 't' || opt == 's'); - if ((batch.follow_symlinks || batch.all_objects) && !batch.enabled) { - usage_with_options(usage, options); - } - - if (force_path && opt != 'c' && opt != 'w') { - error("--path= needs --textconv or --filters"); - usage_with_options(usage, options); - } + /* --batch-all-objects? */ + if (opt == 'b') + batch.all_objects = 1; - if (force_path && batch.enabled) { - error("--path= incompatible with --batch"); - usage_with_options(usage, options); - } + /* Option compatibility */ + if (force_path && !opt_cw) + usage_msg_optf(_("'%s=<%s> needs '%s' or '%s'"), + usage, options, + "--path", _("path|tree-ish"), "--filters", + "--textconv"); + /* Option compatibility with batch mode */ + if (batch.enabled) + ; + else if (batch.follow_symlinks) + usage_msg_optf(_("'%s' requires a batch mode"), usage, options, + "--follow_symlinks"); + else if (batch.buffer_output >= 0) + usage_msg_optf(_("'%s' requires a batch mode"), usage, options, + "--buffer"); + else if (batch.all_objects) + usage_msg_optf(_("'%s' requires a batch mode"), usage, options, + "--batch-all_objects"); + + /* Batch defaults */ if (batch.buffer_output < 0) batch.buffer_output = batch.all_objects; - if (batch.enabled) + /* Return early if we're in batch mode? */ + if (batch.enabled) { + if (opt_cw) + batch.cmdmode = opt; + else if (opt && opt != 'b') + usage_msg_optf(_("'-%c' is incompatible with batch mode"), + usage, options, opt); + else if (argc) + usage_msg_opt(_("batch modes take no arguments"), usage, + options); + return batch_objects(&batch); + } + + if (opt) { + if (!argc && opt == 'c') + usage_msg_optf(_(" required with '%s'"), + usage, options, "--textconv"); + else if (!argc && opt == 'w') + usage_msg_optf(_(" required with '%s'"), + usage, options, "--filters"); + else if (!argc && opt_epts) + usage_msg_optf(_(" required with '-%c'"), + usage, options, opt); + else if (argc == 1) + obj_name = argv[0]; + else + usage_msg_opt(_("too many arguments"), usage, options); + } else if (!argc) { + usage_with_options(usage, options); + } else if (argc != 2) { + usage_msg_optf(_("only two arguments allowed in mode, not %d"), + usage, options, argc); + } else if (argc) { + exp_type = argv[0]; + obj_name = argv[1]; + } if (unknown_type && opt != 't' && opt != 's') die("git cat-file --allow-unknown-type: use with -s or -t"); diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 44285f749cd..10bf46fc513 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -20,7 +20,7 @@ test_expect_success 'usage: cmdmode' ' test_incompatible_usage() { test_expect_code 129 "$@" 2>err && - grep -E "^error:.*$switch.*needs" err + grep -E "^(fatal|error):.*$switch.*(requires|incompatible with|needs)" err } for opt in --batch --batch-check @@ -30,48 +30,54 @@ do ' done +test_missing_usage() { + test_expect_code 129 "$@" 2>err && + grep -E "^fatal:.*required" err +} + short_modes="-e -p -t -s" cw_modes="--textconv --filters" for opt in $cw_modes do test_expect_success "usage: $opt requires another option" ' - test_expect_code 129 git cat-file $opt + test_missing_usage git cat-file $opt ' done for opt in $short_modes do test_expect_success "usage: $opt requires another option" ' - test_expect_code 129 git cat-file $opt + test_missing_usage git cat-file $opt ' for opt2 in --batch \ --batch-check \ - --follow-symlinks + --follow-symlinks \ + "--path=foo HEAD:some-path.txt" do - test_expect_failure "usage: incompatible options: $opt and $opt2" ' + test_expect_success "usage: incompatible options: $opt and $opt2" ' test_incompatible_usage git cat-file $opt $opt2 ' done - - opt2="--path=foo HEAD:some-path.txt" - test_expect_success "usage: incompatible options: $opt and $opt2" ' - test_incompatible_usage git cat-file $opt $opt2 - ' done +test_too_many_arguments() { + test_expect_code 129 "$@" 2>err && + grep -E "^fatal: too many arguments$" err +} + for opt in $short_modes $cw_modes do args="one two three" test_expect_success "usage: too many arguments: $opt $args" ' - test_expect_code 129 git cat-file $opt $args + test_too_many_arguments git cat-file $opt $args ' for opt2 in --buffer --follow-symlinks do test_expect_success "usage: incompatible arguments: $opt with batch option $opt2" ' - test_expect_code 129 git cat-file $opt $opt2 + test_incompatible_usage git cat-file $opt $opt2 ' done done @@ -80,14 +86,9 @@ for opt in --buffer \ --follow-symlinks \ --batch-all-objects do - status=success - if test $opt = "--buffer" - then - status=failure - fi - test_expect_$status "usage: bad option combination: $opt without batch mode" ' - test_expect_code 129 git cat-file $opt && - test_expect_code 129 git cat-file $opt commit HEAD + test_expect_success "usage: bad option combination: $opt without batch mode" ' + test_incompatible_usage git cat-file $opt && + test_incompatible_usage git cat-file $opt commit HEAD ' done From patchwork Sat Nov 6 21:47:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5FE6C433EF for ; Sat, 6 Nov 2021 21:47:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B547A61027 for ; Sat, 6 Nov 2021 21:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234217AbhKFVt7 (ORCPT ); Sat, 6 Nov 2021 17:49:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234169AbhKFVty (ORCPT ); Sat, 6 Nov 2021 17:49:54 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419EBC061570 for ; Sat, 6 Nov 2021 14:47:12 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id r8so19560686wra.7 for ; Sat, 06 Nov 2021 14:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JgJ/xyYMjewGrH+vO+CFHa2rpfIWkVFrGITZyco5Hy0=; b=eK5LtJjRPkTxfSLte5tUWTQjnWrjj6O1vs3KVUeNKFu0gGfqx6T3+HCMx1wp0yjXrr AI9VcJ7J4L4rV29A76//MFkSmxoosp1kT4thDgkAo2EOLROlLqizEvuA5/uIOdRj/d9l gbh5Txgsga3VbNZxzfoDnh/2Liliuo9LC1ZflhbVRuVpUBJkK8vwRqbv+QciWBuNnSCT RTZT5673dOnCuo/JD0TLWIFI9+cCn2iBc5loO0Rl7b8RAodrKjaVuru53U0DgIO597FO JtTwNKnWiper5hrmjPsJ6xtTKbGp3CtHMJHAdSILp6/ictqApj7abwP0L5j8QzHf2lcc dMwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JgJ/xyYMjewGrH+vO+CFHa2rpfIWkVFrGITZyco5Hy0=; b=Ff2MvJ8VNsgoDLUqIQqPfMvVvO+sURVJq2TSGPO7lLCWrdsv0jQRms7ANlycodVvjP Ehtmf66kLwqZyIomTZPyWz970UZ0CkGhQjPrsEJie20X/dI83DeuWfvaBLjr1sOFyqIV NjpVJjrQYQkztRub09gcdPvMh3eAK6qP98wXue8nZYBt0xvKl2xxBDzyN9mdpfNmrcnX O1wCrhYx4tbc29Kl0OnxrWDkcQj92Mr5iNn2gx3v2A7Eh9QOIRZK/gnfsQxrMt1xrzEZ UuZwlCublwceq+Vh0yv20R2b17FHyNY8Jt/mRHT2rNX0ybLfsf26VRVAubFAtjm4dWBr JSMg== X-Gm-Message-State: AOAM532GfYZRn7uy2x3VwqyGUoZKkFvUPkwXeSq9KKfZ7/yQnq6j83wz q4L0jXueJ9fiXPoJFQ6R48y1ElK5DPSrnw== X-Google-Smtp-Source: ABdhPJwoqU9GnqCV1vBN/29kLu06KPl1Bnrhg8wRi1u/i8N+WVGYaS9iPqXGnWPRaARowISwJA9NzA== X-Received: by 2002:adf:f708:: with SMTP id r8mr79322828wrp.198.1636235230599; Sat, 06 Nov 2021 14:47:10 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 08/10] cat-file: correct and improve usage information Date: Sat, 6 Nov 2021 22:47:00 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the usage output emitted on "git cat-file -h" to group related options, making it clear to users which options go with which other ones. The new output is: Check object existence or emit object contents -e check if exists -p pretty-print content Emit [broken] object attributes -t show object type (one of 'blob', 'tree', 'commit', 'tag', ...) -s show object size --allow-unknown-type allow -s and -t to work with broken/corrupt objects Batch objects requested on stdin (or --batch-all-objects) --batch[=] show full or contents --batch-check[=] like --batch, but don't emit --batch-all-objects with --batch[-check]: ignores stdin, batches all known objects Change or optimize batch output --buffer buffer --batch output --follow-symlinks follow in-tree symlinks --unordered do not order objects before emitting them Emit object (blob or tree) with conversion or filter (stand-alone, or with batch) --textconv run textconv on object's content --filters run filters on object's content --path blob|tree use a for (--textconv | --filters ); Not with 'batch' The old usage was: can be one of: blob, tree, commit, tag -t show object type -s show object size -e exit with zero when there's no error -p pretty-print object's content --textconv for blob objects, run textconv on object's content --filters for blob objects, run filters on object's content --batch-all-objects show all objects with --batch or --batch-check --path use a specific path for --textconv/--filters --allow-unknown-type allow -s and -t to work with broken/corrupt objects --buffer buffer --batch output --batch[=] show info and content of objects fed from the standard input --batch-check[=] show info about objects fed from the standard input --follow-symlinks follow in-tree symlinks (used with --batch or --batch-check) --unordered do not order --batch-all-objects output While shorter, I think the new one is easier to understand, as e.g. "--allow-unknown-type" is grouped with "-t" and "-s", as it can only be combined with those options. The same goes for "--buffer", "--unordered" etc. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 49 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index f507e3ae46c..1d7f79184f0 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -666,35 +666,44 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) NULL }; const struct option options[] = { - OPT_GROUP(N_(" can be one of: blob, tree, commit, tag")), - OPT_CMDMODE('t', NULL, &opt, N_("show object type"), 't'), - OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'), + /* Simple queries */ + OPT_GROUP(N_("Check object existence or emit object contents")), OPT_CMDMODE('e', NULL, &opt, - N_("exit with zero when there's no error"), 'e'), - OPT_CMDMODE('p', NULL, &opt, N_("pretty-print object's content"), 'p'), - OPT_CMDMODE(0, "textconv", &opt, - N_("for blob objects, run textconv on object's content"), 'c'), - OPT_CMDMODE(0, "filters", &opt, - N_("for blob objects, run filters on object's content"), 'w'), - OPT_CMDMODE(0, "batch-all-objects", &opt, - N_("show all objects with --batch or --batch-check"), 'b'), - OPT_STRING(0, "path", &force_path, N_("blob"), - N_("use a specific path for --textconv/--filters")), + N_("check if exists"), 'e'), + OPT_CMDMODE('p', NULL, &opt, N_("pretty-print content"), 'p'), + + OPT_GROUP(N_("Emit [broken] object attributes")), + OPT_CMDMODE('t', NULL, &opt, N_("show object type (one of 'blob', 'tree', 'commit', 'tag', ...)"), 't'), + OPT_CMDMODE('s', NULL, &opt, N_("show object size"), 's'), OPT_BOOL(0, "allow-unknown-type", &unknown_type, N_("allow -s and -t to work with broken/corrupt objects")), - OPT_BOOL(0, "buffer", &batch.buffer_output, N_("buffer --batch output")), - OPT_CALLBACK_F(0, "batch", &batch, "format", - N_("show info and content of objects fed from the standard input"), + /* Batch mode */ + OPT_GROUP(N_("Batch objects requested on stdin (or --batch-all-objects)")), + OPT_CALLBACK_F(0, "batch", &batch, N_("format"), + N_("show full or contents"), PARSE_OPT_OPTARG | PARSE_OPT_NONEG, batch_option_callback), - OPT_CALLBACK_F(0, "batch-check", &batch, "format", - N_("show info about objects fed from the standard input"), + OPT_CALLBACK_F(0, "batch-check", &batch, N_("format"), + N_("like --batch, but don't emit "), PARSE_OPT_OPTARG | PARSE_OPT_NONEG, batch_option_callback), + OPT_CMDMODE(0, "batch-all-objects", &opt, + N_("with --batch[-check]: ignores stdin, batches all known objects"), 'b'), + /* Batch-specific options */ + OPT_GROUP(N_("Change or optimize batch output")), + OPT_BOOL(0, "buffer", &batch.buffer_output, N_("buffer --batch output")), OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks, - N_("follow in-tree symlinks (used with --batch or --batch-check)")), + N_("follow in-tree symlinks")), OPT_BOOL(0, "unordered", &batch.unordered, - N_("do not order --batch-all-objects output")), + N_("do not order objects before emitting them")), + /* Textconv options, stand-ole*/ + OPT_GROUP(N_("Emit object (blob or tree) with conversion or filter (stand-alone, or with batch)")), + OPT_CMDMODE(0, "textconv", &opt, + N_("run textconv on object's content"), 'c'), + OPT_CMDMODE(0, "filters", &opt, + N_("run filters on object's content"), 'w'), + OPT_STRING(0, "path", &force_path, N_("blob|tree"), + N_("use a for (--textconv | --filters ); Not with 'batch'")), OPT_END() }; From patchwork Sat Nov 6 21:47:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE514C433F5 for ; Sat, 6 Nov 2021 21:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A89BE61027 for ; Sat, 6 Nov 2021 21:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbhKFVuA (ORCPT ); Sat, 6 Nov 2021 17:50:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbhKFVty (ORCPT ); Sat, 6 Nov 2021 17:49:54 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED780C061205 for ; Sat, 6 Nov 2021 14:47:12 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id d24so19645813wra.0 for ; Sat, 06 Nov 2021 14:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L7RXSh0sSGc01+CkbVX6cZFC6IlkrRUvM5uVfLfmspo=; b=fElVWLH+NP/Et5ECOX/2+OJyrmSTP1EZwxSj//X5VN5Vs5J7Jbgop5oz0QBlpi+/m3 RdKfl2FhMavTU8bvhJbMzJk+0XbAvV3N47QnVh+b9ZnjMO1QGhadpYdLOIr2EQQ7s93/ u6zjkEv/W3tAsj0fnTM5f2JZwbTgl14q1X0nIJ2mK+TFfsKsXN3yIudZIQSJZF8Otpxh fAVsVZbOAEqwtY3Y+TvMDkdAUm2zE1BPoVl+ihEF5OjAWu7BpZbvHiCpFN3iXQ0I9wSP AsV1m4bA5DOmhM7NOo8JtQcbYAXTErXJbVbioAVd2RPMlcnXQbYDZHmD4Nj4izYvgZlv M3pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L7RXSh0sSGc01+CkbVX6cZFC6IlkrRUvM5uVfLfmspo=; b=OTmSjIDUR9sUwUSPley4dltY+c35lNq7K+jpeqtwY4pysWIu0eMFJDqUPn3rYL7G1k U92c3RmW7N0GmMmO0MIBFcYUjmTgxm5V9HosDD1V6L4byu+YGCPrAV71XsxVK7RN3MlA ySrjkAOiMQHsBx4jdFmTi9Y4vvVUoZxAeMke/oESZAka6Gh++uTRKxUkD40FdaH8eKiL ZF2wR+1NGIFHlEcz108XQuTPUp8/yGae/Uxh8wMlENWnwFbBJWj1y+rjvUikrWfQIC1n iiJS6ilu+LsVk8IuBjVYaBmJfS+qjcRYwz2/yezotPXO3jdm4iwuHSizunRAmX3Z69xq e0rQ== X-Gm-Message-State: AOAM532V44jnHKlLgAu1My5nL4ALU5BB59xxjzzGsCWbPuullZUvqbOE E4/YZgLLnt/yZrGY3AbJDsskn9XSXtB3ew== X-Google-Smtp-Source: ABdhPJw4ooZXvJvFbEDJ0fl5CyZPRHBg4pd08hp0SCR2emH/Gy1coKFD+A4b0fiwSh7AF7hu86Gq8w== X-Received: by 2002:adf:dc43:: with SMTP id m3mr87002879wrj.66.1636235231365; Sat, 06 Nov 2021 14:47:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:10 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 09/10] object-name.c: don't have GET_OID_ONLY_TO_DIE imply *_QUIETLY Date: Sat, 6 Nov 2021 22:47:01 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Stop having GET_OID_ONLY_TO_DIE imply GET_OID_QUIETLY in get_oid_with_context_1(). The *_DIE flag was added in 33bd598c390 (sha1_name.c: teach lookup context to get_sha1_with_context(), 2012-07-02), and then later tweaked in 7243ffdd78d (get_sha1: avoid repeating ourselves via ONLY_TO_DIE, 2016-09-26). Everything in that commit makes sense, but only for callers that expect to fail in an initial call to get_oid_with_context_1(), e.g. as "git show 0017" does via handle_revision_arg(), and then would like to call get_oid_with_context_1() again via this maybe_die_on_misspelt_object_name() function. In the subsequent commit we'll add a new caller that excepts to call this only once, but who would still like to have all the error messaging that GET_OID_ONLY_TO_DIE gives it, in addition to any regular errors. Signed-off-by: Ævar Arnfjörð Bjarmason --- object-name.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/object-name.c b/object-name.c index fdff4601b2c..d44a8f3a7ca 100644 --- a/object-name.c +++ b/object-name.c @@ -1795,9 +1795,6 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, const char *cp; int only_to_die = flags & GET_OID_ONLY_TO_DIE; - if (only_to_die) - flags |= GET_OID_QUIETLY; - memset(oc, 0, sizeof(*oc)); oc->mode = S_IFINVALID; strbuf_init(&oc->symlink_path, 0); @@ -1932,7 +1929,7 @@ void maybe_die_on_misspelt_object_name(struct repository *r, { struct object_context oc; struct object_id oid; - get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE, + get_oid_with_context_1(r, name, GET_OID_ONLY_TO_DIE | GET_OID_QUIETLY, prefix, &oid, &oc); } From patchwork Sat Nov 6 21:47:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12606625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95AFCC433EF for ; Sat, 6 Nov 2021 21:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DC9E61027 for ; Sat, 6 Nov 2021 21:47:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233921AbhKFVuB (ORCPT ); Sat, 6 Nov 2021 17:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234211AbhKFVt4 (ORCPT ); Sat, 6 Nov 2021 17:49:56 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A038DC06120B for ; Sat, 6 Nov 2021 14:47:13 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id i5so19646224wrb.2 for ; Sat, 06 Nov 2021 14:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SkAYpnila8VBQ1Jxlb2SWW+uUM6t37f/oTL3Bc8EYao=; b=dUX5uYaxXfT+5qlsHgjHCHJMMYMHGlrICvz+w7iGN2UHtsJ4pt7WOIKQwvnVA7Vwrc 7aDD3uvfraFp3b3lCUq+TtEN+aL9VQcyV2JzfgD+0cLUGoh8G6m4Zb4wWEjOMFe8axOH t/FjR665iO/2GEstwime9N6NmeiXnbzqYervlBhjYx8we3J7yGP4gb6jfY2bCSd4czUg tSW/LhA/6eduWw8dIzUbQ4mhfU7SNGZzO75DcWcGVnxJhHBuC+wHP3bTJRU64usWBh9+ BEsvcRCY+4orM1231/V76+Xb9MnFJr8H5UUnfuAPdjlEveZrcb3O2fLeXy6IYS4gODN6 GFHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SkAYpnila8VBQ1Jxlb2SWW+uUM6t37f/oTL3Bc8EYao=; b=xYeEPt9CrGbVuM0FE6RrKxegpic+VFVQTJoqiFvegn2WpH2eGCgL5vyf7uIZ5s9X04 z43j2StnwqiPhEhLWmbfx7/22uRin3HgQMLNwj8VqXWVL25jcYrspe+zZGZAWhoGbnVX wiCL/Ajt7fEc6d4t17EXDco8Nah/oxYqHgBgRLOIWXPr62AT8ge2tqeDjUzNFdHXZc4w Vh6L8RFYTSe3Cgm+5rf20bCGp+fl7chJ3vcMdG+hFN3dFNqRgRJh00qbehMFhw9DOBz8 0lrJ/8K8tKOaBA3DPf/yrpGWMrX0VWqqHcZxEh+md8QiqauwuN6Fdwvj7i/JK22zzrT7 nGNw== X-Gm-Message-State: AOAM533ArZtMeCCbu2fCua2nECa8BixsK7Ti2hos5ozd2Wr1y1n1i1S0 fOLDweApUCxebtpkZGqgfXtkngajI9NOAA== X-Google-Smtp-Source: ABdhPJyUnTWuS3n0mZ2UEhAVj7gke/8Kt4qg3pUX8yksi4Qc/2FPHli/v4i+OfTPxYJe/MF7HLAEeA== X-Received: by 2002:adf:fe8b:: with SMTP id l11mr82190081wrr.228.1636235232011; Sat, 06 Nov 2021 14:47:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f19sm12736630wmq.34.2021.11.06.14.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 14:47:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 10/10] cat-file: improve --(textconv|filters) disambiguation Date: Sat, 6 Nov 2021 22:47:02 +0100 Message-Id: X-Mailer: git-send-email 2.34.0.rc1.741.gab7bfd97031 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Improve the errors emitted when an invalid and/or is provided with either the --path option, or as an argument. We now use the same logic in get_oid_with_context_1() that "git show" et al use. To replace the "cat-file" use-case we need to introduce a new "GET_OID_REQUIRE_PATH" flag, otherwise it would exit early as soon as a valid "HEAD" was resolved, but in the "cat-file" case being changed we always need a valid revision and path. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 15 +++++---------- cache.h | 1 + object-name.c | 6 +++++- t/t8007-cat-file-textconv.sh | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 1d7f79184f0..b76f2a00046 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -73,14 +73,16 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, struct object_info oi = OBJECT_INFO_INIT; struct strbuf sb = STRBUF_INIT; unsigned flags = OBJECT_INFO_LOOKUP_REPLACE; + unsigned get_oid_flags = GET_OID_RECORD_PATH | GET_OID_ONLY_TO_DIE; const char *path = force_path; + if (!path && (opt == 'w' || opt == 'c')) + get_oid_flags |= GET_OID_REQUIRE_PATH; if (unknown_type) flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE; - if (get_oid_with_context(the_repository, obj_name, - GET_OID_RECORD_PATH, - &oid, &obj_context)) + if (get_oid_with_context(the_repository, obj_name, get_oid_flags, &oid, + &obj_context)) die("Not a valid object name %s", obj_name); if (!path) @@ -112,9 +114,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, return !has_object_file(&oid); case 'w': - if (!path) - die("git cat-file --filters %s: must be " - "", obj_name); if (filter_object(path, obj_context.mode, &oid, &buf, &size)) @@ -122,10 +121,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, break; case 'c': - if (!path) - die("git cat-file --textconv %s: must be ", - obj_name); - if (textconv_object(the_repository, path, obj_context.mode, &oid, 1, &buf, &size)) break; diff --git a/cache.h b/cache.h index eba12487b99..788127a9869 100644 --- a/cache.h +++ b/cache.h @@ -1366,6 +1366,7 @@ struct object_context { #define GET_OID_FOLLOW_SYMLINKS 0100 #define GET_OID_RECORD_PATH 0200 #define GET_OID_ONLY_TO_DIE 04000 +#define GET_OID_REQUIRE_PATH 010000 #define GET_OID_DISAMBIGUATORS \ (GET_OID_COMMIT | GET_OID_COMMITTISH | \ diff --git a/object-name.c b/object-name.c index d44a8f3a7ca..e94ced3f170 100644 --- a/object-name.c +++ b/object-name.c @@ -1799,8 +1799,12 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, oc->mode = S_IFINVALID; strbuf_init(&oc->symlink_path, 0); ret = get_oid_1(repo, name, namelen, oid, flags); - if (!ret) + if (!ret) { + if (flags & GET_OID_REQUIRE_PATH) + die(_(": required, only '%s' given"), name); return ret; + } + /* * tree:path --> object name of path in tree * :path -> object name of absolute path in index diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index 45471cefe73..0b79750cf1e 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -27,19 +27,19 @@ test_expect_success 'usage' ' test_cmp expect actual && cat >expect <<-\EOF && - fatal: Not a valid object name HEAD2:two.bin + fatal: invalid object name '\''HEAD2'\''. EOF test_must_fail git cat-file --textconv HEAD2:two.bin 2>actual && test_cmp expect actual && cat >expect <<-\EOF && - fatal: git cat-file --textconv HEAD: must be + fatal: : required, only '\''HEAD'\'' given EOF test_must_fail git cat-file --textconv HEAD 2>actual && test_cmp expect actual && cat >expect <<-\EOF && - fatal: Not a valid object name HEAD:two.bin + fatal: path '\''two.bin'\'' does not exist in '\''HEAD'\'' EOF test_must_fail git cat-file --textconv HEAD:two.bin 2>actual && test_cmp expect actual