From patchwork Fri Jul 16 14:12:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382223 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 946DEC636CA for ; Fri, 16 Jul 2021 14:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 777D9613F8 for ; Fri, 16 Jul 2021 14:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240339AbhGPOQP (ORCPT ); Fri, 16 Jul 2021 10:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240309AbhGPOQO (ORCPT ); Fri, 16 Jul 2021 10:16:14 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6527C061760 for ; Fri, 16 Jul 2021 07:13:18 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id a13so12243716wrf.10 for ; Fri, 16 Jul 2021 07:13:18 -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=NJfrIJsyA3bFsHjP3U0w6NL9COiXZQDKDriUDYudU5U=; b=ksGXCGY5FjTCeBwpQsqYXebuGfkMaljLWQwHf+UnHUFChcY7agZMoOsNp7X8tFOi+e sGgAI1Xt1UoJHhSElo/jWEq9w5HfE/Y944bVksjEduc4G15XFvFERqVdRJJZLfMqMPX7 m8O+C3WOFLGbtzlZp/fIpE5BO/s/cUn22hbx2+Qseg+uCYqyDZsTaGsG4A+Hn1A/5wEU rKa/2fNheVytcrlpN87eyMAWdg3AWsqHzpCZtO1bhE1VYFeCjs9sHYPWvig+jwMJIcoI kpkMUzybZZwwMMrLMLkgocJEAfGXaMo/XYmu8bewFVSfKB2twhMFkY291YnCGtvaHOuJ KaQg== 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=NJfrIJsyA3bFsHjP3U0w6NL9COiXZQDKDriUDYudU5U=; b=L0ijveIMuPnyiuYPsNSbHSibCxq1I1qiNJEBiCzHGxXQ6IYoRDCJMHUFzg0FSW+DXz tig9UOqeDZUAhlOtian8su2TEv7Fn8+WP9JaeTg/cpb0rjU7ue3bzZ4u6Rd3ruWXlhjg GOCtHQHqcf19OvCtgr/wuLiABGGrM3U3KgRt2chUuV4GzNEh3O6D6ct91uMtTDjxFKT6 F6MGZAv6UNPhNaAHYayoqIl+YnJtzwNBVUi1BNQan+SJynRbmTeZO6GALffm21wRTVF0 4V3BOKPSqNgIifH+y09a6Qb1SIKGkcBq+YceIyUX2Hw5ZRiJNr0EUP9PtvJ2BHUGheiZ 4N6g== X-Gm-Message-State: AOAM531fPRINXiABXPjm5W2UmjA/5kdYDEPGGw9CuMkrS+DKiIer3lDZ THUBBuO+oJ1sqyORzjDY2xeBOhrkY4U= X-Google-Smtp-Source: ABdhPJxynrAiMf8Jl4pjwupyxi6y7KIORpuHNvEvmGIFEZA7ZAdoEFyth/o3moqLiS+r+2KtAYgiFA== X-Received: by 2002:a05:6000:1c4:: with SMTP id t4mr12759601wrx.181.1626444797079; Fri, 16 Jul 2021 07:13:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:16 -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 v2 01/11] refs/packet: add missing BUG() invocations to reflog callbacks Date: Fri, 16 Jul 2021 16:12:57 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 dfecdbc1db6..53d1ec27b60 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 Fri Jul 16 14:12:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382225 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 0875BC07E95 for ; Fri, 16 Jul 2021 14:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5D59613FA for ; Fri, 16 Jul 2021 14:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240415AbhGPOQQ (ORCPT ); Fri, 16 Jul 2021 10:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240309AbhGPOQQ (ORCPT ); Fri, 16 Jul 2021 10:16:16 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7ABC061762 for ; Fri, 16 Jul 2021 07:13:19 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so8302998wms.1 for ; Fri, 16 Jul 2021 07:13:19 -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=5OKJ5/z6mzkpyFLr8dQSMW7FZKBlkXYkL9ZO9LFWfbs=; b=squ92wztvLUuvu2EQLG3As6VayTLCXis2+co7KGwjBYWBdBgqAgh5edEYN5eEg/t3m TDsZzcj0TympbGkRRZS6CVzpJevGexKDTUQAiZGg+/xA6CWF1OL9qQIBHEPTZRssdab5 5L/VKz+nhpu+rtR0adIYIbxgBfCrrVPGqV+g7+Z3bb2hK+4v8NHh7bPgNhoALtYNxpeJ IXlMC31yEBBM4EHD8B059J7iRUiyEWMHGjtZeKQxfjtxCb6NO0DjbN2MiHmRsqmKF3mL 13uSo/CHlBbduVn4PivYXF9J93LlUiAGzu2SW+4jtFoqxG/vBpXKESlH1HF9j+WGJgVD RA2A== 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=5OKJ5/z6mzkpyFLr8dQSMW7FZKBlkXYkL9ZO9LFWfbs=; b=PAnp1dT+gcx0ipyauF1fkwhg9qNvzDCRhHrn4GdMzNAhRc2rjbddfkjZ8RKt32HypS vkYHKTURAuqbRuYkVF0wKU3ZTlD321GFM31d6at3O2fIo6E91YT3tHErfB8GByTiOILQ 8lq0+FqQSB5tSM4XBfw5TS1hPpzZZETnDZ+2sSQe/9bjjwVx4Qjpr5O1EPdrbu5xCcjv R1uSNA5hgGbD3IdOzKSCXKwOgUtvxtoJ0ufpdYN6ugjD3omBFuY8VyJvaMwbvrP9GyVT wXWhWXqZGiSm+wfCm1zxjuWoVD10Uv42F80LE50h3p0po1ii+0GS+du3OvlacjWYPR3e wf6Q== X-Gm-Message-State: AOAM533PF+uHdBdwKCAITo7O4cW52nmd5bOmqRbv1dWbiruUZydVzAvY 7OKcGqoSQYJ7/YdSK+f9CaMblfhfOQ5ejQ== X-Google-Smtp-Source: ABdhPJyWS57DupglUZm5gY4PRnReePlfyZ/EEzTkkQJ543AuuMG0sGUE4/CXEoq5xNea4ZBKRv1zcA== X-Received: by 2002:a1c:f016:: with SMTP id a22mr11070892wmb.65.1626444798073; Fri, 16 Jul 2021 07:13:18 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:17 -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 v2 02/11] refs/files: remove unused REF_DELETING in lock_ref_oid_basic() Date: Fri, 16 Jul 2021 16:12:58 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 REF_DELETING, the last such caller went away in 8df4e511387 (struct ref_update: move "have_old" into "flags", 2015-02-17). This is the start of even more removal of unused code in and around this function. 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 Fri Jul 16 14:12:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382227 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 E889BC07E95 for ; Fri, 16 Jul 2021 14:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD270613E8 for ; Fri, 16 Jul 2021 14:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240442AbhGPOQT (ORCPT ); Fri, 16 Jul 2021 10:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240345AbhGPOQQ (ORCPT ); Fri, 16 Jul 2021 10:16:16 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAE30C06175F for ; Fri, 16 Jul 2021 07:13:20 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id f17so12286569wrt.6 for ; Fri, 16 Jul 2021 07:13:20 -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=CFcUnjPDZ7o3ewS/Gobz4606x19jZJaXfnETmgvRaPs=; b=smJTMHDMbKy43e36hXz0dkh6M4LtNUsLeWBUAQ5Js44JzHXT+o8xa4PUK0AORUcsuG /m8KCAowFtLLA1Tx4APbIkL35ujltHrMJF+ifR+DMDz0U0JgP1dbi/8jbnNqXs1rcnD6 soucPuLHRgIIq+WcvWrRtCWu/590RelB2iBrwF0R9p3GhiYt1JvtbuitnETgKFPWBT6b VsB/AeshkdYP8xrjW4+gRIzDs31Knl54HZRhucsTU2j4st97SGuyaRhjjMs9LseUAQRi sLB4vSr4xyNYt3Jh0v1689tu9OjRlIypgln9b5/bRv4QopJLqc+yRF8Ch3pDO+Ip8J+a 9pKA== 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=CFcUnjPDZ7o3ewS/Gobz4606x19jZJaXfnETmgvRaPs=; b=JlHdN+q/DN5t4vNE/FYkL55oG0YU4/OCu56MRdC//6FLoy7cF7kHTarGknbT+/3zcO hZhUxnD7UnRo6s+HA++YyFm3XilUrM6pWMArCA7R48qBMuzbcOF7W/F/zy4xB4JxDlCW c4vKZhLAKeT0oYaozxDiVCUNGNUE0qVEI5VTvvcG/nq/BwsdrdSxeT5yyNHmM8WEC3ZD qsxyihmc4Ony+B3FVTRqoHR/6s1hCdI44K66wjFxQzHi2j1pTrCPYFok4IvKg6e+PLcR lkxByqeawNMxrBdYem+8uhS3mKwrFd5SD1WjckDtdOBtE6q0XziFrP5mjDWuNEaU60di pOPA== X-Gm-Message-State: AOAM533h65cuqNX9TUBxnny9t4OJj+lu6O7Vymhwc2MnDAOM/wMqolds yAXyXasIMhpz1WvQfFPb5dsaFnGmjGIBGA== X-Google-Smtp-Source: ABdhPJwazC3j7fFCCQYFF2x54ymzLsjelA/5WJFDzXO9Q0VBCveuKpTdN7To3Ggnw/wgUzh0+u+qwQ== X-Received: by 2002:a5d:5142:: with SMTP id u2mr12354414wrt.314.1626444799124; Fri, 16 Jul 2021 07:13:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:18 -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 v2 03/11] refs/files: remove unused "extras/skip" in lock_ref_oid_basic() Date: Fri, 16 Jul 2021 16:12:59 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 Fri Jul 16 14:13:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382229 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 16ECBC636CA for ; Fri, 16 Jul 2021 14:13:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF53F613EB for ; Fri, 16 Jul 2021 14:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240444AbhGPOQU (ORCPT ); Fri, 16 Jul 2021 10:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240424AbhGPOQR (ORCPT ); Fri, 16 Jul 2021 10:16:17 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A279C061760 for ; Fri, 16 Jul 2021 07:13:21 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id g16so12291109wrw.5 for ; Fri, 16 Jul 2021 07:13:21 -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=HTYiFHLwxoA2G6tuYvUmIwltasJol6cFbm5zGgdtlDM=; b=RF4SUtUNeEf6+VvZsq7kwxRqVmI7mcDOZ9H5i/f+8EMs31DtH7M6Wb3kTwBwbYP3dZ nGlconKGfMjwsEY2Qe32qt/dEjYSPfRP/scxuKGsLsp32IQRQ7yVyMpmSvjL/0yaTb6S vx+2e20NC9G64qd+QRv6E+JKM9DfH7WwBNeKPKHddKqRPu1b7Pc7DEpimkE127s9aFBC ps7laAO8OGND3VVul2NGIYftjdwIfV6zNitGVACOLJ1FgaxKoyEUbR5z94+m4HiR8YLB 3QX6pPpBoco1zgP9f0LX4pFJFV8ejfcjaWPKSx83gOPJILfZuft9ODMB4RZY79mQ322m 1GTw== 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=HTYiFHLwxoA2G6tuYvUmIwltasJol6cFbm5zGgdtlDM=; b=mtKDwnactbzue4nv6yxnUUVRSp5nfUBEtz4pZ8WMQ3DkDozh331CbWZjWfGVDjaKWC b6SYUriVJGm3YGzlIf164W/RRQEF9Bu8D8xW1I9cUPACHtdU0f1K1So9BAcrTMOGOk+K FdZT4T9j9MpUfYbP68Vq7xR3lJrDZFUBJ55hwpiTpucKz3W09JrUTMlveBUn/TF1RTVn fAgk3hvYmOiGmY1AYmY7iKO2L/WH1PZXrJWAanHx8G3g4Y0WEDx+l68HmCZdd7ZixvXq OuwDV3NyjzHKjFKXztn++6uuaaU3sLgHVJWjGZHXER/9ScBbeDDPSNp59Gzq2xExaMCw RsZA== X-Gm-Message-State: AOAM5337f7FPlhVSzmr4vbDSC+6m023XvXOiMbjYxu9Lnucv3hVgl27v Vw6LLbYlMAH6vLOiaOVpPSn6pYJLgD9lnQ== X-Google-Smtp-Source: ABdhPJxJCNoqQAUo7iF29SPd48CnGHLKEenvi13LeFuxymoWzLRax655ov6kPF7h2wLipko81Xjxww== X-Received: by 2002:a5d:6501:: with SMTP id x1mr12413158wru.169.1626444799865; Fri, 16 Jul 2021 07:13:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:19 -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 v2 04/11] refs/files: remove unused "skip" in lock_raw_ref() too Date: Fri, 16 Jul 2021 16:13:00 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 Fri Jul 16 14:13:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382231 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 AB5A3C12002 for ; Fri, 16 Jul 2021 14:13:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92B3E613E8 for ; Fri, 16 Jul 2021 14:13:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240470AbhGPOQW (ORCPT ); Fri, 16 Jul 2021 10:16:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240428AbhGPOQS (ORCPT ); Fri, 16 Jul 2021 10:16:18 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305FAC06175F for ; Fri, 16 Jul 2021 07:13:22 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u1so12324950wrs.1 for ; Fri, 16 Jul 2021 07:13:22 -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=3o5d+dcP1XSl9ZdYR/rF9iU6xQoZcztCXTEGCd2oFiA=; b=lDQoSj/vf+WZy+ijBq5uBcBJ1oc8ykPecQoJDuO4vS/f3A9VLvuSnZneKB49sNIWgf 6OZOmDEnU7yb57hiPOv7WXXUy35vzXT+5W7bWHEnsNoOdr9njNftKpu7alVwub4MqK/X +ZBY8szeutU4dnggKd0RMrF6pfwDtyeT//r9JA8PQ27IRDQFLtbbTmdd5iyO8NxgrD+/ 9EFRHAUCyM4er7RayffdI4/ecUUbOpcuP6cuFoPaFXApkMZe7028qxtlrMDYxZoFs9Om U7xZbD2/aYXTT95Gsrn+Y3M9TYA2jLwzfVaCV/swm8q1tmrAgU8PGLFUiEqukrJn89Zp fu2A== 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=3o5d+dcP1XSl9ZdYR/rF9iU6xQoZcztCXTEGCd2oFiA=; b=GEw+M++GoQvzrmFUz4JXkKb1zi8FpCS3JjxFZ6BivOPiutqJTtZWsyap4e8K9UGGpV lZvRyT14lz3XlS8cyWWWbAg28yLer0VvpNO/KE7KSxI0dlDhmrdJBWWb/qKdTQYCS4yd vTULeh6wp6jScLqm7mZZCMsMLVL8b/SDjKoLp8iqXNK7MtqQu28YIUu6SHaRXcQzIEdU l9YBOvL8zPBLd3xflWB7ExP0Aedl+kjIvPr7TqBP33sEmJ1YGG7ntGYLZSqic86nVkzs rHmTw96WlcNNuyVknB9sI4wHec0N7DdK5QdcW578FX5ust7VCSHV/6XrUEJv+pdlhsf9 TW6Q== X-Gm-Message-State: AOAM5307gL616sre9v1pwOMZ/SBgfNZm3yTvLbrkD6AGAs58xDEoR6o2 pyPKovWaZ0f5vPkIj3CitmNBW+mH7NAhqQ== X-Google-Smtp-Source: ABdhPJyqgdUoBZZm02XmeR+M4LcWy4qC3IMTDLJ8QnO+GRvBrRAj+MCoBviGbGSvvN7gMhLMhAR8wg== X-Received: by 2002:a5d:4fc6:: with SMTP id h6mr12782410wrw.112.1626444800596; Fri, 16 Jul 2021 07:13:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:20 -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 v2 05/11] refs/debug: re-indent argument list for "prepare" Date: Fri, 16 Jul 2021 16:13:01 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 Fri Jul 16 14:13:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12382233 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 02EE1C07E95 for ; Fri, 16 Jul 2021 14:13:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0D61613EB for ; Fri, 16 Jul 2021 14:13:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240198AbhGPOQX (ORCPT ); Fri, 16 Jul 2021 10:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240443AbhGPOQT (ORCPT ); Fri, 16 Jul 2021 10:16:19 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F24C061762 for ; Fri, 16 Jul 2021 07:13:23 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id f8-20020a1c1f080000b029022d4c6cfc37so6984101wmf.5 for ; Fri, 16 Jul 2021 07:13:23 -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=Eshe/9n5XyR/ztvffNnilQjb6AsPQ34i3bNCQVmfiR0=; b=qOzc6GXYsBluEaUFiZ3tGcJSkApEXkcodaVo48sgO3z3pGMTKPedXncVcjuXRI8Z/Q viR5hRUeIg43G/areT5VtA+Sw8XTCJfxIQn5gmczUbH/yuGyX/rtcttD+4AU4ZIWhcbu 4OTkNJDyADR62gORQ1QWnEsSEifvp3mki83vboUWYrV/f2zxiRK53weM8za5FX/L/kpi EDmzlHgn36VPdWc3WAiR25HSlEv65SepmE7J0eUSM5BBAP9XsHqfNr24w2B5IoE9WLdU N9lG2nt51o1eGg25Kegv5uP16h1cusRyzIcbzNrE+4o5J7RuN16IWlKW6aqBFgPFTugP rY0Q== 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=Eshe/9n5XyR/ztvffNnilQjb6AsPQ34i3bNCQVmfiR0=; b=X5FrvY+WcTS1yaxlnFNC183lZsgBxq/1kxdOHYinC03tDmmjuM89jgzUmsoODJx8OF 1OOSXtMbNxior4zpI9pj2HdHXPqbrAQgeA42/yfmU5bpE+cy9/FFyHrVNJM8U6XqXcsx 3v0q8vgroZ+m/mG8bCURZSUt8WSWKzny6Eor1b7OxTVuRzE7TZOdwvj6DhL7xWZu7TR8 SzppqBo1DXhpRmJH23U7XrkeekjXziNB5kDgvN47VCM+snF06bUcBWZPyoanbnVPmJna W7oHPl4pMB+mxJuzUBlbfDI5KNJ01MKML3+6itCNnsHUxbCj0yIybDQQlLR/l60nQNxl KVdQ== X-Gm-Message-State: AOAM531suU4uN7/wuxZ92KmsQhBjYnH/ah6FoOgbBknSofOYy6J8XMOh Am5Ste5P4Qx6PmPJjENgJYSxynyJPBUCGg== X-Google-Smtp-Source: ABdhPJy1rL9fjYrLpOVNjMqpzYLkqPQ9By/e8ZmAsqAqVZ+xwEZg6k0XmXge5e+iYY62hYtnfiSdiQ== X-Received: by 2002:a05:600c:3799:: with SMTP id o25mr16879582wmr.63.1626444801532; Fri, 16 Jul 2021 07:13:21 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:20 -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 v2 06/11] refs API: pass the "lock OID" to reflog "prepare" Date: Fri, 16 Jul 2021 16:13:02 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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, but as part of removing the passing of the OID to other functions further on I'm splitting up these concerns. 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 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 | 2 +- 4 files changed, 10 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..ec9c70d79cc 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3098,7 +3098,7 @@ static int files_reflog_expire(struct ref_store *ref_store, } } - (*prepare_fn)(refname, oid, cb.policy_cb); + (*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 Fri Jul 16 14:13:03 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: 12382235 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 3D5D5C12002 for ; Fri, 16 Jul 2021 14:13:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 271E0613E8 for ; Fri, 16 Jul 2021 14:13:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240489AbhGPOQZ (ORCPT ); Fri, 16 Jul 2021 10:16:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240345AbhGPOQU (ORCPT ); Fri, 16 Jul 2021 10:16:20 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 060DCC061765 for ; Fri, 16 Jul 2021 07:13:24 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id f8-20020a1c1f080000b029022d4c6cfc37so6984125wmf.5 for ; Fri, 16 Jul 2021 07:13:23 -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=W4Xp1UVRShn6koTEGWpMy5JtQaqU8qxbSaIq2rqI3Xc=; b=je92ROuT3Ftfa4NFfEZo/x5zm11MXcH5lZwOD01bPUlwkmekJnkHEJ53t1zhpO8wZF RYhfPGDvBj1OVGvQoFOhSyRw9GVS+uMVcBmmZfgNX4cguE33i8zSBGviBR2LXhfDOxHH Bl/vTnBq6h+4xkEp235gY4UWUBrARS9v0mSh46svI++60/MIVslkbloWPh66sgmFbjY7 zqv5KSAOIc/cGDnyP6YlvV8oASKhPcEgsUQqBSchtT/X8MAfX5knNuioK1lJh5zAK6ph r7SZgz2p54+IGtsbdRwDAqSINo1t5Ur0kta3FinA+KbuiNQaMrMHVnvem9nLpf+kL4Gf 0DRQ== 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=W4Xp1UVRShn6koTEGWpMy5JtQaqU8qxbSaIq2rqI3Xc=; b=OlLj6kapfvlje1brLwOjIJqcLW5eRXWafAlvvlwBHb6Y5lgdWZya87WWM/Dn5L7oWm +sERpvArd5B6E/lsN6WW7pN31nZOg9PyV7NenG+zuY3+OCByJx0H81BmgMi8FvzxG+cz fGEBDAfVmmZlrkV0nZnh/sSvu6FeoqTGtdWpinCCtj30aILc21VVU8334f+UJiL89vO3 TgvgRdOS8jM9wDD3BCYeNNpF9jZpb5q6GZYDG2zG0NFZTJ5JGlZILshlfdonY6yNdPZj 5xJzkfrs2YyRzb55Z549dTVqKxeKnIntC6Nwdn7/tSAPWHzbuisglKAey+Z9S6J0Ri5r zqlw== X-Gm-Message-State: AOAM530W0AAMbB7yZ7ycPK4xTQ003utrZnjIy2TOubv5/GXPDSA233MN RhEp5gjXeqk7tBbntvv/1R2dEVBgMNXbwQ== X-Google-Smtp-Source: ABdhPJwnN1LVaUWBeFB9VdJgOVmrg35MfW91QOd4bg6fWf45cX2UWV98GyS5cfSov7wxSAQn4XN/2w== X-Received: by 2002:a1c:38c7:: with SMTP id f190mr17120325wma.29.1626444802369; Fri, 16 Jul 2021 07:13:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13:21 -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 v2 07/11] refs: make repo_dwim_log() accept a NULL oid Date: Fri, 16 Jul 2021 16:13:03 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 8c9490235ea..5e2330bf78e 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 Fri Jul 16 14:13:04 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: 12382237 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 182ACC636CB for ; Fri, 16 Jul 2021 14:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 036BD613F7 for ; Fri, 16 Jul 2021 14:13:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240500AbhGPOQ0 (ORCPT ); Fri, 16 Jul 2021 10:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240452AbhGPOQU (ORCPT ); Fri, 16 Jul 2021 10:16:20 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0639FC06175F for ; Fri, 16 Jul 2021 07:13:25 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id a23-20020a05600c2257b0290236ec98bebaso3505915wmm.1 for ; Fri, 16 Jul 2021 07:13: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=vS8cpxYaUJiKejehV8UbxlfqqpZAb1uy3HabawGtWGs=; b=O4f6mUElDYRERyEYVluXTPoMCJ3e2kRz/qVy6JwZQ2zS9zsQiqQCaGrTp7npJbc536 zQTVPiyHJ5LKhixOqhhaaGN/8hIN2CNUB2mIabhGX3cTG3OXUvNnhJnwE/LEwSTUsrky FQIxEMf2U+rp+uNhaCU9SVWx0qiJrgZawh/7/ZaL2+x+dQodPgo2aChxSHESwBE93M/c UqosOQ4Yknja874iwI1dLCcq9UxTImtGvcT1LI6a/DjbkrtoowA2zkWPQwqTLNBpW4nV UfaLeTTez8SXr6lF6Av81qYuzj9cxAgy4uLj4SlD4PXqq166zLM5D/2Yr/WdOLU4KWit Dxxw== 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=vS8cpxYaUJiKejehV8UbxlfqqpZAb1uy3HabawGtWGs=; b=bNa3pvrSlRLDRa+dVNcUHAoRcjRfTTMMaCZR3KIG0EPooYVD02nG1z0hMH4OgjZGyy 8vEQ3Cvi8Atfq17oES0ph9L+OgH02bQMTw8Uwnbdpm3dxVcqdEnB17V3PEpmGBv6uUf5 JI1nzrQ1U+a/zlJTpfAvUdkaqizdS8VjeFCiWum9WFmv080LezavwXQnsDjjOo42FXs0 FtTx9cpVCopNQJTQlwOs+V4poxeamiw08XQHML2kLHTCiUn/roIdlcRqRAUumCHXHuPt 1BPuvakjgqCP7HjKTTgm78myVCTZlAlg3hUP22PlPtvZ8PWCWMPbjEFxyFZh8WxfZ2tC fbOg== X-Gm-Message-State: AOAM530zGrVvW5HyFFCCCjIvNyX3Trt7MelR81qxCUFrjyCOKCmhtYq1 NVm1VxdFNUB+2IT20NxikJsdh+r9ynLnBQ== X-Google-Smtp-Source: ABdhPJyVFtHSy+0MXJRAM4q4iFHvue7e67xyNoTkuhMGJ9/ezOLiROB2yq0ndxh/iKXCAMadEupn5A== X-Received: by 2002:a1c:7407:: with SMTP id p7mr10504502wmc.111.1626444803273; Fri, 16 Jul 2021 07:13:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13: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 v2 08/11] refs/files: add a comment about refs_reflog_exists() call Date: Fri, 16 Jul 2021 16:13:04 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/refs/files-backend.c b/refs/files-backend.c index ec9c70d79cc..f73637fa087 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3068,6 +3068,17 @@ 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 deleted. This race happens because there's no + * such thing as a lock on the reflog, instead we always lock + * the "loose ref" (even if packet) above with + * lock_ref_oid_basic(). + * + * If race happens we've got nothing more to do, we were asked + * to delete the reflog, and it's not there anymore. Great! + */ if (!refs_reflog_exists(ref_store, refname)) { unlock_ref(lock); return 0; From patchwork Fri Jul 16 14:13:05 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: 12382239 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 95635C636CA for ; Fri, 16 Jul 2021 14:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 876A7613E8 for ; Fri, 16 Jul 2021 14:13:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240316AbhGPOQ1 (ORCPT ); Fri, 16 Jul 2021 10:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240460AbhGPOQV (ORCPT ); Fri, 16 Jul 2021 10:16:21 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D22A7C061764 for ; Fri, 16 Jul 2021 07:13:25 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d12so12229087wre.13 for ; Fri, 16 Jul 2021 07:13: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=+ZenKHIZoNm9ef3GfmGRxVWQMfhVZAff6Jexs/sxezc=; b=jTle2sDN0iGcn6JYj5UpqMvxLwLBdS7l6VxW4LJsEvMJlF3b9e4PVQQAxwdQ7uesRr /IZzeLYI5PSfPyNKGOVz1QTNb5Af8eTlb4WZtOTCPBBVg21eWLxzb/X1jAFxP/tkBhjx y0vOpaOOUzhTsLiGRZrHht8afSKPUoTk3DpvuE2j6UwfIygCX0O7s+8VP955OprPxjke 6017yDBUit5JlYvy48RPMCyRsFQ/haDqVssYJWqybCgllu7VTcO9/1VJgVg/3cy1iBOk FDum9jkdU5YHjlTxev1IR7wrFx+RNlQ8o8AJ08Kqus7SGKG/jZkrcjpwM0YuzU6X+Whi 51IA== 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=+ZenKHIZoNm9ef3GfmGRxVWQMfhVZAff6Jexs/sxezc=; b=cvCe68rin/Que67jzR5aXMCdd5MXKROI8Q/2xtjpqqeFOMPAWpqLfaU1a0MyIvVPNZ nsemU4aJQWQ52yQDpjuGiP0T2OaOGZMUgV02v0aMyBCFYylmozijJ+aFfq6MxnAV2O4l 820pmsoF9s9Apm5VShaZb47N0bZHjafm5cb9Sk4MAcJLck9GwVcrhcgaTexvsauIqbCU VXrA8xe2LEAitr+j94HzP2L0pPbMHtY7th12qGE70C+Ky5mLGrGDhYOquVvZ9cTSQacI DosFFaAjdFmPAy35QTQ4O0IKDUJzXbPynyeKqXwyXB+zhRCtTDpxS19nCFF5vv+6qduC Lk3A== X-Gm-Message-State: AOAM533pkr9OYhErzkgzyhO96jUquDell7sMiyT+zuL86xunzeCupPMo CUWfyh8xe4k2K6auYPYaMrvrLxeGBZt3DQ== X-Google-Smtp-Source: ABdhPJzm36ktB62bZCDFLa0ixxqdOnw5Bo2fR8G35uPeF0vNelIXeSym8srOcH3SFvZ4TfPcOIGPQA== X-Received: by 2002:a5d:5609:: with SMTP id l9mr12768366wrv.123.1626444804098; Fri, 16 Jul 2021 07:13:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13: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 v2 09/11] reflog expire: don't lock reflogs using previously seen OID Date: Fri, 16 Jul 2021 16:13:05 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 we looked as input to lookup_commit_reference_gently(), assured that it's equal to the OID we got from dwim_log(). What do I mean with "mostly" above? 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. This 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 his[2], but that 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 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 a "but expected" error. 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. 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 | 2 +- 2 files changed, 7 insertions(+), 8 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 f73637fa087..cb8c64cffb5 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) { From patchwork Fri Jul 16 14:13: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: 12382241 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 99990C07E95 for ; Fri, 16 Jul 2021 14:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FF44613EB for ; Fri, 16 Jul 2021 14:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240476AbhGPOQd (ORCPT ); Fri, 16 Jul 2021 10:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240478AbhGPOQX (ORCPT ); Fri, 16 Jul 2021 10:16:23 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6078C061767 for ; Fri, 16 Jul 2021 07:13:26 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id f10-20020a05600c4e8ab029023e8d74d693so916208wmq.3 for ; Fri, 16 Jul 2021 07:13: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=mBqs5NI95VVCSW8XTC1DnIF5sVypYowl2/e4u47tQAU=; b=FLOmI66e/ZcD5hBfWutnJToyS/wTFeOpu2eCbA+PVS5BXtivQuEmqoffF1y6HN/Zzq 3t1bqX8ZC33p96fl6Ep9wdv9GClITH9WoZsyI3BVzJHoDcKOOumh7masGPfHsBSBaAFA JrV63oLDhjJylLu1EXRxphre0BToVqMssuWdWjDHDp8u2P8AgYosEvRxhkGjTzTxW4zN yl2q7H0qCDopJBAsUrrvHC5Ud3y2n9O8MmPd+2RSe5EyOTuICel1WKqu0tRoctm0h5oh v40BaeAicUuDnwFHmSnG/4DZXIFzvn+h77yAxpYtuhZP0gHpehJiL6Il0y146TG9aiIH FN2Q== 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=mBqs5NI95VVCSW8XTC1DnIF5sVypYowl2/e4u47tQAU=; b=MIEjVV6GqL1sc6pLchQ/d1/qZVTMOiNBRrqTFWELpRP+yJa9pm+iGdGDkDAlp2BYd6 28ZiZ8P7zgU3Lktw7TcgBsjSDfsDziby0yWg/7uKQY42DZ7sngYfODASSZdxbxfTO546 n/IhB2e7PNYYRWD6j25bXDI1Jyn0AScRn6M4Z2EfdoW0pYCoScVMDNpvH+yrTlRQSA11 VRi5NWqFyIqDubtpyqh5srGO21ozZQkkJ1gFLUKEby2GsY/n4Qe9s6JGraj/qex1/TLA /6Qyko6+cIWsrGj1BLSdP6cHJJzHDieiGW3t4/wAaJNOQRLfGi+2k0rTyRbvigr1aoVo WBfQ== X-Gm-Message-State: AOAM533+bg4LIVuyRUJQWKe4QBwtJEKTmr0/ptfUq0JHlwGbTC2DFb4+ fuZivytM+Iz8Xp9J2urxx6UcHGJXA9GZ/Q== X-Google-Smtp-Source: ABdhPJwmV+1f/cO8IxrYH29yAL2zu4p5V15dvsh/PzBJLv5jKO44ueiq/p3fzrei0cOK/NWNwa0cYw== X-Received: by 2002:a05:600c:221a:: with SMTP id z26mr17161908wml.34.1626444805019; Fri, 16 Jul 2021 07:13:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13: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 v2 10/11] refs/files: remove unused "oid" in lock_ref_oid_basic() Date: Fri, 16 Jul 2021 16:13:06 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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_rew()), 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 what's now its only caller. 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 cb8c64cffb5..3e7598cc86c 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 Fri Jul 16 14:13: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: 12382243 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 7BF75C12002 for ; Fri, 16 Jul 2021 14:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66FB6613E8 for ; Fri, 16 Jul 2021 14:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240562AbhGPOQe (ORCPT ); Fri, 16 Jul 2021 10:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240459AbhGPOQY (ORCPT ); Fri, 16 Jul 2021 10:16:24 -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 A3199C0613DC for ; Fri, 16 Jul 2021 07:13:27 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id l6so5971020wmq.0 for ; Fri, 16 Jul 2021 07:13: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=cqO+qBRoNA+WC46tZBm3MxJFpnM20dKP2YQI5gBuOII=; b=SpL0UU3A7TkqKoQAmLL22pZgZK+WTT9N5hgwA2mrqgzx9Y3G+SiTDoXcF3sWPgqWxF Pc3p0vNCjj+7W0i65sbBEuhPNbzVX0zoz8JS4sa+404wn3PIiS78rqlveL+p6Z6cO9eP ziRi3FXg+H/QV7fUcOXi1ZmEbr4Zlt/5sGNQpHaNNhbnNVyFAqPpMamr7M0DYZMFhJCY viON7GGt7jQdYcwHF3qnwxVzR4m8G5ydwC/ATOkDmkQqWATS3ho6GXEYTWo2TNwhIUTM Xoprza4rLQmdazKtX0dtpqnAtnT22oyB8R0xhURS8UtBAlnJBI5pmFh8JPITv0EvyJlj 66Hg== 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=cqO+qBRoNA+WC46tZBm3MxJFpnM20dKP2YQI5gBuOII=; b=Zb1vV0jXFTSu8GwhYImUr0NT3INsIJrY0LkSFcgQlkUaJGdw/xm8yqHtJQmpWt81kL KkCznJUPnoKTzADZrX0NjOwHY0RT2j7IcTt1k08Z85c74a9N/8QNGP1TZ5LVPYET4hiM O45pOBcf2k6K0E9VOQZCifdzo44UEhvAw5jgG1bTmPzR4I75JyX3Kc45n+oVozRJo3YS u9uB8pDo7qqWh73zFlgb7aHQXSpxamGJKhTtCMy/loOv62QgQiS/7lfLOj8HEfc88Ot0 cE5VFmX5EL29dBV+Kx72LEmybS/bd5N1QUIlRHw9nIhY/388sNC+JUfzBu0jKlPKEaKj dZBg== X-Gm-Message-State: AOAM530fn4YM/W+MR1NnJi0uqbeUCcSHwv8RnP+zQMAgyO1x3qonEc7y zq3Jq0DK8HWHjkkSy1qIDIKyUbWwxx6rDQ== X-Google-Smtp-Source: ABdhPJz/FwXic6GMoNnmyO2qRBpkODFReRW0aU9vMlhm4dewQehdr4KhJeoOam9eTbAefFrNPv5Qug== X-Received: by 2002:a1c:3c42:: with SMTP id j63mr10798736wma.35.1626444806024; Fri, 16 Jul 2021 07:13:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id a9sm10101363wrv.37.2021.07.16.07.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 07:13: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 v2 11/11] refs/files: remove unused "errno == EISDIR" code Date: Fri, 16 Jul 2021 16:13:07 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.874.gfa1990a4f10 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 3e7598cc86c..bd99bc570de 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,