From patchwork Tue Jul 20 10:24:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387987 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B776AC6377A for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AADAD610D2 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237821AbhGTJtt (ORCPT ); Tue, 20 Jul 2021 05:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237670AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAE16C0613B2 for ; Tue, 20 Jul 2021 03:24:24 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id o30-20020a05600c511eb029022e0571d1a0so1710135wms.5 for ; Tue, 20 Jul 2021 03:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FmQRw4ks+TUjlGp4POlzZ3ZiYws7aD0O20w2NCTieT8=; b=bTQsmtkGvhVdv7+MK3960zm1NuvrKjgpxgxlzr6z3pthg3MGERhX1WZCg6sUykHyUD 4gE7YxusJCKGHGMSLxRKgYlRBN3SH2RS7jNqE6Kx4aaVSf74y4bB1CJeylrsr5Y3bWt5 kBFmXv58pmJI3gEzNmXymjjuLv1DOyEJaF64zaSW+nM1aZnvJvhFxGd8HnBwxL9kB89U +hjzWaWaod2uLykCXh3aPcXZ4uYG6ZCVNoFSO7yqqSa2t5UnSmI68qk7KIA25pjhXXsY FhmXYXCtbeZGnXZN2zMQhr6KmQDW9W2LJyGG+gg2ul1BDF3qI/dUaV907I9TQquyEVgV ACxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FmQRw4ks+TUjlGp4POlzZ3ZiYws7aD0O20w2NCTieT8=; b=PE/F7eXhZo00PdiTM6CDi8x4INj2yk8XFm134+IOtlRiM2e2E2buxOE12upvMkOfew 8EGJD5izFWHdqMWER2IpyeLV8mquASZCSBSyVk2rqhUbwi5cU3Strn5HdF3QNigrJFn7 wvxyGJA1I01yp9OgwHaiBcK4f0R2nIm9EMwQtcJzG6SiNBYpI1BQrraG3o5J0+wF3yGO H9zDd/saWcwdO8Qb4rdlJhVo/P+51ef4jfnYTlXNM5zNT6fHytXh3SQ8ANXadKQTwjof eULCbZwa0MIQhgUWaLaUnWI39PEqeOTfPwyYf1piN9LSI0Vt91ez5dUXg8tw/xsgaVGK pJDg== X-Gm-Message-State: AOAM5324nBmpO4Wm1dKWDunCEDNXXGYnT7HeVmTCLBeaRnTqr1Dpl048 AB5pJcbVURpzN+/axa6kuRqWZJ5nPidr8A== X-Google-Smtp-Source: ABdhPJy+UG1doA93oZQhdQbxZMTL/JL+IpNToYvgwmIMDf8gyqUMmOKnY1YbdXrWn1sf+wIkblvOLw== X-Received: by 2002:a1c:9a12:: with SMTP id c18mr31895491wme.48.1626776663323; Tue, 20 Jul 2021 03:24:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 01/12] refs/packet: add missing BUG() invocations to reflog callbacks Date: Tue, 20 Jul 2021 12:24:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e0cc8ac8202 (packed_ref_store: make class into a subclass of `ref_store`, 2017-06-23) a die() was added to packed_create_reflog(), but not to any of the other reflog callbacks, let's do that. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/packed-backend.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/refs/packed-backend.c b/refs/packed-backend.c index f8aa97d7998..24a360b719f 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1600,6 +1600,7 @@ static int packed_for_each_reflog_ent(struct ref_store *ref_store, const char *refname, each_reflog_ent_fn fn, void *cb_data) { + BUG("packed reference store does not support reflogs"); return 0; } @@ -1608,12 +1609,14 @@ static int packed_for_each_reflog_ent_reverse(struct ref_store *ref_store, each_reflog_ent_fn fn, void *cb_data) { + BUG("packed reference store does not support reflogs"); return 0; } static int packed_reflog_exists(struct ref_store *ref_store, const char *refname) { + BUG("packed reference store does not support reflogs"); return 0; } @@ -1627,6 +1630,7 @@ static int packed_create_reflog(struct ref_store *ref_store, static int packed_delete_reflog(struct ref_store *ref_store, const char *refname) { + BUG("packed reference store does not support reflogs"); return 0; } @@ -1638,6 +1642,7 @@ static int packed_reflog_expire(struct ref_store *ref_store, reflog_expiry_cleanup_fn cleanup_fn, void *policy_cb_data) { + BUG("packed reference store does not support reflogs"); return 0; } From patchwork Tue Jul 20 10:24:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C901C636CE for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7723F61242 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237500AbhGTJtR (ORCPT ); Tue, 20 Jul 2021 05:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237674AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 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 EDD3DC0613B3 for ; Tue, 20 Jul 2021 03:24:25 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso1287541wmc.1 for ; Tue, 20 Jul 2021 03:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UAIwz2LkcNS7M0zdOjdG//UwSqGXWyC8Mh97oVNpkkY=; b=K/PmAAlz4tngDuqiQJqFi2pk0VrSSgr8/NJFg2St5AiU9XdKmQY03hQ7Q5IJZ+PGry Csz0iT1g5cr0glh1xfgXFs3CsNZpHvvW1UK4Vwx4dcrmfdjaViorpGUQLLztbFL0//74 5LQtFGA+Q2FW0RY00ar9hlTf9vz6SnRKl6E9uuGCZHUYLkHosGAKb+kxLxVeW/E2d68Q IOX1LCqsGl/spl7VQPtkB61mL0JFhI1ShnSHwvaGRHXJ50ai0F9MzkbJ6ExXYHS/1ZC2 RoA+8pspLQEKgXjmtlboDJc54F9+XEDbx5bEbfStXA5WeoWGbfZk+yVWdQoiQsi3X7YD 1URQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UAIwz2LkcNS7M0zdOjdG//UwSqGXWyC8Mh97oVNpkkY=; b=ZX6VdsHbbjdLWEPCDuOSRwhm0WlLkW7kjqANGB3spvFxUMlrpyYMNtMytrbK7SKJyn xuBtsD9vd+Vob3qKl8zN2FVnVyC/EhrvZjLOeGWs51UauOPl5u2pTw81K1t7Erx32rO6 FwMw5XmdK9ubsI1bTv1LKd3RSY3hYWndsfE+rKg0YEPxaxSXnlVlq9uRfgBfIrBR0V0f KquVn7zMvGeXMjgsDlO3evWrp6KsBdJnuvfRxzizUuO5FQsQFGt8m/bOpdk4sMf5EiHE 1ORQmYtqBRJXbeMxjEQtkpwTbt5j45XyX2NBONYEfnR15Czqia9ajjoz+nrCI3IUKiKM Zr4g== X-Gm-Message-State: AOAM532Mp7xsZTEkm13YzEhwIHFgX/NMBfBeVqPHW1+RaeT+7fp4LdhO 0K3lNulXFNOs+AccGTBDbdG8DtwPjwYSXA== X-Google-Smtp-Source: ABdhPJzWrddGlpgNaJ4SkQrf+bEMijxuhfIedF3DO6X8iouvAvO82eCRlQnH2bjpseCmjScguftc2g== X-Received: by 2002:a1c:4c15:: with SMTP id z21mr30971449wmf.114.1626776664334; Tue, 20 Jul 2021 03:24:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 02/12] refs/files: remove unused REF_DELETING in lock_ref_oid_basic() Date: Tue, 20 Jul 2021 12:24:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The lock_ref_oid_basic() function has gradually been by most callers no longer performing a low-level "acquire lock, update and release", and instead using the ref transaction API. So there are only 4 remaining callers of lock_ref_oid_basic(). None of those callers pass REF_DELETING anymore, the last caller went away in 92b1551b1d (refs: resolve symbolic refs first, 2016-04-25). Before that we'd refactored and moved this code in: - 8df4e511387 (struct ref_update: move "have_old" into "flags", 2015-02-17) - 7bd9bcf372d (refs: split filesystem-based refs code into a new file, 2015-11-09) - 165056b2fc (lock_ref_for_update(): new function, 2016-04-24) We then finally stopped using it in 92b1551b1d (noted above). So let's remove the handling of this parameter. By itself this change doesn't benefit us much, but it's the start of even more removal of unused code in and around this function in subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 677b7e4cdd2..326f0224218 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -934,8 +934,6 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, if (mustexist) resolve_flags |= RESOLVE_REF_READING; - if (flags & REF_DELETING) - resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME; files_ref_path(refs, &ref_file, refname); resolved = !!refs_resolve_ref_unsafe(&refs->base, From patchwork Tue Jul 20 10:24:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1261C6377C for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B563E61221 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237839AbhGTJuJ (ORCPT ); Tue, 20 Jul 2021 05:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237665AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C521FC0613B4 for ; Tue, 20 Jul 2021 03:24:26 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id l7so25402105wrv.7 for ; Tue, 20 Jul 2021 03:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZfM4QF8THUoYTTDvmBhCmR4GPrCTFDwxvRw2PaS2nSM=; b=iHQvBV3Tqsx0EY0KbW/oNeUVBJWJsozMFTZYLW0HqP3zW8/OEN/FEWaNxNmBDgUrRc GKN5Gk6q6trPsuTD3vEMsGupKG4rKa42TEJ1LSShfHKHl00fe4RFj3Mbf1ovIaEJ3g23 M4TQV5icNfezz9tViNLlpoxf7oi25ZS/MpL/DbM/Ydte9jA24J8v9Hii21HiFg42qsY7 Rk3lODeTaxIMP81CXUKMpyNyEt8hICce+PbDWprnkXSUHe0gSvzCPLcGWgNCX9qdTNHe GutLZT07DYQJBAo/5USbXLGZHfagmJGnmWglYu3jqbsTEz1jqmTdro/rnE49NuJBk9Lg amBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZfM4QF8THUoYTTDvmBhCmR4GPrCTFDwxvRw2PaS2nSM=; b=Vc1ffOGYjNKwNzRsPDHSImbz3uUxBQdc8ajDISFn/tP8Fu6nM+hYjX6cgXdAJJ6rVh FGndoT+CdkfOUTUmSu2Om7gCRU0LlnyF8vl52RgmiJJsTFl/BEKah8eMIVpWaCBx1zf9 tXmblw8FE7sVpcOG4dexwbgoRl3LTtNy2SuXjCsUFDrCEgx+nKOktf6dbFkmokAuKaiK sM1GxxZGG04qHnxq+tEhNoOjWEMG0WK5k9Vm7yRdI072Hhwv1o7FDzMjNKCuIOBYKaUG rIVzQVbwD8z4on23Ed/N0j+ElEp2gaEY8mqKREdRsNESwD6tPrVAdnz6qte5k7amtagf iRBQ== X-Gm-Message-State: AOAM533tEL9+Ju6jy9/084nExS0xrrN9UijkKfIvk2y2/R6ICGPV136Y OucIYgRddVsBAmeS+x3A3VbEiJeYsWkgMA== X-Google-Smtp-Source: ABdhPJzkkrdfvW/smDFOmMPyeLaJSlvmB21h2Ego/Yz85iPZYgbbK8XH4v/w5yqJuZm2icdvxR83aQ== X-Received: by 2002:a5d:528d:: with SMTP id c13mr35420853wrv.343.1626776665072; Tue, 20 Jul 2021 03:24:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 03/12] refs/files: remove unused "extras/skip" in lock_ref_oid_basic() Date: Tue, 20 Jul 2021 12:24:08 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The lock_ref_oid_basic() function has gradually been replaced by use of the file transaction API, there are only 4 remaining callers of it. None of those callers pass non-NULL "extras" and "skip" parameters, the last such caller went away in 92b1551b1d4 (refs: resolve symbolic refs first, 2016-04-25), so let's remove the parameters. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 326f0224218..a59823d667e 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -915,8 +915,6 @@ static int create_reflock(const char *path, void *cb) static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, const char *refname, const struct object_id *old_oid, - const struct string_list *extras, - const struct string_list *skip, unsigned int flags, int *type, struct strbuf *err) { @@ -950,7 +948,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, last_errno = errno; if (!refs_verify_refname_available( &refs->base, - refname, extras, skip, err)) + refname, NULL, NULL, err)) strbuf_addf(err, "there are still refs under '%s'", refname); goto error_return; @@ -963,7 +961,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, last_errno = errno; if (last_errno != ENOTDIR || !refs_verify_refname_available(&refs->base, refname, - extras, skip, err)) + NULL, NULL, err)) strbuf_addf(err, "unable to resolve reference '%s': %s", refname, strerror(last_errno)); @@ -978,7 +976,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, */ if (is_null_oid(&lock->old_oid) && refs_verify_refname_available(refs->packed_ref_store, refname, - extras, skip, err)) { + NULL, NULL, err)) { last_errno = ENOTDIR; goto error_return; } @@ -1413,8 +1411,8 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, logmoved = log; - lock = lock_ref_oid_basic(refs, newrefname, NULL, NULL, NULL, - REF_NO_DEREF, NULL, &err); + lock = lock_ref_oid_basic(refs, newrefname, NULL, REF_NO_DEREF, NULL, + &err); if (!lock) { if (copy) error("unable to copy '%s' to '%s': %s", oldrefname, newrefname, err.buf); @@ -1436,7 +1434,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, goto out; rollback: - lock = lock_ref_oid_basic(refs, oldrefname, NULL, NULL, NULL, + lock = lock_ref_oid_basic(refs, oldrefname, NULL, REF_NO_DEREF, NULL, &err); if (!lock) { error("unable to lock %s for rollback: %s", oldrefname, err.buf); @@ -1845,7 +1843,7 @@ static int files_create_symref(struct ref_store *ref_store, int ret; lock = lock_ref_oid_basic(refs, refname, NULL, - NULL, NULL, REF_NO_DEREF, NULL, + REF_NO_DEREF, NULL, &err); if (!lock) { error("%s", err.buf); @@ -3064,7 +3062,7 @@ static int files_reflog_expire(struct ref_store *ref_store, * reference if --updateref was specified: */ lock = lock_ref_oid_basic(refs, refname, oid, - NULL, NULL, REF_NO_DEREF, + REF_NO_DEREF, &type, &err); if (!lock) { error("cannot lock ref '%s': %s", refname, err.buf); From patchwork Tue Jul 20 10:24:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12388001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA321C07E95 for ; Tue, 20 Jul 2021 10:32:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0F1E6101E for ; Tue, 20 Jul 2021 10:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235892AbhGTJuz (ORCPT ); Tue, 20 Jul 2021 05:50:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237647AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF30C0613B5 for ; Tue, 20 Jul 2021 03:24:27 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id f190so10407448wmf.4 for ; Tue, 20 Jul 2021 03:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KY+tWZQPyoSryn7STBqGNabPfDxysc33R8mcW+m9lqs=; b=jebTL7FSHxZQYoH+GLrHyduYC0GltIaXDtCE09rOE8mhgb0KsYEMH+1IUDtSFmUXhG mC3Q8mvYdlv2HYsxDluO9VoUcGPmvFVUtac2lOjfPluqzyypqrg/6YCLb81p4h3z8RVZ 0RooQ9hBhhjETYM0HOYkqkhuazYpdKUyT1BGlVJAYQ2iI3Zyjto0qw/d4lZzTMIgJ5KI i/HMH0Zt05prjaxvDaVrUp2SyHcEL9Byn+OIcSgfsxQVUREYBqIgsdRVUM2cyUs3CFJs u6r9SdzUju3ap4MxLHtPt284VGRwSltw/YKFfo9Iu98d/MSy2ARM9vJ0lO8WKXDkLgqe OnrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KY+tWZQPyoSryn7STBqGNabPfDxysc33R8mcW+m9lqs=; b=dOm2BNqldrZ84upRkURisvbuhMRsOcCvYGk8u/DH+eu3BHgvRsK7SCY1MWDfPXYHtV 9/Voop1DFU4AgGQwr+sXHoKh8m4y4pyOIsxk8qAsoU/rbQeszSkvInVjEHLScGAKNFqU YeSn60wsWDmQIVyPUdFD4FLY8St2paMd09YmcfM/N7VRw0uL4rqOjdF94P8RB4kG5L10 xnBFyT9zJQBqAsLL2RskvuEyofwbTAEKStY4faSf7fcCylpq2YDx6PeQOmk9lh4Agi0x vcVcP0Nyb5g5dtrUi+/ZSLvc6nF0dRYAr/GjzT/+dycaep4r06SmmAhA30fGvNPjxj4D ygBQ== X-Gm-Message-State: AOAM531i5UDG6R1g/S4xjxnUNondFCTLVGflGpf40oWwtIkAfR0y3CRj n7G5DHdmpbIetQgDykEHlQYTScGK5VYp2w== X-Google-Smtp-Source: ABdhPJy6OGAPwdo8i0cb14zyZFp+0v9/ZfEKm/4vAXr+4+tClrQ2LIfeBGgmxRuclaU6ClpVWuAkWg== X-Received: by 2002:a1c:741a:: with SMTP id p26mr30647650wmc.47.1626776665861; Tue, 20 Jul 2021 03:24:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 04/12] refs/files: remove unused "skip" in lock_raw_ref() too Date: Tue, 20 Jul 2021 12:24:09 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the unused "skip" parameter to lock_raw_ref(), it was never used. We do use it when passing "skip" to the refs_rename_ref_available() function in files_copy_or_rename_ref(), but not here. This is part of a larger series that modifies lock_ref_oid_basic() extensively, there will be no more modifications of this function in this series, but since the preceding commit removed this unused parameter from lock_ref_oid_basic(), let's do it here too for consistency. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index a59823d667e..af332fa8fe4 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -531,7 +531,6 @@ static void unlock_ref(struct ref_lock *lock) static int lock_raw_ref(struct files_ref_store *refs, const char *refname, int mustexist, const struct string_list *extras, - const struct string_list *skip, struct ref_lock **lock_p, struct strbuf *referent, unsigned int *type, @@ -568,7 +567,7 @@ static int lock_raw_ref(struct files_ref_store *refs, * reason to expect this error to be transitory. */ if (refs_verify_refname_available(&refs->base, refname, - extras, skip, err)) { + extras, NULL, err)) { if (mustexist) { /* * To the user the relevant error is @@ -673,7 +672,7 @@ static int lock_raw_ref(struct files_ref_store *refs, REMOVE_DIR_EMPTY_ONLY)) { if (refs_verify_refname_available( &refs->base, refname, - extras, skip, err)) { + extras, NULL, err)) { /* * The error message set by * verify_refname_available() is OK. @@ -710,7 +709,7 @@ static int lock_raw_ref(struct files_ref_store *refs, */ if (refs_verify_refname_available( refs->packed_ref_store, refname, - extras, skip, err)) + extras, NULL, err)) goto error_return; } @@ -2412,7 +2411,7 @@ static int lock_ref_for_update(struct files_ref_store *refs, } ret = lock_raw_ref(refs, update->refname, mustexist, - affected_refnames, NULL, + affected_refnames, &lock, &referent, &update->type, err); if (ret) { From patchwork Tue Jul 20 10:24:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D771C636C8 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57750610D2 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237227AbhGTJst (ORCPT ); Tue, 20 Jul 2021 05:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237649AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FAC7C0613B8 for ; Tue, 20 Jul 2021 03:24:28 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a13so25383927wrf.10 for ; Tue, 20 Jul 2021 03:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ALo8N8Qtn6qP605t6tU9H4g7oH+29n59122nn552CxA=; b=AeQG+XsiaQ/kqOiCag5U2wqutfjQ6Rkj8zUefSJhWS3Sz5n65Rdvxzt3YeUFawE7Z2 BpOjhHqlcv5c4vlK1BYWL8Nd8hJHgxsmmC27asPZBt65+5VJnjjJZA/mBf6okmH/4DdZ L2Jh7T1VpVIjJdCheIEZMyaSBIyQYQzoQdy3Xpuf8A5Z4ugEC59HOQ/uY2+qzC4P9mZJ hHUfJukb3iSECspNDDPWTsziQh0uSWWy8n3EDTQameOReaPNqcmitlWlmeWkYQ8926bu vAp1JehShCBXPB3Iu/9qO9AzGHUwzjZNVqUFdRd0tZIIEnjhF4h257aPhUq/eyej/cxc VxZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ALo8N8Qtn6qP605t6tU9H4g7oH+29n59122nn552CxA=; b=jgC3LMe2Gk9JzOgTYpbQcq9y7PpQA/IXEeaT5KJ6iyEEgMMQHOQ6V8FKgVyhIWCVWW W40VHoQW+FYjCED4T8A+jaZaZtGPJMhBwuOxjd0y10hkAX++mpKgh5Y7cmUuExrlhN93 AJoVWTNdGsTI9AX5FqtewmiIK9UuJc03/5roYJTmNRicsqrBTcoD+5QcAXAsoeQfqQ5M wuAezB+69rAxTthfc79h+36n9F9MuAd8/qYb+WUtAetHOVVbfGyIEDU0Ag9gcPdLcIb/ MOX3VlTfxk9Ya4EYLMkMR9m9LXomNxMQX4/kRd6weOub65EftgjQAqbkBHWvmiovFFoM JJrQ== X-Gm-Message-State: AOAM532cNtiFFkexTigtvxJBMKI8bhdbWH4Ga03mL6UUtHm8DJ/0heeZ NZnVpgUI43UBMHhxkLuzvPcwVNiwJcrq7w== X-Google-Smtp-Source: ABdhPJxergGrmMNiFdldl+bwG2NPJs+83o98fBtHOhqmi2ywmV32Gs6drBPOF6Fte6bn1LKbCYZzbg== X-Received: by 2002:a5d:6dac:: with SMTP id u12mr34632504wrs.153.1626776666938; Tue, 20 Jul 2021 03:24:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 05/12] refs/debug: re-indent argument list for "prepare" Date: Tue, 20 Jul 2021 12:24:10 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Re-indent this argument list that's been mis-indented since it was added in 34c319970d1 (refs/debug: trace into reflog expiry too, 2021-04-23). This makes a subsequent change smaller. Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/refs/debug.c b/refs/debug.c index 7db4abccc34..449ac3e6cc8 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -364,8 +364,8 @@ struct debug_reflog_expiry_should_prune { }; static void debug_reflog_expiry_prepare(const char *refname, - const struct object_id *oid, - void *cb_data) + const struct object_id *oid, + void *cb_data) { struct debug_reflog_expiry_should_prune *prune = cb_data; trace_printf_key(&trace_refs, "reflog_expire_prepare: %s\n", refname); From patchwork Tue Jul 20 10:24:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE6AEC6377E for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1C7D6101E for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237870AbhGTJuq (ORCPT ); Tue, 20 Jul 2021 05:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237648AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39B97C0613BC for ; Tue, 20 Jul 2021 03:24:29 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so1181269wms.1 for ; Tue, 20 Jul 2021 03:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LDAw3YZvdL2a1qC7c/lLSHLg9P6Mwv1ogLcex2KyNrE=; b=rjuFEa8AuK8AE/OYtHjIGuBEV3rlvu2Ijto+E6T9xUbmUi/YWAHwktQ95E3uQy9ESv OMTgvQRHRhzDcBJgjsDGsVRMHpWvQERhHjyBtA+BwwLbIkl56s7R4+6AhXNl10iCyQyH IbAsTHvJTNNyXhlu0WMWOCh9Q7LWfUxfIDdnZvfVilufpf4EtPi+fnL0nGsAr1tKIKbk wOtbF0UTn1btsOg0Z8so3RTfx4ERQiDN7GZNDd/afsEBMueEwRjII66rA7W6reZirMBa fCG7QKFKmIW7qY5iNKytBpEHoIaObOjenJ8uP3Fq4VO5V4R8/qm2kfpyIYXdW3FZ/ITb XLgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LDAw3YZvdL2a1qC7c/lLSHLg9P6Mwv1ogLcex2KyNrE=; b=skhsAfWMSkg7kxvCiQQzosizoTMfhg95/BJViuB0uYwy0GTNdfPdVz1X9cL2KNP2St GkxoPrVcmNrx1IvY5j3rc7tTUKqJFKtK0M5RWzujK/g0z3t5QN6AwjejvdQpcLabaRXS 3NhoDEhle8mzaUDlNYnUckyZ01WPLsOFPxNAODe9jXOPrL4qL+eQy4W1+k5CVqU6sy30 9d9iIiUKSrMxfZBoDJGQsP0HRqagbtddVoL9sXpONMj83hSgc53YUqD17HV8oTeWDOBb h+YV+PjoLhZJwW13Sf3a/Bb5b4Iu2Qq+76ZrY0MjbJUeAyakk6dzF9A7Bm3kXvq/VTKG OViA== X-Gm-Message-State: AOAM531Il3YWu6hhM1QlGftYFVa6C0GrY32tNGBuGCzQzwocO+QbuWHZ tIz4sOecm/PVDWqPpkieCHjaGs2FmkE5Aw== X-Google-Smtp-Source: ABdhPJyGvo3i8vxHT2pJcjAx+2xO7LLKBAfmoBmqbAVwiJg0vFQzuIxHaLxlcuojk0S44Qt0RDqG5A== X-Received: by 2002:a1c:c91a:: with SMTP id f26mr30866897wmb.162.1626776667621; Tue, 20 Jul 2021 03:24:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 06/12] refs API: pass the "lock OID" to reflog "prepare" Date: Tue, 20 Jul 2021 12:24:11 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Don't pass the object ID we pass into reflog_expire() back to the caller, but rather our locked OID. As the assert shows these two were the same thing in practice as we'd exit earlier in this function if we couldn't lock the desired OID. This is in preparation for a subsequent change of not having reflog_expire() pass in the OID at all, also remove the "const" from the parameter since the "struct ref_lock" does not have it on its "old_oid" member. As we'll see in a subsequent commit we don't actually want to assert that we locked a given OID, we want this API to do the locking and tell us what the OID is, but for now let's just setup the basic scaffolding for that. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 4 ++-- refs.h | 4 ++-- refs/debug.c | 8 +++++--- refs/files-backend.c | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 09541d1c804..9f9e6bceb03 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -351,7 +351,7 @@ static int is_head(const char *refname) } static void reflog_expiry_prepare(const char *refname, - const struct object_id *oid, + struct object_id *locked_oid, void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; @@ -361,7 +361,7 @@ static void reflog_expiry_prepare(const char *refname, cb->unreachable_expire_kind = UE_HEAD; } else { cb->tip_commit = lookup_commit_reference_gently(the_repository, - oid, 1); + locked_oid, 1); if (!cb->tip_commit) cb->unreachable_expire_kind = UE_ALWAYS; else diff --git a/refs.h b/refs.h index 48970dfc7e0..c009707438d 100644 --- a/refs.h +++ b/refs.h @@ -796,7 +796,7 @@ enum expire_reflog_flags { * expiration policy that is desired. * * reflog_expiry_prepare_fn -- Called once after the reference is - * locked. + * locked. Called with the OID of the locked reference. * * reflog_expiry_should_prune_fn -- Called once for each entry in the * existing reflog. It should return true iff that entry should be @@ -806,7 +806,7 @@ enum expire_reflog_flags { * unlocked again. */ typedef void reflog_expiry_prepare_fn(const char *refname, - const struct object_id *oid, + struct object_id *lock_oid, void *cb_data); typedef int reflog_expiry_should_prune_fn(struct object_id *ooid, struct object_id *noid, diff --git a/refs/debug.c b/refs/debug.c index 449ac3e6cc8..18fd9bca595 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -364,12 +364,14 @@ struct debug_reflog_expiry_should_prune { }; static void debug_reflog_expiry_prepare(const char *refname, - const struct object_id *oid, + struct object_id *locked_oid, void *cb_data) { struct debug_reflog_expiry_should_prune *prune = cb_data; - trace_printf_key(&trace_refs, "reflog_expire_prepare: %s\n", refname); - prune->prepare(refname, oid, prune->cb_data); + trace_printf_key(&trace_refs, "reflog_expire_prepare: %s locket at %s\n", + refname, + oid_to_hex(locked_oid)); + prune->prepare(refname, locked_oid, prune->cb_data); } static int debug_reflog_expiry_should_prune_fn(struct object_id *ooid, diff --git a/refs/files-backend.c b/refs/files-backend.c index af332fa8fe4..ce4b3fb1c7a 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3098,7 +3098,8 @@ static int files_reflog_expire(struct ref_store *ref_store, } } - (*prepare_fn)(refname, oid, cb.policy_cb); + assert(oideq(&lock->old_oid, oid)); + (*prepare_fn)(refname, &lock->old_oid, cb.policy_cb); refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb); (*cleanup_fn)(cb.policy_cb); From patchwork Tue Jul 20 10:24:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387983 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7A60C636CA for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B10A61186 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237709AbhGTJtp (ORCPT ); Tue, 20 Jul 2021 05:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237651AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DACEC0613BD for ; Tue, 20 Jul 2021 03:24:30 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id f10-20020a05600c4e8ab029023e8d74d693so1716384wmq.3 for ; Tue, 20 Jul 2021 03:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IM+n33hI6Lqx7U/j+V12GnoODEmZo1L/cn2BWi4aFoA=; b=e4HwgtYRvoWMwxR2Ft+c1G56W1T2KAz4gnwIwttOpn4RTdqNNr2XcI4Bp4v0g9Jfo/ CsMcDX/eOgA8gxmGjjRsedT6VLBcsftqXjoMwASUW03UonetXA7/m2bibPNRTRE/ilLY U4qffWJ29HrPF8MMgbabAoRFJwBKo28+lvYnrcAvdkO5zRsqHcqibM++lQ788Yunn42P A8Zi2wtV29Hb2lij179G3kvaMbt8N/vevmkVYWezDSz99Vzb7R9aNm9WyUVbVV16AHJX qDxmc+Zm5Rhpy0YV4ey9iE2FwSvkW+OTIyLoPYTYWrwMYQtli2z1iWxDOQ60xQWWau7r huog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IM+n33hI6Lqx7U/j+V12GnoODEmZo1L/cn2BWi4aFoA=; b=rY4nOCadIcafT9HQc6oBxenzw6GY9nENZQaCT0bBijDO91tOYbkmjEW2PExpGC+RvI bRdAx2KvC/i2thBujT+Q3Ww286CYDCVmpHQyg30TQVxL+ycb4kDytTLCpJBRG2OqPqCa uACTceDpAFUk4ohcVmDeC+aGrWNp+DnflhXVC6KjfKtP8iRTfL/But2HZb7asi8dcOKe v4zDQ1TGG04mUYBCv9ubOquJN2OOk4Wg7yrLqmHH0NSv8NFxL26ufP17PkMCU/OJNfyN n5vjADZvsdsn/molEmOcUb5lFdi3J2BDOotI7QIV4HXblJvQQxbG09yE7hQQw2O/kaOc zGkA== X-Gm-Message-State: AOAM530SOG/iJnXiIab2+egq66KT78MYMn9ZUO4VtHjPJemr5fzDB+af ii48Q6Zjsc4hcCItYxqliwTkgx1sUxvafw== X-Google-Smtp-Source: ABdhPJwNBtHyYiLIl6PqI+TtWdMnmCP9WLTU0ps2VsA6+NUMzAFLEFCFWFfbp99d3drZj5j6iC61Vg== X-Received: by 2002:a7b:c385:: with SMTP id s5mr30049740wmj.43.1626776668409; Tue, 20 Jul 2021 03:24:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 07/12] refs: make repo_dwim_log() accept a NULL oid Date: Tue, 20 Jul 2021 12:24:12 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the repo_dwim_log() function initially added as dwim_log() in eb3a48221fd (log --reflog: use dwim_log, 2007-02-09) to accept a NULL oid parameter. The refs_resolve_ref_unsafe() function it invokes already deals with it, but it didn't. This allows for a bit more clarity in a reflog-walk.c codepath added in f2eba66d4d1 (Enable HEAD@{...} and make it independent from the current branch, 2007-02-03). We'll shortly use this in builtin/reflog.c as well. Signed-off-by: Ævar Arnfjörð Bjarmason --- reflog-walk.c | 3 +-- refs.c | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reflog-walk.c b/reflog-walk.c index e9cd3283694..8ac4b284b6b 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -158,10 +158,9 @@ int add_reflog_for_walk(struct reflog_walk_info *info, } reflogs = read_complete_reflog(branch); if (!reflogs || reflogs->nr == 0) { - struct object_id oid; char *b; int ret = dwim_log(branch, strlen(branch), - &oid, &b); + NULL, &b); if (ret > 1) free(b); else if (ret == 1) { diff --git a/refs.c b/refs.c index 8b9f7c3a80a..d9635436759 100644 --- a/refs.c +++ b/refs.c @@ -698,7 +698,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len, strbuf_addf(&path, *p, len, str); ref = refs_resolve_ref_unsafe(refs, path.buf, RESOLVE_REF_READING, - &hash, NULL); + oid ? &hash : NULL, NULL); if (!ref) continue; if (refs_reflog_exists(refs, path.buf)) @@ -710,7 +710,8 @@ int repo_dwim_log(struct repository *r, const char *str, int len, continue; if (!logs_found++) { *log = xstrdup(it); - oidcpy(oid, &hash); + if (oid) + oidcpy(oid, &hash); } if (!warn_ambiguous_refs) break; From patchwork Tue Jul 20 10:24:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387981 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BC8CC07E9B for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 629826120F for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237449AbhGTJtI (ORCPT ); Tue, 20 Jul 2021 05:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237652AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD565C0613BE for ; Tue, 20 Jul 2021 03:24:30 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id c12so7399008wrt.3 for ; Tue, 20 Jul 2021 03:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ryKUMtXcrmxdlURminBMLvgMC9zyz7J8hNISbA3YZJU=; b=BVmupZdd8OBwmZy8IN+w3tWbMveARgu+HFmMCU7afFH41TLUdefPedmS551GqWltLJ bc1YamJe9fO8t6kvn9JGHqo/S2gkK6/fLr2BdqLK9510t1GnIk8Xfm7LKioWk4kgAqpn H6NYclBEQkhdL5qpdFSi/Z7+NTDQK8x81+KPHTk+a/yAXKOdF7WnnwHHIBYYGoUX7TM5 xYGoZuJ3I4WZbBnU4jt82BhmZDatXYu12KHaUA0J6tymIdOuwsKar6UA3LLA6TgOvYfp PdMTA8PSjBlEK7F4RELHrU4GWoX+oiaxw7z6MMkdZ8rkTybbzDHLRKWsICZuPOSKmtcY iOow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ryKUMtXcrmxdlURminBMLvgMC9zyz7J8hNISbA3YZJU=; b=Y+s3wPZKLn2NVHyTFpEivSLX2w5ABP+/NnFb+ElfazO3v/f7XpFO63uzEGjkNgEbmX K/lcL6Bp1lY/wh5Zzy+vYC590Ldkm7otBNGTIOuHIJVUzh+12jUqdsCqVM2na25SxSb7 jDAVXGYTa+HTUn7b63PGqOn3YEB0l4PcnKSvK1nJ3bXVbGpx2JYgyDSBIkGBRbk3FZtE LxkyHxIMkmF+xhpuUnnUH36XfHOzsPEWOKlkeczwmf+thrOsfXnfV6AEdPteTeyXTFP4 3UzDs9jmPhW1oYx7V2GatoeoARujZ5/jDOweGHpMj2prM1lHQT+sjBLbsT2TA2b0mfWh UDPg== X-Gm-Message-State: AOAM530t/m1IjxIt04dcNTqw7jbztrPPniy9KLftVJLeDg4YngHTpbi/ cqyxW5dO9aVDsqqclDxhHsC2kiwejhRUBA== X-Google-Smtp-Source: ABdhPJwkPIYqDvilXYcwoWLJCDCc3OVYS89Yz8O2W7BySGnvJU2jDPMfAQL7kAv17HfHws79rTHskQ== X-Received: by 2002:a5d:5642:: with SMTP id j2mr13651504wrw.65.1626776669211; Tue, 20 Jul 2021 03:24:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 08/12] refs/files: add a comment about refs_reflog_exists() call Date: Tue, 20 Jul 2021 12:24:13 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a comment about why it is that we need to check for the the existence of a reflog we're deleting after we've successfully acquired the lock in files_reflog_expire(). As noted in [1] the lock protocol for reflogs is somewhat intuitive. This early exit code the comment applies to dates all the way back to 4264dc15e19 (git reflog expire, 2006-12-19). 1. https://lore.kernel.org/git/54DCDA42.2060800@alum.mit.edu/ Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/refs/files-backend.c b/refs/files-backend.c index ce4b3fb1c7a..92f49cfb7d4 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3068,6 +3068,19 @@ static int files_reflog_expire(struct ref_store *ref_store, strbuf_release(&err); return -1; } + + /* + * When refs are deleted, their reflog is deleted before the + * ref itself is deleted. This is because there is no separate + * lock for reflog; instead we take a lock on the ref with + * lock_ref_oid_basic(). + * + * If a race happens and the reflog doesn't exist after we've + * acquired the lock that's OK. We've got nothing more to do; + * We were asked to delete the reflog, but someone else + * deleted it! The caller doesn't care that we deleted it, + * just that it is deleted. So we can return successfully. + */ if (!refs_reflog_exists(ref_store, refname)) { unlock_ref(lock); return 0; From patchwork Tue Jul 20 10:24:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99E05C636C9 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 839E1611C1 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237598AbhGTJt3 (ORCPT ); Tue, 20 Jul 2021 05:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237659AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC22BC061341 for ; Tue, 20 Jul 2021 03:24:31 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id d12so25375779wre.13 for ; Tue, 20 Jul 2021 03:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QbBMDDH6pr5hKmJWPfK7Eu/bWEEx+jmTSktgti/nTfs=; b=FKTGlV6Iw+xP0i5fut6I5vVGj8HgwpePlVu8mK/hoFTfIQQzwCvXQuApF0D1PsdOiY maEsDEhiZ0mbYG4WCZeL2QTZT6za9rJcvLCiAJGu0Hh5ua5txzuG1It7mNV3Rp7BuPfW wap9hSqtFBNZ2X7T2nzvqDXXNx84gxe++CxQOAMn/Qclg86qZAqsLVo12wZcrICK8l20 raHqJ3/z0OZ4dCIfXBz/8jLmaUR9Q/BQZcvr1CvrVTX+0OCh8NFppi++BjabtNZf72t6 4s0paFH6WwEjSzh39TnaWpri+hsigAvHoHDeXYWw9rAhwpOs0LW8pwyZE/REAnhUEPjv trXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QbBMDDH6pr5hKmJWPfK7Eu/bWEEx+jmTSktgti/nTfs=; b=kJg6C/MZZbwkJKyUqQlx43t7A8l+cA/aTIOVI22JcmkUIq7EVV3qhzHc2H29PHdjqU cSEsLuCEkCmOAnKh6taxXBPYLGzmhGFfQjgYnDt+9DreSoMpLjFBDdWW4g9fh/GmzIsq aUDgQ8R0tK/ytODOdrenaRMRTswPLEgmzLDBrdHPH144pdN5HsCXb1fAJ88/CLpZHxeD PHkBtujy75Pudbi9nQy9hpogJUlMtyJt7sK6K94YbLbpy1PqCjqs1yipKOrPmxmSlvlw EFo8D9pkkn/dxXnqyEAckMspb9Hr9gpmTixE9TCpAqDdd2L8pxKx49dnU9xjycB5VWPf 3mig== X-Gm-Message-State: AOAM533ApfPo1rQ8HYaBbsvQfWD/qEd9XJMJ0HP0FO5h91lgn0NuJSoM 8dEVO0N0h8v82ldCdVBFGQTDxo1d10JLGQ== X-Google-Smtp-Source: ABdhPJyCnEuJpoXfJYIuX545AFOuUyfalougMHWN30roYaRfiHwdpZO9aEKfHhmDSiBw2dc4XDq4XQ== X-Received: by 2002:a5d:4c8c:: with SMTP id z12mr36313318wrs.97.1626776670160; Tue, 20 Jul 2021 03:24:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 09/12] reflog expire: don't lock reflogs using previously seen OID Date: Tue, 20 Jul 2021 12:24:14 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org During reflog expiry, the cmd_reflog_expire() function first iterates over all reflogs in logs/*, and then one-by-one acquires the lock for each one and expires it. This behavior has been with us since this command was implemented in 4264dc15e1 ("git reflog expire", 2006-12-19). Change this to stop calling lock_ref_oid_basic() with the OID we saw when we looped over the logs, instead have it pass the OID it managed to lock. This mostly mitigates a race condition where e.g. "git gc" will fail in a concurrently updated repository because the branch moved since "git reflog expire --all" was started. I.e. with: error: cannot lock ref '': ref '' is at but expected This behavior of passing in an "oid" was needed for an edge-case that I've untangled in this and preceding commits though, namely that we needed this OID because we'd: 1. Lookup the reflog name/OID via dwim_log() 2. With that OID, lock the reflog 3. Later in builtin/reflog.c we use the OID we looked as input to lookup_commit_reference_gently(), assured that it's equal to the OID we got from dwim_log(). We can be sure that this change is safe to make because between dwim_log (step #1) and lock_ref_oid_basic (step #2) there was no other logic relevant to the OID or expiry run in the cmd_reflog_expire() caller. We can thus treat that code as a black box, before and after this change it would get an OID that's been locked, the only difference is that now we mostly won't be failing to get the lock due to the TOCTOU race[0]. That failure was purely an implementation detail in how the "current OID" was looked up, it was divorced from the locking mechanism. What do we mean with "mostly"? It mostly mitigates it because we'll still run into cases where the ref is locked and being updated as we want to expire it, and other git processes wanting to update the refs will in turn race with us as we expire the reflog. That remaining race can in turn be mitigated with the core.filesRefLockTimeout setting, see 4ff0f01cb7 ("refs: retry acquiring reference locks for 100ms", 2017-08-21). In practice if that value is high enough we'll probably never have ref updates or reflog expiry failing, since the clients involved will retry for far longer than the time any of those operations could take. See [1] for an initial report of how this impacted "git gc" and a large discussion about this change in early 2019. In particular patch looked good to Michael Haggerty, see his[2]. That message seems to not have made it to the ML archive, its content is quoted in full in my [3]. I'm leaving behind now-unused code the refs API etc. that takes the now-NULL "oid" argument, and other code that can be simplified now that we never have on OID in that context, that'll be cleaned up in subsequent commits, but for now let's narrowly focus on fixing the "git gc" issue. As the modified assert() shows we always pass a NULL oid to reflog_expire() now. Unfortunately this sort of probabilistic contention is hard to turn into a test. I've tested this by running the following three subshells in concurrent terminals: ( rm -rf /tmp/git && git init /tmp/git && while true do head -c 10 /dev/urandom | hexdump >/tmp/git/out && git -C /tmp/git add out && git -C /tmp/git commit -m"out" done ) ( rm -rf /tmp/git-clone && git clone file:///tmp/git /tmp/git-clone && while git -C /tmp/git-clone pull do date done ) ( while git -C /tmp/git-clone reflog expire --all do date done ) Before this change the "reflog expire" would fail really quickly with the "but expected" error noted above. After this change both the "pull" and "reflog expire" will run for a while, but eventually fail because I get unlucky with core.filesRefLockTimeout (the "reflog expire" is in a really tight loop). As noted above that can in turn be mitigated with higher values of core.filesRefLockTimeout than the 100ms default. As noted in the commentary added in the preceding commit there's also the case of branches being racily deleted, that can be tested by adding this to the above: ( while git -C /tmp/git-clone branch topic master && git -C /tmp/git-clone branch -D topic do date done ) With core.filesRefLockTimeout set to 10 seconds (it can probably be a lot lower) I managed to run all four of these concurrently for about an hour, and accumulated ~125k commits, auto-gc's and all, and didn't have a single failure. The loops visibly stall while waiting for the lock, but that's expected and desired behavior. 0. https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use 1. https://lore.kernel.org/git/87tvg7brlm.fsf@evledraar.gmail.com/ 2. http://lore.kernel.org/git/b870a17d-2103-41b8-3cbc-7389d5fff33a@alum.mit.edu 3. https://lore.kernel.org/git/87pnqkco8v.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/reflog.c | 13 ++++++------- refs/files-backend.c | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/builtin/reflog.c b/builtin/reflog.c index 9f9e6bceb03..4506852c471 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -629,8 +629,9 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) free_worktrees(worktrees); for (i = 0; i < collected.nr; i++) { struct collected_reflog *e = collected.e[i]; + set_reflog_expiry_param(&cb.cmd, explicit_expiry, e->reflog); - status |= reflog_expire(e->reflog, &e->oid, flags, + status |= reflog_expire(e->reflog, NULL, flags, reflog_expiry_prepare, should_expire_reflog_ent, reflog_expiry_cleanup, @@ -642,13 +643,12 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix) for (; i < argc; i++) { char *ref; - struct object_id oid; - if (!dwim_log(argv[i], strlen(argv[i]), &oid, &ref)) { + if (!dwim_log(argv[i], strlen(argv[i]), NULL, &ref)) { status |= error(_("%s points nowhere!"), argv[i]); continue; } set_reflog_expiry_param(&cb.cmd, explicit_expiry, ref); - status |= reflog_expire(ref, &oid, flags, + status |= reflog_expire(ref, NULL, flags, reflog_expiry_prepare, should_expire_reflog_ent, reflog_expiry_cleanup, @@ -700,7 +700,6 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) for ( ; i < argc; i++) { const char *spec = strstr(argv[i], "@{"); - struct object_id oid; char *ep, *ref; int recno; @@ -709,7 +708,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) continue; } - if (!dwim_log(argv[i], spec - argv[i], &oid, &ref)) { + if (!dwim_log(argv[i], spec - argv[i], NULL, &ref)) { status |= error(_("no reflog for '%s'"), argv[i]); continue; } @@ -724,7 +723,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) cb.cmd.expire_total = 0; } - status |= reflog_expire(ref, &oid, flags, + status |= reflog_expire(ref, NULL, flags, reflog_expiry_prepare, should_expire_reflog_ent, reflog_expiry_cleanup, diff --git a/refs/files-backend.c b/refs/files-backend.c index 92f49cfb7d4..819351c82fc 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3060,7 +3060,7 @@ static int files_reflog_expire(struct ref_store *ref_store, * reference itself, plus we might need to update the * reference if --updateref was specified: */ - lock = lock_ref_oid_basic(refs, refname, oid, + lock = lock_ref_oid_basic(refs, refname, NULL, REF_NO_DEREF, &type, &err); if (!lock) { @@ -3111,7 +3111,7 @@ static int files_reflog_expire(struct ref_store *ref_store, } } - assert(oideq(&lock->old_oid, oid)); + assert(!oid); (*prepare_fn)(refname, &lock->old_oid, cb.policy_cb); refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb); (*cleanup_fn)(cb.policy_cb); From patchwork Tue Jul 20 10:24:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A914DC07E9B for ; Tue, 20 Jul 2021 10:29:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FB0161019 for ; Tue, 20 Jul 2021 10:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237141AbhGTJsI (ORCPT ); Tue, 20 Jul 2021 05:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237639AbhGTJqN (ORCPT ); Tue, 20 Jul 2021 05:46:13 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8770C0612E9 for ; Tue, 20 Jul 2021 03:24:32 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id q18-20020a1ce9120000b02901f259f3a250so1723359wmc.2 for ; Tue, 20 Jul 2021 03:24:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Oi1VeRUAlHt4mjCkCiIFPvQgA3VtFMWLSOPqWtrhkh4=; b=g4SsB0iHLi258rULNzYujDRxwLjsDEcjXPFxSvJyqnxtX1RW7cEE9/5wNxowCNILAZ q36JXUffN6fPj3vl5OCY61lm938D58HVbITcn9qiaEF+h/zTrqv+rJOGvg3tlmc0mITv RUaRSNUQWRheSc1qHQAtvYIwm4wuqPIIUkK8pvd7Z5TGkq1FdPTMek9pYQcwr+D2NKaa GuegQ/QbQpHo/uB8YYHPBpRAR8rTgh8VCbpT8XizAD9HCh/+TSE1b3Ic5TUvv0L1a6KD iTNLQbMWmPTkN8GOTEebWFba1HCVEESzC/q5AIQQcqj1wL7DcFpqRQ4MVIsmg4YKMEFL 7avw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Oi1VeRUAlHt4mjCkCiIFPvQgA3VtFMWLSOPqWtrhkh4=; b=RDiPc3IXtNW0V1XjoVAk1vIz/PLhBPp+PRUA3pqzY72I4FCwR20h3iKHEn3ZEOjoWQ tdHPrlVovaBl4EdSg/rjpumv8rd0fJw+6L0yS4tsThTT5xz2UYWEkD10On6oUbddvn6n JAJH83oKO3VKMdTssBywR6+Jj2d+vXrrIGLdT2i7d7/qeXX5Vyz5iwaGEQhqLVLqy2pW lPXXk2L5dPLfL0S7TbIxFYr18eLgduqKJXbrPW8JBLVhju2Q/owrtHX8Ar4RV/T6l6db KhIeuYOHRogPydnaQ8M58+2iXBjhtllL2mceCKCaMAttNLAZNXHfB6JRAh1rRiKfmYtP 44ww== X-Gm-Message-State: AOAM5300txm9q3IYHuarJxpOsrsdcOo7flLsjlDtQbzu8baqE/FACmRQ aAaOH9vGJTHaeVoYeal68JCVqcnFAdERUg== X-Google-Smtp-Source: ABdhPJw78ybiKysER3nWq3lr9PJTe/oX9QCw8eT1wD314HQXdTU1zJBzKQSgZJLqVHDlipcsNUrzTA== X-Received: by 2002:a7b:cd15:: with SMTP id f21mr31488324wmj.148.1626776671323; Tue, 20 Jul 2021 03:24:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 10/12] refs/files: remove unused "oid" in lock_ref_oid_basic() Date: Tue, 20 Jul 2021 12:24:15 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the preceding commit the last caller that passed a non-NULL OID was changed to pass NULL to lock_ref_oid_basic(). As noted in preceding commits use of this API has been going away (we should use ref transactions, or lock_raw_ref()), so we're unlikely to gain new callers that want to pass the "oid". So let's remove it, doing so means we can remove the "mustexist" condition, and therefore anything except the "flags = RESOLVE_REF_NO_RECURSE" case. Furthermore, since the verify_lock() function we called did most of its work when the "oid" was passed (as "old_oid") we can inline the trivial part of it that remains in its only remaining caller. Without a NULL "oid" passed it was equivalent to calling refs_read_ref_full() followed by oidclr(). Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 72 ++++++++------------------------------------ 1 file changed, 12 insertions(+), 60 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 819351c82fc..8bbabc140b2 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -852,42 +852,6 @@ static struct ref_iterator *files_ref_iterator_begin( return ref_iterator; } -/* - * Verify that the reference locked by lock has the value old_oid - * (unless it is NULL). Fail if the reference doesn't exist and - * mustexist is set. Return 0 on success. On error, write an error - * message to err, set errno, and return a negative value. - */ -static int verify_lock(struct ref_store *ref_store, struct ref_lock *lock, - const struct object_id *old_oid, int mustexist, - struct strbuf *err) -{ - assert(err); - - if (refs_read_ref_full(ref_store, lock->ref_name, - mustexist ? RESOLVE_REF_READING : 0, - &lock->old_oid, NULL)) { - if (old_oid) { - int save_errno = errno; - strbuf_addf(err, "can't verify ref '%s'", lock->ref_name); - errno = save_errno; - return -1; - } else { - oidclr(&lock->old_oid); - return 0; - } - } - if (old_oid && !oideq(&lock->old_oid, old_oid)) { - strbuf_addf(err, "ref '%s' is at %s but expected %s", - lock->ref_name, - oid_to_hex(&lock->old_oid), - oid_to_hex(old_oid)); - errno = EBUSY; - return -1; - } - return 0; -} - static int remove_empty_directories(struct strbuf *path) { /* @@ -913,15 +877,12 @@ static int create_reflock(const char *path, void *cb) */ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, const char *refname, - const struct object_id *old_oid, unsigned int flags, int *type, struct strbuf *err) { struct strbuf ref_file = STRBUF_INIT; struct ref_lock *lock; int last_errno = 0; - int mustexist = (old_oid && !is_null_oid(old_oid)); - int resolve_flags = RESOLVE_REF_NO_RECURSE; int resolved; files_assert_main_repository(refs, "lock_ref_oid_basic"); @@ -929,12 +890,9 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, CALLOC_ARRAY(lock, 1); - if (mustexist) - resolve_flags |= RESOLVE_REF_READING; - files_ref_path(refs, &ref_file, refname); - resolved = !!refs_resolve_ref_unsafe(&refs->base, - refname, resolve_flags, + resolved = !!refs_resolve_ref_unsafe(&refs->base, refname, + RESOLVE_REF_NO_RECURSE, &lock->old_oid, type); if (!resolved && errno == EISDIR) { /* @@ -952,8 +910,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, refname); goto error_return; } - resolved = !!refs_resolve_ref_unsafe(&refs->base, - refname, resolve_flags, + resolved = !!refs_resolve_ref_unsafe(&refs->base, refname, + RESOLVE_REF_NO_RECURSE, &lock->old_oid, type); } if (!resolved) { @@ -988,10 +946,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, goto error_return; } - if (verify_lock(&refs->base, lock, old_oid, mustexist, err)) { - last_errno = errno; - goto error_return; - } + if (refs_read_ref_full(&refs->base, lock->ref_name, + 0, + &lock->old_oid, NULL)) + oidclr(&lock->old_oid); goto out; error_return: @@ -1410,8 +1368,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, logmoved = log; - lock = lock_ref_oid_basic(refs, newrefname, NULL, REF_NO_DEREF, NULL, - &err); + lock = lock_ref_oid_basic(refs, newrefname, REF_NO_DEREF, NULL, &err); if (!lock) { if (copy) error("unable to copy '%s' to '%s': %s", oldrefname, newrefname, err.buf); @@ -1433,8 +1390,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, goto out; rollback: - lock = lock_ref_oid_basic(refs, oldrefname, NULL, - REF_NO_DEREF, NULL, &err); + lock = lock_ref_oid_basic(refs, oldrefname, REF_NO_DEREF, NULL, &err); if (!lock) { error("unable to lock %s for rollback: %s", oldrefname, err.buf); strbuf_release(&err); @@ -1841,9 +1797,7 @@ static int files_create_symref(struct ref_store *ref_store, struct ref_lock *lock; int ret; - lock = lock_ref_oid_basic(refs, refname, NULL, - REF_NO_DEREF, NULL, - &err); + lock = lock_ref_oid_basic(refs, refname, REF_NO_DEREF, NULL, &err); if (!lock) { error("%s", err.buf); strbuf_release(&err); @@ -3060,9 +3014,7 @@ static int files_reflog_expire(struct ref_store *ref_store, * reference itself, plus we might need to update the * reference if --updateref was specified: */ - lock = lock_ref_oid_basic(refs, refname, NULL, - REF_NO_DEREF, - &type, &err); + lock = lock_ref_oid_basic(refs, refname, REF_NO_DEREF, &type, &err); if (!lock) { error("cannot lock ref '%s': %s", refname, err.buf); strbuf_release(&err); From patchwork Tue Jul 20 10:24:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7E12C6377B for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F51861244 for ; Tue, 20 Jul 2021 10:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237649AbhGTJtk (ORCPT ); Tue, 20 Jul 2021 05:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237661AbhGTJqO (ORCPT ); Tue, 20 Jul 2021 05:46:14 -0400 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 A2F1DC0612FB for ; Tue, 20 Jul 2021 03:24:33 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d12so25375858wre.13 for ; Tue, 20 Jul 2021 03:24:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JGXV+68aFUcskTXeUCqz/dzjmM5gL9BbXpptl8bSzE8=; b=PSbeiWkWfJwYoZvJo0bIVV/uJra+SqckuhitF+uNq7bb7bwlUbMAiA52Z0RXJSptr9 dMWeZ6CClyDbi6BZMnE/3A4QyH/qAjQWqqZeL8RubWBVrqpEc0LgYA4AH3j/AcN+2QYf KH/IWzGWqlVYioXj0oz562MkFBJiNiDfvimXT27WILARVumpV1vmBCip2Zy8lJK5cAMY NPPz7yETsAdSj75u3zw1+93vWwiZkFW5z7EZiq/UtWHOVhqnDxCcGPLaUEJhhH4SULaP 08yoWXDUKdZZnmPoIhM9NIi59wCS3zYLRMLC4p1qKQ9jkQ8lkRR8keZVuPmCsLSPbaAl 0/Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JGXV+68aFUcskTXeUCqz/dzjmM5gL9BbXpptl8bSzE8=; b=Y5lYMugbt8m+/eJtXLnY40Bnjj0P09TPWKOCITCzbByBlINVxKpmN7J/YkNWRVojRF 36Xusys3JbtVV0L/7kCVrHrX7VcfceN7+DnlNi6ZXpysR0zZpGfNfViq971XBrDEZQ6C PKDAmKbg+2j/uRndCAGScKuu/V4Z/jfeRElMnXY2bnIude50YNb8N5Y/tDR8NpmIJq3k PuBdnnTLvQtbdLjcjfaPE3T7j/9Rd3I7dfRUEu70HqcIxJLPIAvWE+REJhR035X72jwH 7UINiApX0dYZbd6ZGT9nMJtcJ7OXX8UlP7J8eD7AkZrFBYt101iFE02b/F0MiSieIWCf iPqw== X-Gm-Message-State: AOAM533DFskN1lvg3WKIs5nbvyjxzl8hJ3yamtdBwH/Pq+NjrWtjZFpl JX3VcVxzYWFzv2j+hX/TQ8jLBzds9m0RBA== X-Google-Smtp-Source: ABdhPJw/Rr1J+Z99wg1+OH46hAFyDxjtv8sqhc/ZClVkRFWGeSmagv5RZB/uMUZfJbcr/t7epgRhuQ== X-Received: by 2002:adf:9d88:: with SMTP id p8mr36282061wre.409.1626776672049; Tue, 20 Jul 2021 03:24:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 11/12] refs/files: remove unused "errno == EISDIR" code Date: Tue, 20 Jul 2021 12:24:16 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When we lock a reference like "foo" we need to handle the case where "foo" exists, but is an empty directory. That's what this code added in bc7127ef0f (ref locking: allow 'foo' when 'foo/bar' used to exist but not anymore., 2006-09-30) seems like it should be dealing with. Except it doesn't, and we never take this branch. The reason is that when bc7127ef0f was written this looked like: ref = resolve_ref([...]); if (!ref && errno == EISDIR) { [...] And in resolve_ref() we had this code: fd = open(path, O_RDONLY); if (fd < 0) return NULL; I.e. we would attempt to read "foo" with open(), which would fail with EISDIR and we'd return NULL. We'd then take this branch, call remove_empty_directories() and continue. Since a1c1d8170d (refs_resolve_ref_unsafe: handle d/f conflicts for writes, 2017-10-06) we don't. E.g. in the case of files_copy_or_rename_ref() our callstack will look something like: [...] -> files_copy_or_rename_ref() -> lock_ref_oid_basic() -> refs_resolve_ref_unsafe() At that point the first (now only) refs_resolve_ref_unsafe() call in lock_ref_oid_basic() would do the equivalent of this in the resulting call to refs_read_raw_ref() in refs_resolve_ref_unsafe(): /* Via refs_read_raw_ref() */ fd = open(path, O_RDONLY); if (fd < 0) /* get errno == EISDIR */ /* later, in refs_resolve_ref_unsafe() */ if ([...] && errno != EISDIR) return NULL; [...] /* returns the refs/heads/foo to the caller, even though it's a directory */ return refname; I.e. even though we got an "errno == EISDIR" we won't take this branch, since in cases of EISDIR "resolved" is always non-NULL. I.e. we pretend at this point as though everything's OK and there is no "foo" directory. We then proceed with the entire ref update and don't call remove_empty_directories() until we call commit_ref_update(). See 5387c0d883 (commit_ref(): if there is an empty dir in the way, delete it, 2016-05-05) for the addition of that code, and a1c1d8170db (refs_resolve_ref_unsafe: handle d/f conflicts for writes, 2017-10-06) for the commit that changed the original codepath added in bc7127ef0f to use this "EISDIR" handling. Further historical commentary: Before the two preceding commits the caller in files_reflog_expire() was the only one out of our 4 callers that would pass non-NULL as an oid. We would then set a (now gone) "resolve_flags" to "RESOLVE_REF_READING" and just before that "errno != EISDIR" check do: if (resolve_flags & RESOLVE_REF_READING) return NULL; There may have been some case where this ended up mattering and we couldn't safely make this change before we removed the "oid" parameter, but I don't think there was, see [1] for some discussion on that. In any case, now that we've removed the "oid" parameter in a preceding commit we can be sure that this code is redundant, so let's remove it. 1. http://lore.kernel.org/git/871r801yp6.fsf@evledraar.gmail.com Signed-off-by: Ævar Arnfjörð Bjarmason --- refs/files-backend.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 8bbabc140b2..f83aa1063f4 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -883,7 +883,6 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, struct strbuf ref_file = STRBUF_INIT; struct ref_lock *lock; int last_errno = 0; - int resolved; files_assert_main_repository(refs, "lock_ref_oid_basic"); assert(err); @@ -891,30 +890,9 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, CALLOC_ARRAY(lock, 1); files_ref_path(refs, &ref_file, refname); - resolved = !!refs_resolve_ref_unsafe(&refs->base, refname, - RESOLVE_REF_NO_RECURSE, - &lock->old_oid, type); - if (!resolved && errno == EISDIR) { - /* - * we are trying to lock foo but we used to - * have foo/bar which now does not exist; - * it is normal for the empty directory 'foo' - * to remain. - */ - if (remove_empty_directories(&ref_file)) { - last_errno = errno; - if (!refs_verify_refname_available( - &refs->base, - refname, NULL, NULL, err)) - strbuf_addf(err, "there are still refs under '%s'", - refname); - goto error_return; - } - resolved = !!refs_resolve_ref_unsafe(&refs->base, refname, - RESOLVE_REF_NO_RECURSE, - &lock->old_oid, type); - } - if (!resolved) { + if (!refs_resolve_ref_unsafe(&refs->base, refname, + RESOLVE_REF_NO_RECURSE, + &lock->old_oid, type)) { last_errno = errno; if (last_errno != ENOTDIR || !refs_verify_refname_available(&refs->base, refname, From patchwork Tue Jul 20 10:24:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12387999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 066C2C07E95 for ; Tue, 20 Jul 2021 10:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E300E6101E for ; Tue, 20 Jul 2021 10:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237086AbhGTJvB (ORCPT ); Tue, 20 Jul 2021 05:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237679AbhGTJqS (ORCPT ); Tue, 20 Jul 2021 05:46:18 -0400 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 5EE25C0612FC for ; Tue, 20 Jul 2021 03:24:34 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id a23-20020a05600c2257b0290236ec98bebaso1727291wmm.1 for ; Tue, 20 Jul 2021 03:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yCvY7+A3Pc8OMQ+NkfKOGjSFEZyvhHn+BLOkIHSuvE4=; b=sWm5kfvrCJSU9NN8qSFWT9sl3A9RkNc3dSmEdfjYQw1TJEoKmvCnEyPKvi6i0mxYv/ UMPuHBLlOUwUCAQnABsmQbi4Ooklg7+PlHAE6mw0VfKLVCLj8ieA6cIi5ZsJ26og3s3h Hr6ZO1l0074QL5OVp91NSU8wDGz/KFeJR5q3uk2kdcSTYOGy4j0qzeaeP3Mwq7F3bg4f Zpe4AC8Rds+2ZwvW0cPlEkF1msmFEPz1JOE4lRzoC7ItlgisJU6Ga4jGYox44pStCr/9 mOyrz51a0BbuJhy0eGOycBbeghPQDPyQ72riGZ/x5yndyIPTb130O6PyWjle0CrKh3Tc qE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yCvY7+A3Pc8OMQ+NkfKOGjSFEZyvhHn+BLOkIHSuvE4=; b=Rp7d85aK3PZL7TGWW+UcSj/qpTc+yIz7VnIs5ws0MbKa/MBifGrjRbQk4OtrpCaA4c +IxEN9Z22d37Vgt7cVtLyxmtJkEY1zjnVKCsDf/C+DkIbDOQrM3elq+hBi9dy7jVlb+U BXG1SmTG+WpWdMCOUt81y+ftSwOjpZ0dr59byGbQp/PF9ScKcLdBZC/tetjgecGJL9Tv PTz29aFF1hdnl0i9YW1NW7E1+yo9CiNtb9HYaQFf9CkdgZ6QAVgVY/apzst2uYu90xrn MuAIq06yxj/LNNcXcH2eIiKK9C6ratMWodvyzYAaQFNHpF5/Kdg6kR97eZJv2VE+WuEJ de9A== X-Gm-Message-State: AOAM5316eEEqq/dJxsqaOuNqhmf3d2eCw7f7F6CG2U+eRD+6D8HtqbR1 n6FUUAMpqLwdOZUdHZ2GbZhWoxAjA191WQ== X-Google-Smtp-Source: ABdhPJw/YgncUZ4ElBlYwTP/ZnX37HS8IVZZLSVD5GnUMvjOwD5FJhH5Raa2DpmK8XXEDCICi5moPA== X-Received: by 2002:a7b:cb53:: with SMTP id v19mr29786013wmj.127.1626776672762; Tue, 20 Jul 2021 03:24:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l23sm9684536wme.22.2021.07.20.03.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 03:24:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Han-Wen Nienhuys , Michael Haggerty , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v3 12/12] refs/files: remove unused "errno != ENOTDIR" condition Date: Tue, 20 Jul 2021 12:24:17 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.ge7a9d58bfcf In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As a follow-up to the preceding commit where we removed the adjacent "errno == EISDIR" condition in the same function, remove the "last_errno != ENOTDIR" condition here. It's not possible for us to hit this condition added in 5b2d8d6f218 (lock_ref_sha1_basic(): improve diagnostics for ref D/F conflicts, 2015-05-11). Since a1c1d8170db (refs_resolve_ref_unsafe: handle d/f conflicts for writes, 2017-10-06) we've explicitly caught these in refs_resolve_ref_unsafe() before returning NULL: if (errno != ENOENT && errno != EISDIR && errno != ENOTDIR) return NULL; We'd then always return the refname from refs_resolve_ref_unsafe() even if we were in a broken state as explained in the preceding commit. The elided context here is a call to refs_resolve_ref_unsafe(). Signed-off-by: Ævar Arnfjörð Bjarmason --- 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 f83aa1063f4..443182da102 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -894,8 +894,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, RESOLVE_REF_NO_RECURSE, &lock->old_oid, type)) { last_errno = errno; - if (last_errno != ENOTDIR || - !refs_verify_refname_available(&refs->base, refname, + if (!refs_verify_refname_available(&refs->base, refname, NULL, NULL, err)) strbuf_addf(err, "unable to resolve reference '%s': %s", refname, strerror(last_errno));