From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A060BC433FE for ; Wed, 8 Dec 2021 12:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233630AbhLHMiQ (ORCPT ); Wed, 8 Dec 2021 07:38:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233533AbhLHMiJ (ORCPT ); Wed, 8 Dec 2021 07:38:09 -0500 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC99EC0698C8 for ; Wed, 8 Dec 2021 04:34:36 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so4036800wmj.5 for ; Wed, 08 Dec 2021 04:34:36 -0800 (PST) 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=8erU62gnY9z8FpXa21+qVl7ToTIe6xEOPOzmYkn0RQQ=; b=gD/WO9HP2u6HoAUCRbsHKp3GUzx0SsXdRBh7oPsKxS783R7UEE73pZB5+t8VZFliMg c2JhRbmRSIJZTen/q2wKwuiJAw3LfvfakChtC+CCv/rAgbnVdK63t1xFOwy696w+sY7G Tqs/7m+u3ZwS6lRTSxziPO1M5JBetABAercl8BbSnQJg1WNojkPMCJLhW0T9zvNsOXiA +igRTl6pjWlYX/F2LonaK+IhIldrlUd+NiqZCsKSr3lAG39U2eCugoRt7sOm6/CLQgBO izyz9Wq+ENv5jzrEBF5KrzCIBwWkAu8JIXTBEB6cyKxgafZm11xbwKDenX2R+a3uQVmI 3rvw== 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=8erU62gnY9z8FpXa21+qVl7ToTIe6xEOPOzmYkn0RQQ=; b=QjfPLRaVCEXLGlwIVn5NFeYvVu+F+LNiQtEgSOX5jJ5FONUN2cNBaK5H6Zgx1Z4oYm unG0+cIoD5eFVxYl6+4WtpASn0Ng153ultTLSGNNNW9Qg3x91pYC8FO1SPlo4RUstrue OE3IAziR04u1Lv6r4zGYNm6WUSqcWyRwXZG2k/95QLQQP3M33X/Eh6/2FgT5eaA9GW+0 0lthZuCnSjMPsIfHlXjWjhHFKKeRSsVfCHdwaxUD0mePVO60lA/OCFP4usCza337k9Jp GPlnPfJsYZBBxErR30yu0y5B9PMHYXaygulVj0sM6Ca9gySyigBNkXO/6B0OlEl3Qprb 8HGw== X-Gm-Message-State: AOAM533VFtQjj/4TZtUOlJBH64QUJZ6myuJS6/L1wqkFNv1eKPiFaBsG jZRilfDaZ5uarKiGTdS83d5i1PeGLd5ZNw== X-Google-Smtp-Source: ABdhPJyBCLCQDBwfq1Vkj7zKAu6ZYQP6ngE7DA94KlJc+a3Xf5D5yCt9/P20lGwfo87F9964IlKEzQ== X-Received: by 2002:a05:600c:1549:: with SMTP id f9mr15940791wmg.118.1638966875094; Wed, 08 Dec 2021 04:34:35 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id d8sm2540692wrm.76.2021.12.08.04.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 04:34:34 -0800 (PST) From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , John Cai , Sergey Organov , Jiang Xin , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v4 10/10] cat-file: use GET_OID_ONLY_TO_DIE in --(textconv|filters) Date: Wed, 8 Dec 2021 13:34:23 +0100 Message-Id: X-Mailer: git-send-email 2.34.1.926.g895e15e0c0c In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the cat_one_file() logic that calls get_oid_with_context() under --textconv and --filters to use the GET_OID_ONLY_TO_DIE flag, thus improving the error messaging emitted when e.g. is missing but is not. To service 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. This arguably makes the ":" and ":" use cases worse, as we won't quote the component at the user anymore, but let's just use the existing logic "git log" et al use for now. We can improve the messaging for those cases as a follow-up for all callers. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/cat-file.c | 16 ++++++---------- cache.h | 1 + object-name.c | 3 +++ t/t8007-cat-file-textconv.sh | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index e71519739a4..f5437c2d045 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -73,14 +73,17 @@ 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; + const int opt_cw = (opt == 'c' || opt == 'w'); + if (!path && opt_cw) + 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 +115,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 +122,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..92862eeb1ac 100644 --- a/object-name.c +++ b/object-name.c @@ -1799,6 +1799,9 @@ 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 && flags & GET_OID_REQUIRE_PATH) + die(_(": required, only '%s' given"), + name); if (!ret) return ret; /* diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index 71ea2ac987e..b067983ba1c 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -29,7 +29,7 @@ test_expect_success 'usage: ' ' test_expect_success 'usage: :' ' 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 @@ -37,7 +37,7 @@ test_expect_success 'usage: :' ' test_expect_success 'usage: :' ' 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 @@ -46,7 +46,7 @@ test_expect_success 'usage: :' ' test_expect_success 'usage: with no ' ' 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 @@ -55,7 +55,7 @@ test_expect_success 'usage: with no ' ' test_expect_success 'usage: :' ' cat >expect <<-\EOF && - fatal: Not a valid object name HEAD2:one.bin + fatal: invalid object name '\''HEAD2'\''. EOF test_must_fail git cat-file --textconv HEAD2:one.bin 2>actual && test_cmp expect actual -- 2.34.1.926.g895e15e0c0c