From patchwork Thu Dec 2 18:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653237 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 ED930C433EF for ; Thu, 2 Dec 2021 18:40:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376413AbhLBSnb (ORCPT ); Thu, 2 Dec 2021 13:43:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242281AbhLBSn3 (ORCPT ); Thu, 2 Dec 2021 13:43:29 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E65DC06174A for ; Thu, 2 Dec 2021 10:40:06 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id u1so608765wru.13 for ; Thu, 02 Dec 2021 10:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jL466pEYc6tScMJdo6weuZggZZcoDMfxZ5k5yFTYTd0=; b=Xt2Nz4TLJ3UO932DRnxNiFpK3T02ORvwhLfTj4uVt7yT8PLcdJefoYnIPtksd0QSVy MIOjSu5NpE2bUrLPchJw812Q75k2wU3TnUkfVFbbJQ12+imoDJE7OrQKKgpT6Noz5mrd T3DrCii70GQ6cnffDfahZaY6WP/J2KN9IN4lCPKn8/d/3i90Fwp+AT4rjE9RxsswxhE1 lSuc3Sk7jAWolcvWkGqcb8xtM3Bhz9c3GH67EMuM3796wlqr8SknRumFOgPRj3eOXqHx XlCjLpC8PITvNZH5SjDCl+t/Hg+ttaA0Zd2aViUdQKT7Pl+XdwTAvx190HBKnqyisBt+ w0zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jL466pEYc6tScMJdo6weuZggZZcoDMfxZ5k5yFTYTd0=; b=vevuQw1p7H9reqXuqc1HsaHNITozPBiKXqz2VQgou/MhffhWMBRUl3LUJhikP9wpSk PIkrsiVXsKILm68+KSeO3fqHbjx6/C9e8HcWMvc29VRVyKGGDo41MR2x0/UL2o8oKxp7 DjRPzqRpV7zz0envWzO0MgJvj52r66RDbmigHWY28K4jubsi4YGSWDDWjN6qsEIYLTto QL1EqqR3z+TPDmh+mY/HBd8NZsWEHHSaSzKvpLsRwfNtPqCNhJE243NItY/4fOSuuKqn XvSc9LgIwbuN/D7djvhu66f8RDdsuKx1PtPJdit4qJfrQaF9mGkfb4KPWzxNoIy/uK8a 4W8A== X-Gm-Message-State: AOAM531EjFJq6g2LTozjLASL5jSIBhujo7IT85gd+spTRjLTna963vdf NrKdtg+eUCZPywA0F3nW6D60bC/1Ce8= X-Google-Smtp-Source: ABdhPJwM0aDLh3TJVTZPSysuBHmOPT0x31ud3OShOQ/GxsX9DszWOvuc2T45miBVLQV3gt1ujPvkLg== X-Received: by 2002:adf:d1e2:: with SMTP id g2mr16510486wrd.179.1638470404770; Thu, 02 Dec 2021 10:40:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t17sm3009657wmq.15.2021.12.02.10.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:04 -0800 (PST) Message-Id: <3649ef6d0fa14ea1796264188466cdfc42d6d9e1.1638470403.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 02 Dec 2021 18:39:55 +0000 Subject: [PATCH v3 1/8] test-ref-store: remove force-create argument for create-reflog Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Nobody uses force_create=0, so this flag is unnecessary. Signed-off-by: Han-Wen Nienhuys --- t/helper/test-ref-store.c | 2 +- t/t1405-main-ref-store.sh | 5 ++--- t/t1406-submodule-ref-store.sh | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 3986665037a..b795a56eedf 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -182,9 +182,9 @@ static int cmd_reflog_exists(struct ref_store *refs, const char **argv) static int cmd_create_reflog(struct ref_store *refs, const char **argv) { const char *refname = notnull(*argv++, "refname"); - int force_create = arg_flags(*argv++, "force-create"); struct strbuf err = STRBUF_INIT; int ret; + int force_create = 1; ret = refs_create_reflog(refs, refname, force_create, &err); if (err.len) diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 49718b7ea7f..5e0f7073286 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -35,8 +35,7 @@ test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' git rev-parse FOO -- && git rev-parse refs/tags/new-tag -- && m=$(git rev-parse main) && - REF_NO_DEREF=1 && - $RUN delete-refs $REF_NO_DEREF nothing FOO refs/tags/new-tag && + $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag && test_must_fail git rev-parse --symbolic-full-name FOO && test_must_fail git rev-parse FOO -- && test_must_fail git rev-parse refs/tags/new-tag -- @@ -108,7 +107,7 @@ test_expect_success 'delete_reflog(HEAD)' ' ' test_expect_success 'create-reflog(HEAD)' ' - $RUN create-reflog HEAD 1 && + $RUN create-reflog HEAD && git reflog exists HEAD ' diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh index 0a87058971e..f1e57a9c051 100755 --- a/t/t1406-submodule-ref-store.sh +++ b/t/t1406-submodule-ref-store.sh @@ -92,7 +92,7 @@ test_expect_success 'delete_reflog() not allowed' ' ' test_expect_success 'create-reflog() not allowed' ' - test_must_fail $RUN create-reflog HEAD 1 + test_must_fail $RUN create-reflog HEAD ' test_done From patchwork Thu Dec 2 18:39:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653245 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 C75EEC433FE for ; Thu, 2 Dec 2021 18:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376628AbhLBSne (ORCPT ); Thu, 2 Dec 2021 13:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348349AbhLBSna (ORCPT ); Thu, 2 Dec 2021 13:43:30 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3483BC061758 for ; Thu, 2 Dec 2021 10:40:07 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so3072468wme.0 for ; Thu, 02 Dec 2021 10:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eOVaXRyEW4I+R8MQt1q26NykBYsWtrIR+bY5GzLeR/8=; b=SipttDS+OLVDgDkqY6Y4mZm3XZ1nziGlDK6WpqXMXW2nY+ZTxASy1srpgaTf9LSUGd X8e087Xscvl6KQFKoD0Y/odC8e9Ay1uN9uJd/k+bn6YLhVhraJuv2jeK6KuYdou+pmpt +rEbG+jgxWXIIPqapeNe1+1sk7kIqOTDwHMO6KDypYQHCsiZQQ6qpLU9f91adCjW2WJo B9T72yoABL79NO5lwZFxOKtRCPRUxT1sJKOPuE//angmOqFnYs93gmApT/m3yenUM1Af bLe2WxPVUxicP10KtSuQuP3yiKaTL0yRWsONJGnwyoHoN9UhAX/UqKraT+JcQYLLzrqQ qAgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eOVaXRyEW4I+R8MQt1q26NykBYsWtrIR+bY5GzLeR/8=; b=6whxEUU9qLpVjsGlRIDSkS69IDxRWw+fygeNNiTs5JXNZhnSQiK+DvGxVKAKA+RGwo txJS5o1GRn68KVOGUBlxAptZo5AbNjAK7kKFRj2EQhKXks/1hszqur3VUomUYxAOXexY Pdbths/aeUro7OI+qhbaLGcUWpe3UMHRL93SFXodsRTkFIMOJOfAVz6GDL2kGx9YCntj cYqSmhWmq5tB5qaSnA9iTiJfviw1zh/1S3gLJPgTdnULxS9FZkX/VxtJQDK1GK0J9J/X 8E6Th057DSoDFW3mBeehLotBc1H+nOgtSld0GP5NXM/FN9taCqqvwzNViqY8J0fIj4+z p81w== X-Gm-Message-State: AOAM530xkMc0GqZraTCgvEmeU3Z/+kvyCBoNej+DTL4bEO2GYVnAGqUZ r+Mugz5dKveHjMCW/08Ggk0GQoNVTYg= X-Google-Smtp-Source: ABdhPJzVtRguGdqeQ5FfGqVeEtAQMCoJdhNQFnDEd6z7pDPro4C+5XeueTQFlDXtEqF1NOfb3ZI6vQ== X-Received: by 2002:a05:600c:c1:: with SMTP id u1mr8275429wmm.163.1638470405581; Thu, 02 Dec 2021 10:40:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x13sm559271wrr.47.2021.12.02.10.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:05 -0800 (PST) Message-Id: <3cdebd2dbcad2f6d428d88846569d6563249dad8.1638470403.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 02 Dec 2021 18:39:56 +0000 Subject: [PATCH v3 2/8] test-ref-store: parse symbolic flag constants Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys This lets tests use REF_XXXX constants instead of hardcoded integers. The flag names should be separated by a ','. Signed-off-by: Han-Wen Nienhuys --- t/helper/test-ref-store.c | 69 +++++++++++++++++++++++++++++++++++---- t/t1405-main-ref-store.sh | 3 +- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index b795a56eedf..cbf1b5f506d 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -5,6 +5,50 @@ #include "object-store.h" #include "repository.h" +struct flag_definition { + const char *name; + uint64_t mask; +}; + +#define FLAG_DEF(x) \ + { \ +#x, (x) \ + } + +static unsigned int parse_flags(const char *str, struct flag_definition *defs) +{ + struct string_list masks = STRING_LIST_INIT_DUP; + int i = 0; + unsigned int result = 0; + + if (!strcmp(str, "0")) + return 0; + + string_list_split(&masks, str, ',', 64); + for (; i < masks.nr; i++) { + const char *name = masks.items[i].string; + struct flag_definition *def = defs; + int found = 0; + while (def->name) { + if (!strcmp(def->name, name)) { + result |= def->mask; + found = 1; + break; + } + def++; + } + if (!found) + die("unknown flag \"%s\"", name); + } + + string_list_clear(&masks, 0); + return result; +} + +static struct flag_definition empty_flags[] = { + { NULL, 0 }, +}; + static const char *notnull(const char *arg, const char *name) { if (!arg) @@ -12,9 +56,10 @@ static const char *notnull(const char *arg, const char *name) return arg; } -static unsigned int arg_flags(const char *arg, const char *name) +static unsigned int arg_flags(const char *arg, const char *name, + struct flag_definition *defs) { - return atoi(notnull(arg, name)); + return parse_flags(notnull(arg, name), defs); } static const char **get_store(const char **argv, struct ref_store **refs) @@ -64,10 +109,14 @@ static const char **get_store(const char **argv, struct ref_store **refs) return argv + 1; } +static struct flag_definition pack_flags[] = { + FLAG_DEF(PACK_REFS_PRUNE), + FLAG_DEF(PACK_REFS_ALL), +}; static int cmd_pack_refs(struct ref_store *refs, const char **argv) { - unsigned int flags = arg_flags(*argv++, "flags"); + unsigned int flags = arg_flags(*argv++, "flags", pack_flags); return refs_pack_refs(refs, flags); } @@ -81,9 +130,15 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv) return refs_create_symref(refs, refname, target, logmsg); } +static struct flag_definition transaction_flags[] = { + FLAG_DEF(REF_NO_DEREF), + FLAG_DEF(REF_FORCE_CREATE_REFLOG), + { NULL, 0 }, +}; + static int cmd_delete_refs(struct ref_store *refs, const char **argv) { - unsigned int flags = arg_flags(*argv++, "flags"); + unsigned int flags = arg_flags(*argv++, "flags", transaction_flags); const char *msg = *argv++; struct string_list refnames = STRING_LIST_INIT_NODUP; @@ -120,7 +175,7 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv) { struct object_id oid = *null_oid(); const char *refname = notnull(*argv++, "refname"); - int resolve_flags = arg_flags(*argv++, "resolve-flags"); + int resolve_flags = arg_flags(*argv++, "resolve-flags", empty_flags); int flags; const char *ref; int ignore_errno; @@ -209,7 +264,7 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv) const char *msg = notnull(*argv++, "msg"); const char *refname = notnull(*argv++, "refname"); const char *sha1_buf = notnull(*argv++, "old-sha1"); - unsigned int flags = arg_flags(*argv++, "flags"); + unsigned int flags = arg_flags(*argv++, "flags", transaction_flags); struct object_id old_oid; if (get_oid_hex(sha1_buf, &old_oid)) @@ -224,7 +279,7 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv) const char *refname = notnull(*argv++, "refname"); const char *new_sha1_buf = notnull(*argv++, "new-sha1"); const char *old_sha1_buf = notnull(*argv++, "old-sha1"); - unsigned int flags = arg_flags(*argv++, "flags"); + unsigned int flags = arg_flags(*argv++, "flags", transaction_flags); struct object_id old_oid; struct object_id new_oid; diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh index 5e0f7073286..63e0ae82bdf 100755 --- a/t/t1405-main-ref-store.sh +++ b/t/t1405-main-ref-store.sh @@ -17,8 +17,7 @@ test_expect_success 'setup' ' test_expect_success REFFILES 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' ' N=`find .git/refs -type f | wc -l` && test "$N" != 0 && - ALL_OR_PRUNE_FLAG=3 && - $RUN pack-refs ${ALL_OR_PRUNE_FLAG} && + $RUN pack-refs PACK_REFS_PRUNE,PACK_REFS_ALL && N=`find .git/refs -type f` && test -z "$N" ' From patchwork Thu Dec 2 18:39:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653241 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 97F5FC43217 for ; Thu, 2 Dec 2021 18:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376638AbhLBSnf (ORCPT ); Thu, 2 Dec 2021 13:43:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235498AbhLBSnb (ORCPT ); Thu, 2 Dec 2021 13:43:31 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0338DC061759 for ; Thu, 2 Dec 2021 10:40:08 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so460840wme.4 for ; Thu, 02 Dec 2021 10:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=3alPs0V96A3U1mKPlrtf6B+b0US9dI+Mh5kG8iFdhAw=; b=FfRqoHZDmjmuYj4wgk6lRCICcOd/3KBnF5M5fukXxdBhRwmQJdxf65VApFS0qwa1Gk R4nOwJsnjZds+BN82Cz4gD6AnMXn2zS2gfMPJpSGVQiJKyaHRQQCXajavUEUUbx7Rr4K u+Wm5Vhn9X7rD9T+gC2ukukFfBgRa0mWeFJTew4sZ6+tND33hdAKp34mppJO9130iqds hWtabOmTkAy+KIENjNzohLuv3/pHWhIipAov5qPkTq0Or0zcVYADereYN0T/JGilYlkx zkhnmCnwVh+FSP/17KMGn0T8fk7Lya0UcpA7cws5VvCiXvvXLQCeu5vH7yXNkEZbO4Lr x6ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=3alPs0V96A3U1mKPlrtf6B+b0US9dI+Mh5kG8iFdhAw=; b=sGNg/uB1dF1/tp7jZJDfKn9bN0Wa/QLaPqYAF8VemIe0zud3f8tr6xZN48AHLhR9LS LPFpZiqTFJD90a+1UNN4+lQUQ8QJKJGfFZa9QBfPavitDzS5mIRcsrTL5+6BGK+uBH2H dmFQ3RFE1mcUA++bCS2uOiTnZE+r+bXtfMYxd7tTtQrUUs5EREl1WEVJ7CHxvhiyx3ac 9gfMOMEwUfcosyZVcHMWDQ6kRAXjOhumuwjXivA15Bb6EMypiOKSQ/WD5AiVKx8Ex7a/ A36ItIKd+x/lz7J9zpjU/uyE/hebGi/cjvJII+J2f1WKGUq+dk+Z5BX7TY5X6Unp5UCr il3Q== X-Gm-Message-State: AOAM5321XuOTvObt3F+QGIfccCFiFKJhAhE7rwXOwLtBiuZFY+Ijhucc HczwmwV62PQ0ks3uJBuzBKbk0B3kn3o= X-Google-Smtp-Source: ABdhPJzj8Ql8m6ZliEziwXJI1i20LZrsOA/iB8V8Ec5gD8YJx3pmSrM/A6VugtFtnPN9cSL5sV5J8Q== X-Received: by 2002:a7b:cd02:: with SMTP id f2mr8462767wmj.115.1638470406483; Thu, 02 Dec 2021 10:40:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v15sm583250wro.35.2021.12.02.10.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:06 -0800 (PST) Message-Id: <536005d65a26e8471bb0c5b9109a59319c636eb1.1638470403.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 02 Dec 2021 18:39:57 +0000 Subject: [PATCH v3 3/8] test-ref-store: plug memory leak in cmd_delete_refs Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- t/helper/test-ref-store.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index cbf1b5f506d..c8ae36e2172 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -141,11 +141,14 @@ static int cmd_delete_refs(struct ref_store *refs, const char **argv) unsigned int flags = arg_flags(*argv++, "flags", transaction_flags); const char *msg = *argv++; struct string_list refnames = STRING_LIST_INIT_NODUP; + int result; while (*argv) string_list_append(&refnames, *argv++); - return refs_delete_refs(refs, msg, &refnames, flags); + result = refs_delete_refs(refs, msg, &refnames, flags); + string_list_clear(&refnames, 0); + return result; } static int cmd_rename_ref(struct ref_store *refs, const char **argv) From patchwork Thu Dec 2 18:39:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653243 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 5EB9DC43219 for ; Thu, 2 Dec 2021 18:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376644AbhLBSng (ORCPT ); Thu, 2 Dec 2021 13:43:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376430AbhLBSnc (ORCPT ); Thu, 2 Dec 2021 13:43:32 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2B09C06174A for ; Thu, 2 Dec 2021 10:40:08 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id q3so700574wru.5 for ; Thu, 02 Dec 2021 10:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=jA2SVtXqn+u0233wQxvaNn9NKHl97Jzpp83rxUSYsyQ=; b=XRkxaeSBzukvwaKJ+PVXRAgY5q8oImlJghDX32SsQQktVETdEEgSjuJIrCP8c15vpi BScQRkXcejCQnuTM9iQ7fWT5GzlEBkwZ2XynrGn51gtg8/0LP5Iw41q2AQ9PFU8Ba/78 mDeArwtk7qFzRGGvX0dFEtOp0JImA3JAG3Z8JXpDiXrkW2QyPqxNVoNmUf4CQV9vcUeU NtT42Nt1Ix9qAVGazBi2z8OJQ5dCttjtf77w1NvogfQCSz/xn0gsOXuLalTido0OUD62 YdeETmiYYGXoBBPirbAFYqj2fBo6RK5mC+n2Apeq3ApdJ5t3d4pk3lo0HKbVovJnysPA H+nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=jA2SVtXqn+u0233wQxvaNn9NKHl97Jzpp83rxUSYsyQ=; b=0QC9dCRbLAf5bHF8PlJBYGVLQGKAi6TMVyFq3HVfU+Z3QIAeddzPWmYcrcV43orRMP iD6Hb9cBsWn9dIqmd3IMJy2mgN+cw2/TUf4SmE3rCPnPpjNU4UVZIG2qKz3/HCNWvEMn Hov8sNS55+C45nCL8B5cJEjTJaRehYn6qX+8CEPDXYP2BNNjgaFNaCK70Xk+zVKpQciX 4mpGFXjFi63128PStAPpcvg8p6ut0rK0TMsvJmladQvMFPLuQE6u7Q5BdxR7PdTPSSVM fZyeslgey1autA9ViRi9GetARttgC73/fNZ1tK/8LlOyFyCFGaP5yu+CGgf81qDMMEFt +ZNQ== X-Gm-Message-State: AOAM532Als0l1xPAH+bI4ODb09G/jOtuEdOrN2eEfvi69PdFDozj7B5e r6RA/hJVebifxMaBBqZfCE46etdk5EI= X-Google-Smtp-Source: ABdhPJyYAhi55aARZB9tQed7VE7Iv3dDIUtF0ikwvV7OAUhBTCpzYJq3wBUraoxtqg6FFnZ+7f/50A== X-Received: by 2002:a5d:42cf:: with SMTP id t15mr16256263wrr.444.1638470407421; Thu, 02 Dec 2021 10:40:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c6sm3858658wmq.46.2021.12.02.10.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:06 -0800 (PST) Message-Id: <466b4451015dfe4b2631f378dbf9631c04240f53.1638470403.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 02 Dec 2021 18:39:58 +0000 Subject: [PATCH v3 4/8] refs: update comment. Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys REF_IS_PRUNING is right below this comment, so it clearly does not belong in this comment. This was apparently introduced in commit 5ac95fee (Nov 5, 2017 "refs: tidy up and adjust visibility of the `ref_update` flags"). Signed-off-by: Han-Wen Nienhuys --- refs/files-backend.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4b14f30d48f..37329b98cca 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -16,8 +16,7 @@ * This backend uses the following flags in `ref_update::flags` for * internal bookkeeping purposes. Their numerical values must not * conflict with REF_NO_DEREF, REF_FORCE_CREATE_REFLOG, REF_HAVE_NEW, - * REF_HAVE_OLD, or REF_IS_PRUNING, which are also stored in - * `ref_update::flags`. + * or REF_HAVE_OLD, which are also stored in `ref_update::flags`. */ /* From patchwork Thu Dec 2 18:39:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653247 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 8EDFEC433F5 for ; Thu, 2 Dec 2021 18:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376653AbhLBSni (ORCPT ); Thu, 2 Dec 2021 13:43:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376625AbhLBSnd (ORCPT ); Thu, 2 Dec 2021 13:43:33 -0500 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 A08FFC061757 for ; Thu, 2 Dec 2021 10:40:09 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id a9so661428wrr.8 for ; Thu, 02 Dec 2021 10:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IEpsiqmWXpF3+dw1+Q0DTmfooQtpxnKXDD+MNAhBTKY=; b=oDlFLys+BQlu79L2ry+GkdcgkhGqAYY1iqItfrYXG7uKtRZ+DjLCx4LJxd47DRfKyN kvFcR1DSuJ4yuIWLXYoCZS9KcMgwubE00vMLgtR58okSenJhZ5lYdOpST2Q4wu+S8AQp QLz9HxzHOS88LYhce3kciRTjjqx+2F6Uf/xqb9srmeq5abkwxhYu01n3GsSH7F7Vi4/G IH9+IDxTovG8RzyLCYgtNtuDDiMrYXamS2Q2mVtWHlRJLZ3miX7qf+NGiDutSGMQkRXL puV9ThPBYnTFBDNTCHMGd7rrEZ8RUQvy1EDVJNIXR+lXSUGPHRCvkIoWsg1qWRUAnL8i oCCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IEpsiqmWXpF3+dw1+Q0DTmfooQtpxnKXDD+MNAhBTKY=; b=yu7aoLVUGrJhWTekYtOhF2spRqWwMddqX1Lo3WsiZRdjGipguhU4PB0KrVkTqqG/In IatJBAHnV98xd6r5zvTPdSJdGS8V9jb6Vs2MJuzh+tTGXGj01+OK61/AUbugS/Z+5+0G fQo/1V+S2J98xKUc3AzXimwF+/12wBYRgfk3FVA/FR/Jk+bGOLRNKSbefzQOzdv4S4id +elsd/CzXAnDWzBv8robJEiHHudq1FWCUcWOGABvo3k6jgYaw2GE7ni+5a+zQTFNEegO 59gBmGTJ/vWyjxpFMOZS7Du8K7J+mTPcwq43rqmRgBQjLLJxVxqw/prKMm72d8d8xpFL Jnyw== X-Gm-Message-State: AOAM530kGtykY8RVTupJvmghLkiTrqc5C/cgorBlbNt7R8Xf96ZUnb7O dtYqeNZ5y/bJiTglkir54HcQMGZRvhI= X-Google-Smtp-Source: ABdhPJzjn35AJC/P+/fZQSbNhycd9JJRvKDVMCk3CXyhJVCnMu8wkbkYxNZRJO8RYNzaxyypq3wGEg== X-Received: by 2002:adf:cc8d:: with SMTP id p13mr16154986wrj.274.1638470408080; Thu, 02 Dec 2021 10:40:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r83sm2938716wma.22.2021.12.02.10.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:07 -0800 (PST) Message-Id: <89d692a34b8023c536deaa1e50bc41ceb511d0b3.1638470403.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 02 Dec 2021 18:39:59 +0000 Subject: [PATCH v3 5/8] refs: introduce REF_SKIP_OID_VERIFICATION flag Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys This lets the ref-store test helper write non-existent or unparsable objects into the ref storage. Use this to make t1006 and t3800 independent of the files storage backend. Signed-off-by: Han-Wen Nienhuys --- refs.h | 8 ++++++- refs/files-backend.c | 50 +++++++++++++++++++++++---------------- t/helper/test-ref-store.c | 1 + t/t1006-cat-file.sh | 5 ++-- t/t3800-mktag.sh | 6 +++-- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/refs.h b/refs.h index 45c34e99e3a..76efc589cca 100644 --- a/refs.h +++ b/refs.h @@ -615,12 +615,18 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err); */ #define REF_FORCE_CREATE_REFLOG (1 << 1) +/* + * Blindly write an object_id. This is useful for testing data corruption + * scenarios. + */ +#define REF_SKIP_OID_VERIFICATION (1 << 10) + /* * Bitmask of all of the flags that are allowed to be passed in to * ref_transaction_update() and friends: */ #define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \ - (REF_NO_DEREF | REF_FORCE_CREATE_REFLOG) + (REF_NO_DEREF | REF_FORCE_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION) /* * Add a reference update to transaction. `new_oid` is the value that diff --git a/refs/files-backend.c b/refs/files-backend.c index 37329b98cca..d0019fcd8b7 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1353,7 +1353,8 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname) } static int write_ref_to_lockfile(struct ref_lock *lock, - const struct object_id *oid, struct strbuf *err); + const struct object_id *oid, + int skip_oid_verification, struct strbuf *err); static int commit_ref_update(struct files_ref_store *refs, struct ref_lock *lock, const struct object_id *oid, const char *logmsg, @@ -1500,7 +1501,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, } oidcpy(&lock->old_oid, &orig_oid); - if (write_ref_to_lockfile(lock, &orig_oid, &err) || + if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) || commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) { error("unable to write current sha1 into %s: %s", newrefname, err.buf); strbuf_release(&err); @@ -1520,7 +1521,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, flag = log_all_ref_updates; log_all_ref_updates = LOG_REFS_NONE; - if (write_ref_to_lockfile(lock, &orig_oid, &err) || + if (write_ref_to_lockfile(lock, &orig_oid, 0, &err) || commit_ref_update(refs, lock, &orig_oid, NULL, &err)) { error("unable to write current sha1 into %s: %s", oldrefname, err.buf); strbuf_release(&err); @@ -1756,26 +1757,31 @@ static int files_log_ref_write(struct files_ref_store *refs, * errors, rollback the lockfile, fill in *err and return -1. */ static int write_ref_to_lockfile(struct ref_lock *lock, - const struct object_id *oid, struct strbuf *err) + const struct object_id *oid, + int skip_oid_verification, struct strbuf *err) { static char term = '\n'; struct object *o; int fd; - o = parse_object(the_repository, oid); - if (!o) { - strbuf_addf(err, - "trying to write ref '%s' with nonexistent object %s", - lock->ref_name, oid_to_hex(oid)); - unlock_ref(lock); - return -1; - } - if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) { - strbuf_addf(err, - "trying to write non-commit object %s to branch '%s'", - oid_to_hex(oid), lock->ref_name); - unlock_ref(lock); - return -1; + if (!skip_oid_verification) { + o = parse_object(the_repository, oid); + if (!o) { + strbuf_addf( + err, + "trying to write ref '%s' with nonexistent object %s", + lock->ref_name, oid_to_hex(oid)); + unlock_ref(lock); + return -1; + } + if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) { + strbuf_addf( + err, + "trying to write non-commit object %s to branch '%s'", + oid_to_hex(oid), lock->ref_name); + unlock_ref(lock); + return -1; + } } fd = get_lock_file_fd(&lock->lk); if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 || @@ -2189,7 +2195,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator) } static int files_reflog_iterator_peel(struct ref_iterator *ref_iterator, - struct object_id *peeled) + struct object_id *peeled) { BUG("ref_iterator_peel() called for reflog_iterator"); } @@ -2575,8 +2581,10 @@ static int lock_ref_for_update(struct files_ref_store *refs, * The reference already has the desired * value, so we don't need to write it. */ - } else if (write_ref_to_lockfile(lock, &update->new_oid, - err)) { + } else if (write_ref_to_lockfile( + lock, &update->new_oid, + update->flags & REF_SKIP_OID_VERIFICATION, + err)) { char *write_err = strbuf_detach(err, NULL); /* diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index c8ae36e2172..ac8fa2fe730 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -133,6 +133,7 @@ static int cmd_create_symref(struct ref_store *refs, const char **argv) static struct flag_definition transaction_flags[] = { FLAG_DEF(REF_NO_DEREF), FLAG_DEF(REF_FORCE_CREATE_REFLOG), + FLAG_DEF(REF_SKIP_OID_VERIFICATION), { NULL, 0 }, }; diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 658628375c8..0d4c55f74ec 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -452,9 +452,8 @@ test_expect_success 'the --allow-unknown-type option does not consider replaceme # Create it manually, as "git replace" will die on bogus # types. head=$(git rev-parse --verify HEAD) && - test_when_finished "rm -rf .git/refs/replace" && - mkdir -p .git/refs/replace && - echo $head >.git/refs/replace/$bogus_short_sha1 && + test_when_finished "test-tool ref-store main delete-refs 0 msg refs/replace/$bogus_short_sha1" && + test-tool ref-store main update-ref msg "refs/replace/$bogus_short_sha1" $head $ZERO_OID REF_SKIP_OID_VERIFICATION && cat >expect <<-EOF && commit diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 0544d58a6ea..e3cf0ffbe59 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -72,7 +72,8 @@ check_verify_failure () { # Manually create the broken, we cannot do it with # update-ref - echo "$bad_tag" >"bad-tag/$tag_ref" && + test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" && + test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && # Unlike fsck-ing unreachable content above, this # will always fail. @@ -83,7 +84,8 @@ check_verify_failure () { # Make sure the earlier test created it for us git rev-parse "$bad_tag" && - echo "$bad_tag" >"bad-tag/$tag_ref" && + test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" && + test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION && printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected && git -C bad-tag for-each-ref "$tag_ref" >actual && From patchwork Thu Dec 2 18:40:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653249 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 8EA5AC001B6 for ; Thu, 2 Dec 2021 18:40:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376667AbhLBSnk (ORCPT ); Thu, 2 Dec 2021 13:43:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348134AbhLBSne (ORCPT ); Thu, 2 Dec 2021 13:43:34 -0500 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 6B073C06174A for ; Thu, 2 Dec 2021 10:40:10 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id u1so609238wru.13 for ; Thu, 02 Dec 2021 10:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Jp0aKmt+Bddo4/E/zxJIMe7vzz0j+Z/sXLOUzaPrXbE=; b=Udd9pMMY/9rwGbrfPL8ymvGOvyTzkw5T5JDUMT1xRvLOkaAqlpZ9vUJrdJwmBN67Ld 4gBpwvXfVUKhpIpNEpr57dIHM1FZRsL9o2s+VLyUBDtjadelkYpOhdrZqmn2bwNgQFZy ME0dIjI+JcUNoInCRvNojYP0VtAFB0NNqS90ByhcPdBxZBcEwtI7VfEiwzKd59DjFI5u KgUyenpQJj7Dr3PgyZIT/4YTP3xZ98Hd0pQ3vvSqxzfHg7ICYKyiXVuesTnaHDzzDigl /+caeG3wSY6l1olT4WP1i2GijA48O8x2x4epVr7Bxc7kVcp6PHeadzjsqH516ruCMtGn aGtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Jp0aKmt+Bddo4/E/zxJIMe7vzz0j+Z/sXLOUzaPrXbE=; b=C05X6PhGk4CDQHXviLQ6UuAA4cl58mpyCgChM9wYkyoD20cMnavJtu1cjDXCsX7FNz JOjsdalg0wt5BY0oz9FNYQPjMW8yK2Y6Z+nQGB6mex4XriAc3f+ZeOXAhUk1VSmZ3xYQ cUaYYC138slOLT78v2+FvyAYiL3DZnI3ScEbWSP4QLYyw19cEbNll8GrVQ9+inz5eCsQ AMcS0LIa0Aogs+VK7YXZpNPcqLF4tsSoWL+iqWgMlXnfXmL44dVPHE4St3SYlU5DEmtD cH5VIyYzumkGdlzCLe4/doRdOz69zUWz2LeFRVlG+lMiK7XbgsqfFSi2dd8aXcYWPopa gASw== X-Gm-Message-State: AOAM531/a6RsasCy3Dl4W/g2HubpCI0rpRq0OIuEslLaTC8TsrLDcZe6 fI94Jv420JcReWzcIilXn4zdERwd1ZM= X-Google-Smtp-Source: ABdhPJxN+/fsFZJAJWriwmRVnzFWXpr6vYCVUH/aH0REzjRSfnxyFc7Kwa3wHMjW/XHNE9WbIeWk5A== X-Received: by 2002:a5d:68d2:: with SMTP id p18mr16378243wrw.21.1638470408773; Thu, 02 Dec 2021 10:40:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y6sm2861834wma.37.2021.12.02.10.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:08 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 02 Dec 2021 18:40:00 +0000 Subject: [PATCH v3 6/8] refs: introduce REF_SKIP_REFNAME_VERIFICATION flag Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Use this flag with the test-helper in t1430, to avoid direct writes to the ref database. Signed-off-by: Han-Wen Nienhuys --- refs.c | 7 +++-- refs.h | 10 +++++-- t/helper/test-ref-store.c | 1 + t/t1430-bad-ref-name.sh | 59 +++++++++++++++++++++------------------ 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/refs.c b/refs.c index 996ac271641..93bfe5b30cf 100644 --- a/refs.c +++ b/refs.c @@ -1083,9 +1083,10 @@ int ref_transaction_update(struct ref_transaction *transaction, { assert(err); - if ((new_oid && !is_null_oid(new_oid)) ? - check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) : - !refname_is_safe(refname)) { + if (!(flags & REF_SKIP_REFNAME_VERIFICATION) && + ((new_oid && !is_null_oid(new_oid)) ? + check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) : + !refname_is_safe(refname))) { strbuf_addf(err, _("refusing to update ref with bad name '%s'"), refname); return -1; diff --git a/refs.h b/refs.h index 76efc589cca..65017ceaefc 100644 --- a/refs.h +++ b/refs.h @@ -621,12 +621,18 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err); */ #define REF_SKIP_OID_VERIFICATION (1 << 10) +/* + * Skip verifying refname. This is useful for testing data corruption scenarios. + */ +#define REF_SKIP_REFNAME_VERIFICATION (1 << 11) + /* * Bitmask of all of the flags that are allowed to be passed in to * ref_transaction_update() and friends: */ -#define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \ - (REF_NO_DEREF | REF_FORCE_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION) +#define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \ + (REF_NO_DEREF | REF_FORCE_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION | \ + REF_SKIP_REFNAME_VERIFICATION) /* * Add a reference update to transaction. `new_oid` is the value that diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index ac8fa2fe730..78270b3c880 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -134,6 +134,7 @@ static struct flag_definition transaction_flags[] = { FLAG_DEF(REF_NO_DEREF), FLAG_DEF(REF_FORCE_CREATE_REFLOG), FLAG_DEF(REF_SKIP_OID_VERIFICATION), + FLAG_DEF(REF_SKIP_REFNAME_VERIFICATION), { NULL, 0 }, }; diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh index 4c77cf89a6c..326e5bd5e80 100755 --- a/t/t1430-bad-ref-name.sh +++ b/t/t1430-bad-ref-name.sh @@ -9,7 +9,8 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success setup ' test_commit one && - test_commit two + test_commit two && + main_sha1=$(git rev-parse refs/heads/main) ' test_expect_success 'fast-import: fail on invalid branch name ".badbranchname"' ' @@ -43,16 +44,16 @@ test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"' ' test_expect_success 'git branch shows badly named ref as warning' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch >output 2>error && test_i18ngrep -e "ignoring ref with broken name refs/heads/broken\.\.\.ref" error && ! grep -e "broken\.\.\.ref" output ' test_expect_success 'branch -d can delete badly named ref' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch -d broken...ref && git branch >output 2>error && ! grep -e "broken\.\.\.ref" error && @@ -60,8 +61,8 @@ test_expect_success 'branch -d can delete badly named ref' ' ' test_expect_success 'branch -D can delete badly named ref' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch -D broken...ref && git branch >output 2>error && ! grep -e "broken\.\.\.ref" error && @@ -90,7 +91,7 @@ test_expect_success 'branch -D cannot delete absolute path' ' ' test_expect_success 'git branch cannot create a badly named ref' ' - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && test_must_fail git branch broken...ref && git branch >output 2>error && ! grep -e "broken\.\.\.ref" error && @@ -98,7 +99,7 @@ test_expect_success 'git branch cannot create a badly named ref' ' ' test_expect_success 'branch -m cannot rename to a bad ref name' ' - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && test_might_fail git branch -D goodref && git branch goodref && test_must_fail git branch -m goodref broken...ref && @@ -109,8 +110,9 @@ test_expect_success 'branch -m cannot rename to a bad ref name' ' ' test_expect_failure 'branch -m can rename from a bad ref name' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch -m broken...ref renamed && test_cmp_rev main renamed && git branch >output 2>error && @@ -119,7 +121,7 @@ test_expect_failure 'branch -m can rename from a bad ref name' ' ' test_expect_success 'push cannot create a badly named ref' ' - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && test_must_fail git push "file://$(pwd)" HEAD:refs/heads/broken...ref && git branch >output 2>error && ! grep -e "broken\.\.\.ref" error && @@ -139,7 +141,7 @@ test_expect_failure 'push --mirror can delete badly named ref' ' cd dest && test_commit two && git checkout --detach && - cp .git/refs/heads/main .git/refs/heads/broken...ref + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION ) && git -C src push --mirror "file://$top/dest" && git -C dest branch >output 2>error && @@ -148,9 +150,9 @@ test_expect_failure 'push --mirror can delete badly named ref' ' ' test_expect_success 'rev-parse skips symref pointing to broken name' ' - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch shadow one && - cp .git/refs/heads/main .git/refs/heads/broken...ref && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && printf "ref: refs/heads/broken...ref\n" >.git/refs/tags/shadow && test_when_finished "rm -f .git/refs/tags/shadow" && git rev-parse --verify one >expect && @@ -160,8 +162,8 @@ test_expect_success 'rev-parse skips symref pointing to broken name' ' ' test_expect_success 'for-each-ref emits warnings for broken names' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && test_when_finished "rm -f .git/refs/heads/badname" && printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && @@ -176,8 +178,8 @@ test_expect_success 'for-each-ref emits warnings for broken names' ' ' test_expect_success 'update-ref -d can delete broken name' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git update-ref -d refs/heads/broken...ref >output 2>error && test_must_be_empty output && test_must_be_empty error && @@ -187,8 +189,8 @@ test_expect_success 'update-ref -d can delete broken name' ' ' test_expect_success 'branch -d can delete broken name' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch -d broken...ref >output 2>error && test_i18ngrep "Deleted branch broken...ref (was broken)" output && test_must_be_empty error && @@ -198,8 +200,9 @@ test_expect_success 'branch -d can delete broken name' ' ' test_expect_success 'update-ref --no-deref -d can delete symref to broken name' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && test_when_finished "rm -f .git/refs/heads/badname" && git update-ref --no-deref -d refs/heads/badname >output 2>error && @@ -209,8 +212,9 @@ test_expect_success 'update-ref --no-deref -d can delete symref to broken name' ' test_expect_success 'branch -d can delete symref to broken name' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && test_when_finished "rm -f .git/refs/heads/badname" && git branch -d badname >output 2>error && @@ -238,8 +242,9 @@ test_expect_success 'branch -d can delete dangling symref to broken name' ' ' test_expect_success 'update-ref -d can delete broken name through symref' ' - cp .git/refs/heads/main .git/refs/heads/broken...ref && - test_when_finished "rm -f .git/refs/heads/broken...ref" && + test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && + + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && test_when_finished "rm -f .git/refs/heads/badname" && git update-ref -d refs/heads/badname >output 2>error && From patchwork Thu Dec 2 18:40:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653251 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 9E603C433F5 for ; Thu, 2 Dec 2021 18:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376673AbhLBSnl (ORCPT ); Thu, 2 Dec 2021 13:43:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376629AbhLBSnf (ORCPT ); Thu, 2 Dec 2021 13:43:35 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B6FBC061758 for ; Thu, 2 Dec 2021 10:40:11 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so3072578wme.0 for ; Thu, 02 Dec 2021 10:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2TVRLSi+w77MBadJmLiDcs0AzkIYMxQckPgbd9BIQWs=; b=ebYRAAjDlTzziEyu3iigmBijg/4CApFZxOPbPupTbZOmD6Gc1pleTaAa/aDLGiI7Ox 9ShTlNo2iSfGqaWQnsRHwyJESozkLIMCI0El/6KorubTKAyZJxtnd6lwDDuBYBxADy+S fJjEv3gyttY9kunClqLqCioise+piLdCspcFTMFNdTfghMR2/br1j85zffEm9MovzqW1 +PntyzY2JX3v+mm2bg6dN/OUBZrKgjHgqJoOXlpBUrXnXQqdcdpGpzz/tCOxNkH1IdAJ WMwd9jSSWhtfyAhsUWR0++9Rbus0wsQ/ZAhSgyzfev4YYqPSdihYZfP8V1PgJ1VmYf6m dBnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2TVRLSi+w77MBadJmLiDcs0AzkIYMxQckPgbd9BIQWs=; b=EXw7Q0Yv7czDTMWUMZF7JxRNBKB329sYSE4ce50yd2Z+03hkxyJ292WwsNuhsOLC7R aIok/7WVJd2Lq+h0Nnw7+0Hg0Ko8vbJgphafKtok5vOk0sxVuq3RetWhpvoaKsD2Tsgt HqEFNPNDKBNmcnmDoZ9a+8zYlhu8g95MvI60GDg4CSeLmORlkEyM5IgCHudOMNmMHLnx HOjMfaZwJh2mxtHn/Fw9+1nrKVutHYFponFM86RyOUDHUOMjgoGXmWGN9kU6c816eK0k S13mKr0ghUbon6DmpYRNBqco/SCa2GJRT3nnhXsE09rSA2FaqSRxlejBCx+X1IEENmWW HLhA== X-Gm-Message-State: AOAM530wrCLqs5vOjsGsZ7YbFjhJ2dB0R5oOJs1u/ZiY4p/7Wn0KnDTb nt8iDSQeCQ9gzMlu8yvc11ihGUFXbAA= X-Google-Smtp-Source: ABdhPJw29G85pzsIq4VA2l6yYABj4V9SYwaPrZBHIA4VUlb9SHBEjvZTKYgJhBCDHeGpiqn77HG64w== X-Received: by 2002:a05:600c:354b:: with SMTP id i11mr8484231wmq.61.1638470409638; Thu, 02 Dec 2021 10:40:09 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b13sm543887wrh.32.2021.12.02.10.40.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:09 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 02 Dec 2021 18:40:01 +0000 Subject: [PATCH v3 7/8] t1430: remove refs using test-tool Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- t/t1430-bad-ref-name.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh index 326e5bd5e80..84e912777c5 100755 --- a/t/t1430-bad-ref-name.sh +++ b/t/t1430-bad-ref-name.sh @@ -154,7 +154,7 @@ test_expect_success 'rev-parse skips symref pointing to broken name' ' git branch shadow one && test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && printf "ref: refs/heads/broken...ref\n" >.git/refs/tags/shadow && - test_when_finished "rm -f .git/refs/tags/shadow" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/tags/shadow" && git rev-parse --verify one >expect && git rev-parse --verify shadow >actual 2>err && test_cmp expect actual && @@ -165,9 +165,9 @@ test_expect_success 'for-each-ref emits warnings for broken names' ' test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && - test_when_finished "rm -f .git/refs/heads/broken...symref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git for-each-ref >output 2>error && ! grep -e "broken\.\.\.ref" output && ! grep -e "badname" output && @@ -204,7 +204,7 @@ test_expect_success 'update-ref --no-deref -d can delete symref to broken name' test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref --no-deref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/badname && test_must_be_empty output && @@ -216,7 +216,7 @@ test_expect_success 'branch -d can delete symref to broken name' ' test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git branch -d badname >output 2>error && test_path_is_missing .git/refs/heads/badname && test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output && @@ -225,7 +225,7 @@ test_expect_success 'branch -d can delete symref to broken name' ' test_expect_success 'update-ref --no-deref -d can delete dangling symref to broken name' ' printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref --no-deref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/badname && test_must_be_empty output && @@ -234,7 +234,7 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref to brok test_expect_success 'branch -d can delete dangling symref to broken name' ' printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git branch -d badname >output 2>error && test_path_is_missing .git/refs/heads/badname && test_i18ngrep "Deleted branch badname (was refs/heads/broken\.\.\.ref)" output && @@ -246,7 +246,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' ' test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && - test_when_finished "rm -f .git/refs/heads/badname" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/broken...ref && test_must_be_empty output && @@ -255,7 +255,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' ' test_expect_success 'update-ref --no-deref -d can delete symref with broken name' ' printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && - test_when_finished "rm -f .git/refs/heads/broken...symref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && test_path_is_missing .git/refs/heads/broken...symref && test_must_be_empty output && @@ -264,7 +264,7 @@ test_expect_success 'update-ref --no-deref -d can delete symref with broken name test_expect_success 'branch -d can delete symref with broken name' ' printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && - test_when_finished "rm -f .git/refs/heads/broken...symref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git branch -d broken...symref >output 2>error && test_path_is_missing .git/refs/heads/broken...symref && test_i18ngrep "Deleted branch broken...symref (was refs/heads/main)" output && @@ -273,7 +273,7 @@ test_expect_success 'branch -d can delete symref with broken name' ' test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' ' printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref && - test_when_finished "rm -f .git/refs/heads/broken...symref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && test_path_is_missing .git/refs/heads/broken...symref && test_must_be_empty output && @@ -282,7 +282,7 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref with br test_expect_success 'branch -d can delete dangling symref with broken name' ' printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref && - test_when_finished "rm -f .git/refs/heads/broken...symref" && + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git branch -d broken...symref >output 2>error && test_path_is_missing .git/refs/heads/broken...symref && test_i18ngrep "Deleted branch broken...symref (was refs/heads/idonotexist)" output && From patchwork Thu Dec 2 18:40:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12653253 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 E699EC433EF for ; Thu, 2 Dec 2021 18:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376647AbhLBSnt (ORCPT ); Thu, 2 Dec 2021 13:43:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376635AbhLBSng (ORCPT ); Thu, 2 Dec 2021 13:43:36 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED41EC061759 for ; Thu, 2 Dec 2021 10:40:11 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id o29so515224wms.2 for ; Thu, 02 Dec 2021 10:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=f9F7TJyomLrMSKcIkZcwHRa0eTQ9RZcolol+/4rLphg=; b=eL1/3Wh5C0XcyhraE7LvRwSywnoOO8huF/yjQAA+FvzGGb4VAR0j2iP6xcKQx2BAQt H9j9uqrw1E/kW5GmwTUCNFV8i5hTa0iJ7S2Jr3P4LtFBPzhAkt7GGjaaeqmPAQ/uxvXN IGWHatELgF9dKH1fbg5PgBuQhNhuaJjj9kg3KOl1oFV3xZwm9JNgM264FtS04UztE1Rb CayhPKZCs9KJtrpLJ8UtdfbfoR0uy0FKCpQJAdOlNuzrfzS31EHtHZICglegZX4RM3vq 35O8Zp5KsgIoLf5CI7xnl4xfV91g238i/QvINXiqQFy3TzfN81our0itJIX8DX5LsUZy cTMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=f9F7TJyomLrMSKcIkZcwHRa0eTQ9RZcolol+/4rLphg=; b=BZFvBUb7Z0+IkhzGQiSxPKXG/Ix8SVzDUvkaAqtRf5Z1axLA1NvzAnNUgHZQ7rdYq8 uiydtXzSzHkhZkYcbUuWZWDZf5fpfgK6ZIZN4tVz0EozeYhzq5fwBdRoFOhbW92ChCu5 jlxB60xBAVC4wErAf5apHOUkMKQo5qOzD8JWZAgzwqklx2FW/Sr5XrHmPLFIX7zi43Co CVR43Vd0zjK3X3Vo0WVCpSOd7nvSo4vuzmPu4r3wIxbWoClCYymgnJVDV8KWGiS6c8j8 4FK3FgfP3twBxE2lq2INxZtCLHg/by0jzquTjTbA4FUUw/lKSVwdmi/4hD97PrNip3iO R+Mg== X-Gm-Message-State: AOAM531zgUMXmoflgU6Qy3VseU0ONUD01qhSxaTd1BBuWqJTMhQ5OTcw DHkep6y0/VxxhcB/PqacwH90vf9yTdE= X-Google-Smtp-Source: ABdhPJzPxtYwjGZm2o9TimrOcNOLnCpVCIjZCJgBC93Y8icS8VcHNoN6Ika8gMraGHNu6MDnBm/Bvw== X-Received: by 2002:a1c:ed0a:: with SMTP id l10mr8459874wmh.140.1638470410413; Thu, 02 Dec 2021 10:40:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm518037wmq.46.2021.12.02.10.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Dec 2021 10:40:10 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 02 Dec 2021 18:40:02 +0000 Subject: [PATCH v3 8/8] t1430: create valid symrefs using test-helper Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jeff King , Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys This still leaves some other direct filesystem access. Currently, the files backend does not allow invalidly named symrefs. Fixes for this are currently in the 'seen' branch Signed-off-by: Han-Wen Nienhuys --- t/t1430-bad-ref-name.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh index 84e912777c5..ff1c967d550 100755 --- a/t/t1430-bad-ref-name.sh +++ b/t/t1430-bad-ref-name.sh @@ -153,7 +153,7 @@ test_expect_success 'rev-parse skips symref pointing to broken name' ' test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && git branch shadow one && test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && - printf "ref: refs/heads/broken...ref\n" >.git/refs/tags/shadow && + test-tool ref-store main create-symref refs/tags/shadow refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/tags/shadow" && git rev-parse --verify one >expect && git rev-parse --verify shadow >actual 2>err && @@ -203,7 +203,7 @@ test_expect_success 'update-ref --no-deref -d can delete symref to broken name' test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref --no-deref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/badname && @@ -213,9 +213,8 @@ test_expect_success 'update-ref --no-deref -d can delete symref to broken name' test_expect_success 'branch -d can delete symref to broken name' ' test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && - test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git branch -d badname >output 2>error && test_path_is_missing .git/refs/heads/badname && @@ -224,7 +223,7 @@ test_expect_success 'branch -d can delete symref to broken name' ' ' test_expect_success 'update-ref --no-deref -d can delete dangling symref to broken name' ' - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref --no-deref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/badname && @@ -233,7 +232,7 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref to brok ' test_expect_success 'branch -d can delete dangling symref to broken name' ' - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git branch -d badname >output 2>error && test_path_is_missing .git/refs/heads/badname && @@ -243,9 +242,8 @@ test_expect_success 'branch -d can delete dangling symref to broken name' ' test_expect_success 'update-ref -d can delete broken name through symref' ' test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && - test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref msg && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && git update-ref -d refs/heads/badname >output 2>error && test_path_is_missing .git/refs/heads/broken...ref &&