From patchwork Tue Dec 7 13:38:13 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: 12661879 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 5591BC433F5 for ; Tue, 7 Dec 2021 13:38:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbhLGNl4 (ORCPT ); Tue, 7 Dec 2021 08:41:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237267AbhLGNlz (ORCPT ); Tue, 7 Dec 2021 08:41:55 -0500 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 5FFBBC061574 for ; Tue, 7 Dec 2021 05:38:24 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id m25-20020a7bcb99000000b0033aa12cdd33so1629030wmi.1 for ; Tue, 07 Dec 2021 05:38:24 -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=VlpvmapMRSl0u1iQ9mDvRBQLXx/vWa0qtuNFDYJO6Rlv1NUdrwnFhH4RmnINoYHm7E SvNUFKk3wcBQ3raoJ1Rhq3yvVG/af4mNChYkv4Ky2iZCU0m6Xm79UCKobVvDnqIrV84Z Gkc5HBfNKW5mRHJKZjCIq77iB9HzVRixI8y0NCOzba+4zY1JRnlznXXjCXW2P7abyUN0 pChr+jc5NtWYCRQCZGpVVTfFySfB1kTzHEzOdmkHlcHt1JL+ijJUoycc7xd5Dv9xG63J +SJu54l7mKOY2OOb28b1wZMHAVuV7hb38jiYkxcDWDp6SZRpObzrMXmJ/U5kpvXxksRY vigg== 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=04ImnPfyfilrlFNXFrk6cZ9BOxMZzZdRgvCvpRqmp5t0QCWDg5MT50LgfxfIS+0Iz4 JBXtvPA3+NpQtG4hXm9SGOLl2O6nCzWPlYfxzQYCbIYgR6ffEILD/1Sq0RVtnluSLrEY t+jOCP1h9gHkUMjWJc+0pEUMHFJ4LhUZLdvBf0skhspZNVOIpxVXQv8fOriOBt/pwF2I iJd6QZ57jRBsJ2TCEBpKMRKsHk11h8D3Z7oGE2MC1uS2aqK4yXEk9UK1xG5hkgrU0tRz ZVcdGFatZwjW+beERsMVYUxROxiUdf1OrnopE9ldTKTm7/i9r2/x8zLmIX6BKdD7YCpu z6Jg== X-Gm-Message-State: AOAM5312vyXDx6fiLmYe/nOvtkTUKOW9PgckFGy0SPNlZxfPiznEUUHW fVFBem5tLPkcGoG2v0BET0fQ2ZxQ7d0= X-Google-Smtp-Source: ABdhPJw6lcT7J5nm8vLKTK1Suk5BxAlEBhzrsCHtVKEso0J7ES2reyRzKYEJvFRArjcrLXZ3YQGQhg== X-Received: by 2002:a1c:4303:: with SMTP id q3mr7038510wma.78.1638884302842; Tue, 07 Dec 2021 05:38:22 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u13sm3012359wmq.14.2021.12.07.05.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:22 -0800 (PST) Message-Id: <3649ef6d0fa14ea1796264188466cdfc42d6d9e1.1638884300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:13 +0000 Subject: [PATCH v4 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 Tue Dec 7 13:38:14 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: 12661881 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 7F64AC433EF for ; Tue, 7 Dec 2021 13:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237222AbhLGNl5 (ORCPT ); Tue, 7 Dec 2021 08:41:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237269AbhLGNlz (ORCPT ); Tue, 7 Dec 2021 08:41:55 -0500 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 0C062C061746 for ; Tue, 7 Dec 2021 05:38:25 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id 77-20020a1c0450000000b0033123de3425so1799330wme.0 for ; Tue, 07 Dec 2021 05:38:24 -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=dtxgHuiXmVxNjjRkzOGJL0LrW2h0Q9w7V1oY0yFki+Y=; b=DG34I05LSs58SmbR/WE4ZjM1cEAyZCVq4Qbm3ewrExdxq4BoGUqeWdjz40gRlCiaZ4 Brv5wtxWbOgHwRuRqEdIjpqzyi95AlgoJf5Ro5+WGkkGmGjlTdrRPn/F+3S7pVPZj1Ey Lk+fSZXB0apH23kxlOQGPYpvR09LfW+rLO0nw+DOP7MZXOSWL+mUnyoKSCNJBFfnTZZH XsglpBFJrjsNngQmmlMR60Wa9jwG6XSDRVLDnZhtdKy/+RNOLGt0HwpXNKmBFJIniCjT XbnhIs3bYJqzASUpMbvMWCRS5KP6NiqUEM+VsJpsiimjSg2L2AYhpb5sE/UuEHIJXZif Q0xw== 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=dtxgHuiXmVxNjjRkzOGJL0LrW2h0Q9w7V1oY0yFki+Y=; b=1zdKVTHlR7IQXi+m0wb6hbzPNOgHGvW/KM90rXJZNaLdTFduVtyGNE3cYy3oFD5/PC ir4uABe619P0wqSRnuqdCPP9pZbPwZQsMh+RT9D5CY1OHecNHHpXb2j5wBIIGDtSwS1v 068OME9Q6FWNj0FNNkF+Mtp2bw1oZSW2YlbTht9ei48RfrNDb8Adb7NwDQRjZN5q2Btm L870RGXwk3ZkSykx+aWkgjW9jkINlY4CvI4OwT9wTj5i9nsrNcpfdQBPGMJ3iGMoU8yd /kT1qNVOZtiirfO7JYVYO9jGUnvHjomC1XXhnh51DtEeFzSdloht7GhoM59wfyBT1uNt 2EDA== X-Gm-Message-State: AOAM533/pFpSBLcJ30vplaIQH8fGogg31Vd3b1275TO86WN4xAF5iou0 sRT6M2KqEac1neS5r829w5Dr3iHg9To= X-Google-Smtp-Source: ABdhPJxZ89KJRlFhVoMFwTVy+Y+pJpiKUmbVPFecMDVVENtY/OXbNUJ6Sr2AyjUwwEs22jP9/Jo3sg== X-Received: by 2002:a05:600c:3553:: with SMTP id i19mr6987762wmq.97.1638884303451; Tue, 07 Dec 2021 05:38:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o4sm3157444wmq.31.2021.12.07.05.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:23 -0800 (PST) Message-Id: <865458bc0cb1c2abbc4c378f9e4e4317a05fa0b9.1638884300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:14 +0000 Subject: [PATCH v4 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 | 66 ++++++++++++++++++++++++++++++++++----- t/t1405-main-ref-store.sh | 3 +- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index b795a56eedf..abb0ba101ae 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -5,6 +5,48 @@ #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 +54,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 +107,13 @@ 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), + { NULL, 0 } }; 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 +127,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 +172,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 +261,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 +276,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 Tue Dec 7 13:38:15 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: 12661883 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 AC797C433F5 for ; Tue, 7 Dec 2021 13:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237224AbhLGNl6 (ORCPT ); Tue, 7 Dec 2021 08:41:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237274AbhLGNl4 (ORCPT ); Tue, 7 Dec 2021 08:41:56 -0500 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 AAAEFC061574 for ; Tue, 7 Dec 2021 05:38:25 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id a18so29584486wrn.6 for ; Tue, 07 Dec 2021 05:38:25 -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=AX7AELtrhtiyAKC6KZCsWLD4t7wORrZE9iy7m31WOdQ=; b=lPhUSxhxwC4vs6bNXgGREnmdh54IijWfFxG9BzzsmUSLPIfKVT564IVbTotAZOPpxB N+i+p+S0jRORPgDM+1DFvSLvpb74ZNlgBPSjUmEBCKlTpoTAXlSBKyJwhcEe9UnQ/3P2 NOvIj/3oT2eV8yQOE+EKsqKY19bu4RDhqU2z3m3xhnHgemrJeyGboMf5Ck3H0ipq3Wme edOEAQ70vRbVROXKA2Ya622aXgJ9rB1cJzEjsZERt1TAz7JdbCMpCRfpMlaxXg86Gn1p eVXPkfO0ilFY0Tu8q7C2N0ScD0muXg/v4QtIpAqyLgjP6mPE0Ye5NKxZjI0b+O1Zc1D5 H5qw== 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=AX7AELtrhtiyAKC6KZCsWLD4t7wORrZE9iy7m31WOdQ=; b=iAwIiiUnt5Kul/rkxqa7jumSWYhAMMdkyRDPh40dsTyWNhLqsvGPK/VGPY+Gr9G/mY op7d8CdNug6xDSoBgWmNXd2skXHCj7FuX7S+F/ASaXYl2MIOCN1/Qcz7UBML/WTFbLIG tnG3C0FpaCHahsmXfpczbfybsjwNs/qyuqjeFsOVJ82GYloZi6UY+HkWod9ArjWvZlN+ HCPh18ttCZHQ7ivFgbKisxcFEpNCWpcBhNIT8vcYV3UArOYsDYi3BxT2HOTNfSPtZlW5 yiPjuQeegRjugK+MBusfq0EdAkBttKS2PzlupIITlezDgd0vvgQ3Afp6ue3IrjZI1jR6 BvNw== X-Gm-Message-State: AOAM533tcYcG+W8x+hepXrjScwNAlHUWm/+FITKbMUVAkPyhPTvN7Uxr u5o+vGyf7vH+3ASsbmhjY6P29O7PhqU= X-Google-Smtp-Source: ABdhPJyfu5kTtTG+0weoD4xeZc4glGDpEWy5QCb0i/1DwND1/eABjS4Mho46Kvu2b5bK1lNFVDSjiA== X-Received: by 2002:a05:6000:2a3:: with SMTP id l3mr50609083wry.415.1638884304194; Tue, 07 Dec 2021 05:38:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 10sm18265506wrb.75.2021.12.07.05.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:23 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:15 +0000 Subject: [PATCH v4 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 abb0ba101ae..8fee3cfce1a 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -138,11 +138,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 Tue Dec 7 13:38:16 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: 12661885 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 ED867C433FE for ; Tue, 7 Dec 2021 13:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237230AbhLGNmA (ORCPT ); Tue, 7 Dec 2021 08:42:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237212AbhLGNl4 (ORCPT ); Tue, 7 Dec 2021 08:41:56 -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 56C01C061574 for ; Tue, 7 Dec 2021 05:38:26 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so2263568wme.4 for ; Tue, 07 Dec 2021 05:38:26 -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=LqGJ71XqTo02c0bqVf8zoPPT3ndo8ckFPpk8FEScPm+k9Il/gYq0h35VX+PYbmhgxH /LdrV9RBRnWnd+RMi25xqGaj+5uXsKILKOKyXqKhUFQjOIaUhhJfzHzFRp/Z0Du0Tzo3 4V1D+QTJnlYOIyM4Cag4wspDFPOYlikhvq89AXOyuU8IEfCbL3v73/TRMML5s34J4JAF hE94A7SfAnXg1scJUsGNAHKjA/SIHNq9w9+8vree65Ohv2YEtZY3NoduSxtvixiUyvm4 f28odKB1vRVQJTyDXvnE11VJWWD0BVL0GpGyEYdACx4nBtGYwx6ruF0aYM1DB/PmfExk +fnA== 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=rS/vnHe68SA7C2B+vu8xXcMsNt1qtLuyJh+qBr4JEY+4cXeJ6m7bsVYHjU+gJyEYpD Xu/0zy0xsYUs97Exa6X5sDt6PG/VjvmZ0kTBFJ/LgWRLZeDcKdrvdbc3o9ZLvVQdr5d5 xf1ffxBba6RKOKUQl8DYGW43LUfoU8oZNeqS3BU3KAw5ydSjGR1JBju86skWBANSTEPU 1U1cqd19L/n1aE7JbBRHQ16YhrU+v2vrpaq/nlsKVvWnHZ6hfRwJWF/HmE0qOLaJu0LZ t92vxvtZflNCDK2pshrxRd2vmtC+YwPFApHBRvauUpNzSbU0f5N86cjorCmp3XA3bwAO fdvA== X-Gm-Message-State: AOAM532XiJJiiiNfSWfCWPInvVH40JaorSnq4XlE3cis6Gtb+n5t1VSE UQXwBEFbKp1XI81NtBCMx9s8dS+003E= X-Google-Smtp-Source: ABdhPJxBrzc6R2aDKgkZmOArckeKJRbR4wVYjBg1AFINlx607VPqZkeXpIfOLfwlOm9C/urQiWZS2Q== X-Received: by 2002:a1c:9d03:: with SMTP id g3mr6875670wme.143.1638884304841; Tue, 07 Dec 2021 05:38:24 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r17sm3144554wmq.11.2021.12.07.05.38.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:24 -0800 (PST) Message-Id: <67d22211ac4b1b62b2c3f76893765255a59ade8a.1638884300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:16 +0000 Subject: [PATCH v4 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 Tue Dec 7 13:38:17 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: 12661887 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 5854FC433EF for ; Tue, 7 Dec 2021 13:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237235AbhLGNmB (ORCPT ); Tue, 7 Dec 2021 08:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233053AbhLGNl5 (ORCPT ); Tue, 7 Dec 2021 08:41:57 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18292C061574 for ; Tue, 7 Dec 2021 05:38:27 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id o13so29470538wrs.12 for ; Tue, 07 Dec 2021 05:38:27 -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=gEp4bKfQL+NnYSScrqq4hmnwCYjF/KAyBwcYmIy9Rs0=; b=Bsj1BfHaoELvbh7ArPHIpBkrC1oUNN9rM23/5T2tPo0kOCwgs8XLQF/PNrObT7KhlU E/jGNiV5933bCnzEPHRzEkfPEwPNUeymBjbTOi0XSgJlllTCkZ9tOByF4dtSX7rAipkl OlGjtQ5la8x0Pix4CeznSGGIV2FDR0YjeOZe++4iL8kZVDIzvb9lDT7rwSNtCCmBB+C5 0OVsmboAwi31fNQdr8fI6oOcxeZkYSSrJk7rJ6B4RW8Xtdnu2ehu2D+m+2F/SuCExNEV rMh3joOUk11NjSdzBtzCFgc+A9ipcykbN2+/JWPsjrr8fOG+9KF12OZk4gL5yOdCIPpT FTYQ== 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=gEp4bKfQL+NnYSScrqq4hmnwCYjF/KAyBwcYmIy9Rs0=; b=FUkSti9WFvGL41UbnIQVwi4FF6PqT7iCqeD3KtBt0InYsfI6LuXrRZZPQPtxo0ok9e Fx+w7jyCDvwR/xHwLt6ApmzNK+HW2SOLlguu/K2HUKW8GAX6d9z6zqzIIYRwBhU7w9BB gHNLnOeZbSsIQtFEea1OttgGY3bzG61XMJNq8bEgWK+HITV8D269tR6n9TSXegqz5xz6 pDRy7OLTD/U4gBJQIzOmRmI8ThYC5OAyZwSmsxGp3h3NpLuLDGjUxNhML1NpZW+snnRV Wut6KEy7svwqW0aZ0DQuMI11S8e2PK2vyN1dNmopkXaep+QyToN2Ne3jB4gj3ewDJfj0 StCw== X-Gm-Message-State: AOAM532sEwSXycF+lDPXK4V7v4jX1bwB9sEjN8tqErRDQJ0CTb0eXFYQ k6VdNO+6SZIvaSexZVHxjN8cMiSaGhE= X-Google-Smtp-Source: ABdhPJz/MQE6DEXxHychRk+WhqgqXSKe6g0s2CqXPocI3X/SXPJ342vtcsEo/G8F6PHvmH4gSs1hOQ== X-Received: by 2002:adf:e7c2:: with SMTP id e2mr49047677wrn.349.1638884305474; Tue, 07 Dec 2021 05:38:25 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d2sm2823480wmb.24.2021.12.07.05.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:25 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:17 +0000 Subject: [PATCH v4 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 8fee3cfce1a..0f3aa84c9f0 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -130,6 +130,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 Tue Dec 7 13:38:18 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: 12661889 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 5572FC433FE for ; Tue, 7 Dec 2021 13:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237243AbhLGNmC (ORCPT ); Tue, 7 Dec 2021 08:42:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237218AbhLGNl6 (ORCPT ); Tue, 7 Dec 2021 08:41:58 -0500 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 0D5A6C061574 for ; Tue, 7 Dec 2021 05:38:28 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id j3so29610369wrp.1 for ; Tue, 07 Dec 2021 05:38:27 -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=sFhcJPD/UXyuC6RDfKOl0yb3a7+qO5odJVmbBbbbDBA=; b=ZOzqS/cjfx+LrClWVei8meSWshrst5hXrBs5SMH0FxYcVzOQ2i8lS5R17IdVHrVYhl 6sz/uPYiZ6swiWGfhx7u1PvcS9B5fg1Q0KT/+jWoq1EuR8+CZ+5XcQMUvGv8nquvEKIu lAp9JipGCiscYNYIlyx4hS+AO6CrzafPOlAxO6/+SwkGeFRo++9WUtH3VxL93Wn8/uct SZpzl2XPitfCwamiz2WCb6PNXGMtn4ODcqwU2OzCIOVjlpHylmd6FtwAqCk4Dto6ehI0 6FE7U9SzZf3MQYtBAEzcc71ywIHw1tbn8imCT6hJD9skGfALTu4foJZ/+YqgxjWt1F7f 19PA== 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=sFhcJPD/UXyuC6RDfKOl0yb3a7+qO5odJVmbBbbbDBA=; b=y+1fshhe1DEZ/Wz3++tf9Zt75ckBYf3G9XHTBErfFPxQzJSTmJdAzLGAfNj1zrnmxY ENHYCw3WEu+BSzAQuwolZKpBflYqEMZOKMaxai84KyvCARgm7TyRD9uF98v4JleCyp6A tRx7xD9Ua18eWKwQGal4dcsglMlrQ5gWoaf2E1BHhU/yJyRzP3mnkRIY3HmVFCWURoht pdAeFlx2UBT0ey+q3kBsCv8GluTPMCW7YhJHSixkSpQcfnXY0CLBRgFDmD9yvSPPpX3G 0QF10JOtUcdCRLSsFwOuvIicn7ziqPxmXj6lSqygW4EYF/HbSJM/1N+pl+L7qp4Vp48g OUxw== X-Gm-Message-State: AOAM533jDgPYIQdH32WTHtqgHCyCT/Zl8GtbU5F1bC7QuifTYtg+kY2J w7c9QXVnh1N1pEoVjsZyVgXSa9V0InU= X-Google-Smtp-Source: ABdhPJzVWl9Ic+4voO6VCaMg7VV9Ok5ZU5xGqv81/t7+e+0/3pGtUmRboPFAlnnZlqtQUeDywIFqEg== X-Received: by 2002:adf:d1cb:: with SMTP id b11mr51242857wrd.33.1638884306288; Tue, 07 Dec 2021 05:38:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k27sm2882602wms.41.2021.12.07.05.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:25 -0800 (PST) Message-Id: <577726dc9dffb14558cfe5d3183c6b96c149b3fb.1638884300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:18 +0000 Subject: [PATCH v4 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 0f3aa84c9f0..8bca4f2af1b 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -131,6 +131,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 Tue Dec 7 13:38:19 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: 12661891 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 EF04DC433EF for ; Tue, 7 Dec 2021 13:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237250AbhLGNmE (ORCPT ); Tue, 7 Dec 2021 08:42:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237225AbhLGNl7 (ORCPT ); Tue, 7 Dec 2021 08:41:59 -0500 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 93749C061746 for ; Tue, 7 Dec 2021 05:38:28 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id q3so29522749wru.5 for ; Tue, 07 Dec 2021 05:38:28 -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=QqxswQu75HubnbcXF/bUQAgJgU5SbgOQgeqIqZ6HLu93RP66Ec+2zsJrEspF7KJ7lc etphHtDG9ftYnld06wUEmP5PbjxYLn0Td/LFJKhauUlAIARg86lf7q1JT6AhiwJu631h AU/+KueUXozRlJPBazVL84cpWYGU2CosF5fytYhJV1lMXxG+24A6mlVAt7vY+Rh1vu+W FZJMHS3ZcaEMM+IFMFvfCDNUSXlCd/i32ROIvSBz9Rldz2nwKoVY5NfMPZ9ZNV5qalbb 4Kg1ITpZkUgT0aXvBstMkl4zJKsCjfW3NBTgxYzRribDb2wojyBlFzGxOqwxKWOlF9ZY nUXA== 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=RbxjoNifW0VZxACY2BvwDOL/7DQzaQUQmjPZSPrIg5emi6/+DmsLh34jqcn2+Jjh6C DUO92+gN4rfTOkXz3KI6C86pgFf9GwomjbKevXhwNsBrxYwNZaLe19NFO8cEz0VuyX5P uDArlKqDSoO1xeu4F4329reh8qi4T8LV/Yxwrz4FcAFSVd1DazNyvbon2EkaOuIbH9mM KG9wXYCIvOtnvzJdxJtDdgkDckDyAadmsflTqwXI4wMt1g7RGMdR6PUoYLueBFWeM2nV mXo6tx0LyvClByX5zCHU3FwrYzbA98smE7R487UI0gGbn7GtOq6/n1HKd8wDdmAKcH5J GwXg== X-Gm-Message-State: AOAM531h4l0XHVE8KIuo10sVmgtqEoMDdfG2IcmH6fgYW4EKlOLudUVu DL74fiZ6aQ9lnqrkUQu/kgKoiA5jcdA= X-Google-Smtp-Source: ABdhPJyB9cfFfAjs49aSQej8TWWa77ER/EX+M1PAhtI7GXOdSQMV+rcu6Xo0TFPHf5jm4z3cmojMWA== X-Received: by 2002:adf:e484:: with SMTP id i4mr52785151wrm.49.1638884307077; Tue, 07 Dec 2021 05:38:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y12sm14444197wrn.73.2021.12.07.05.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:26 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:19 +0000 Subject: [PATCH v4 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 Tue Dec 7 13:38:20 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: 12661893 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 0D474C433FE for ; Tue, 7 Dec 2021 13:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237267AbhLGNmG (ORCPT ); Tue, 7 Dec 2021 08:42:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237229AbhLGNl7 (ORCPT ); Tue, 7 Dec 2021 08:41:59 -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 3CC22C061748 for ; Tue, 7 Dec 2021 05:38:29 -0800 (PST) Received: by mail-wm1-x32a.google.com with SMTP id i8-20020a7bc948000000b0030db7b70b6bso1775518wml.1 for ; Tue, 07 Dec 2021 05:38:29 -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=fCUqWXoj4XeF5B6yrIZxZa41XFKzQIfK1kg9FXjFOsn+lbkti4ciKxL0WkWg9ojdFs qw+aaq3lhh6qUc8tyA1Rx5FJvBGPzwESdWtJ7b5b8fgBqSFeYLR+fp6dpklwFKFlCXBW Zp3IBCbz8knadm4xx4FEEF77ZcsNQ1rI63u/VMf+SmWnKOIPjZCm2jzfdvT2WQkpGEhn r9VFKhlA/CM3v1DygvDTBtL/O4Sce0phWiH8mvK4svUKptXVhCM4YSVcHghkB51qq3x3 /M8fGHV0tG0sgb/ilDx45NteoeL7gEHyLsCkLMWcg7zcGfBGIr8OmJUp7SXVBeMHTuus DsvQ== 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=NWmZOtk2SpWnmuY1IHvJnY6vqSd7RZ9H+xla0lZe/Cxnv4PEj5oke9GuWfdkrntT+r FHheMljcerH8QhhY2GufDMMBnXOIPh4FglS0Nadg5QO6znWUlRPPigMFrtpjWrLmCvaO qfJF5SKGgWE7KNKJUQiPFT9tgtTqoyp75SzxJtAaQcTI2mDEvwFTbMrCTTd2bVwEgkdv BNsbYk9oDRARoSkLkl/8ofKYLdWvQxyRS0ub7Br8gts0AZ9m+3Gv4vTOAw5mORNVIsYd TdLagQrRVd3sJOV0xJeH2xobCIK0VjgM9kBLBEACgNyTSFEqR3OYhxN4oXVt+ueA02cQ Z8zQ== X-Gm-Message-State: AOAM5300cBY02hYv9ZAtcKCEPgcQotrPFzOxQtQzS6vR8ssplnZXAUun dMgj/JJg8F9L3mNtLB2GjGI0AYW5uOA= X-Google-Smtp-Source: ABdhPJwoXaFJnbxopEHzTqptPOh11WMhZ8KGsws0QDL0jDm/LsaIaSkQ3Jnawt55YkZ3leVXM5auag== X-Received: by 2002:a1c:f414:: with SMTP id z20mr7216471wma.17.1638884307744; Tue, 07 Dec 2021 05:38:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f8sm3243996wmf.2.2021.12.07.05.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 05:38:27 -0800 (PST) Message-Id: <7597620ec83a2e956316d27835db423372d618a8.1638884300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 07 Dec 2021 13:38:20 +0000 Subject: [PATCH v4 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 &&