From patchwork Thu Sep 9 09:47:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12482819 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.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 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 71EF3C433F5 for ; Thu, 9 Sep 2021 09:47:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 51B2B611BF for ; Thu, 9 Sep 2021 09:47:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233296AbhIIJsW (ORCPT ); Thu, 9 Sep 2021 05:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233190AbhIIJsV (ORCPT ); Thu, 9 Sep 2021 05:48:21 -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 94AF4C061575 for ; Thu, 9 Sep 2021 02:47:12 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso976192wmb.2 for ; Thu, 09 Sep 2021 02:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ZkrfvFvHxoHMDOBTZSzqjARUmPAkGSl77AqRw+h74Qo=; b=AOh4t4IpFJ9s8SohFSV+55tRJLGfS40YVm7US6dPQCuq5KcDrQmXwJRCUyg7oKelgP RJY6EqCvVLF3k40wVj3QkPKPaGiFrvly5ssG8AFdcMSFfuKf5PTADLUwC3TKX1M7kRAV rtE4V9WkUAj95j0EF+qYwpQML31XF+TEvxtBeY+b79fbSdN8Tbm/tnoEzujZRpyJpVzg 88b/VM2mWIBCScVlbnwBFh/Po4mPSScqthKe+SQR3IGeFpNJQhiVETx/adoCvtXogKk/ u6FJoBdZkiS7nSDjmQikgpVCSoYXH9ja/rpkb01QRO57QZ8+B+OUdbnjOKPY9PsvZfHC ONyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ZkrfvFvHxoHMDOBTZSzqjARUmPAkGSl77AqRw+h74Qo=; b=rAo5X6q6ZIyFxSD5ZVL1dcVX5VRf9d2hIOUbz9qkvJTIxmjaXEHEwosV0MOIvvzY+I mt9ETr/Sw/OdHbm0JnAE4TZ1PxrHRv85H3h3A76WBH/DuhDg8K979Mykn6Gf8CgJRJcd InRLz/ZXxCzKeEX+FaE8XZBMxY4bnK6C6VboPrSIX94d/NeDae6jQy3WeV6U6ETrModU sSCE1mL0NDgiyCAb+A33/ha/HAUb9ag6zUXTEUysSB/DuTZklQDgdWGPZTuRXX7OFmLK 8mxEqgsOO96QCiHlWoR0tLc/rM+igdukm8uYi3daoXDv5mUL6SMj/R1Xo7TFurQEaa4O aHFg== X-Gm-Message-State: AOAM532iSF79BQj0u8FPB3QZpWbeIS0XyIRYGe8XHgmngOGObCuQFlQx POyM43WO5HRzD127nJByq2fTfCtTvSg= X-Google-Smtp-Source: ABdhPJxrpEGqIxtPCrq5htIibLi1K5hWQOpTKqm5HQ485k5lyMPk7RPM7Dt0nir0tXOOx1gqV3BVbA== X-Received: by 2002:a1c:1fc2:: with SMTP id f185mr2014640wmf.22.1631180831190; Thu, 09 Sep 2021 02:47:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g1sm1334367wrc.65.2021.09.09.02.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 02:47:10 -0700 (PDT) Message-Id: <75f39fc80f46455a93f312cce2e989711c748f8a.1631180828.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 09 Sep 2021 09:47:05 +0000 Subject: [PATCH 1/4] run-command: prettify the `RUN_COMMAND_*` flags Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The values were listed unaligned, and with powers of two spelled out in decimal. The list is easier to parse for human readers if the numbers are aligned and spelled out as powers of two (using the bit-shift operator `<<`). While at it, remove a code comment that was unclear at best, and confusing at worst. Signed-off-by: Johannes Schindelin --- run-command.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/run-command.h b/run-command.h index af1296769f9..3893193f32f 100644 --- a/run-command.h +++ b/run-command.h @@ -233,13 +233,13 @@ int run_hook_ve(const char *const *env, const char *name, va_list args); */ int run_auto_maintenance(int quiet); -#define RUN_COMMAND_NO_STDIN 1 -#define RUN_GIT_CMD 2 /*If this is to be git sub-command */ -#define RUN_COMMAND_STDOUT_TO_STDERR 4 -#define RUN_SILENT_EXEC_FAILURE 8 -#define RUN_USING_SHELL 16 -#define RUN_CLEAN_ON_EXIT 32 -#define RUN_WAIT_AFTER_CLEAN 64 +#define RUN_COMMAND_NO_STDIN (1<<0) +#define RUN_GIT_CMD (1<<1) +#define RUN_COMMAND_STDOUT_TO_STDERR (1<<2) +#define RUN_SILENT_EXEC_FAILURE (1<<3) +#define RUN_USING_SHELL (1<<4) +#define RUN_CLEAN_ON_EXIT (1<<5) +#define RUN_WAIT_AFTER_CLEAN (1<<6) /** * Convenience functions that encapsulate a sequence of From patchwork Thu Sep 9 09:47:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12482821 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.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 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 AD24EC433EF for ; Thu, 9 Sep 2021 09:47:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 93A61611BF for ; Thu, 9 Sep 2021 09:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233350AbhIIJsX (ORCPT ); Thu, 9 Sep 2021 05:48:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233190AbhIIJsW (ORCPT ); Thu, 9 Sep 2021 05:48:22 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A73F8C061575 for ; Thu, 9 Sep 2021 02:47:13 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id u19-20020a7bc053000000b002f8d045b2caso917895wmc.1 for ; Thu, 09 Sep 2021 02:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=hBpn/46jdaM8KeSDi2/L4N0QpfzUDd1UJlMYW8lw10c=; b=D8EJ+gPEZ26lqvwCpd7epW69G1AE62DqTR5l1zJEeoYt8FHW6hI8qtqOUen/bB75Nl ArQRqecU8pSsahXed5247FUBze5JxsRsC2s7LVJMAvJci2lOD+jq1MOPePMQjK0HUWGA XhiN2b1QedLYU37sMAtQwd3YWXohQ6opjoytcamUhZoVsyRouULCup9zGsbYZ+/Uckn0 IRovBgMTsM5j6hNf6qHHmlQPanFm9plHIjNuvBUf4KP45o3XUNF409R77AtJay/YgukN jwPpE7eWUcnX0Vd2u8eFBmOExYwvcfbWijTsJOF4aUMn3/hFDqAidKD+ef0y+ZXOK/9W 0eOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=hBpn/46jdaM8KeSDi2/L4N0QpfzUDd1UJlMYW8lw10c=; b=vgwiIagk4RmpvI7S1hGxJbE7f7H0IEwV1iHxitC446EXoaN2T6NfKYi2pEAiIKxlP/ Mpjndkl39FWJGwsHEYQihrb5MWOekq1aL5deSFAaMV8SYH0UHH1gnXshbPsKm7mKFH8+ BNvpkdroqmZ4Icw5qQuUDjwbfT5OXy6RYH8sBLY+/MdLr8h5AdCot0ORLMmDmE31Sdbm +38TpWPchoU9ygP53pQo0zC02JjpcG/qsgYwLTD9DHgfODqjaKOZNhay/nlLs+Cr4J7S G3bnCtlzyUFjhCxkLagRAKxTJpSO8/3Gj1rdgxeolVvsGQ+i2QNKTD2KSI4RbThMSqQz uk3w== X-Gm-Message-State: AOAM531SWIzweimhA2ZiXcHK/qFTQa+oMYt7FVtbX3SI7plDYtvmzFgd ht4K3u5zGQF/woaog9k5L6AsXv4dwR8= X-Google-Smtp-Source: ABdhPJy4u2S3agW9vbMMAkDlkVC3iezHnL+riGXjjzzCYwXy6EAyAd7OhSDrFkpXUKuhNkZ7oLXTBg== X-Received: by 2002:a7b:c197:: with SMTP id y23mr2023340wmi.135.1631180831764; Thu, 09 Sep 2021 02:47:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u2sm1032721wmj.29.2021.09.09.02.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 02:47:11 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 09 Sep 2021 09:47:06 +0000 Subject: [PATCH 2/4] run-command: offer to close the object store before running Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Especially on Windows, where files cannot be deleted if _any_ process holds an open file handle to them, it is important to close the object store (releasing all handles to all `.pack` files) before running a command that might spawn a garbage collection. This scenario is so common that we frequently see the pattern of closing the object store before running auto maintenance or another Git command. Let's make this much more convenient by teaching the `run_command()` machinery a new flag to release the object store before spawning the process. Signed-off-by: Johannes Schindelin --- run-command.c | 5 +++++ run-command.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/run-command.c b/run-command.c index f72e72cce73..e2dc6243774 100644 --- a/run-command.c +++ b/run-command.c @@ -8,6 +8,7 @@ #include "string-list.h" #include "quote.h" #include "config.h" +#include "packfile.h" void child_process_init(struct child_process *child) { @@ -740,6 +741,9 @@ fail_pipe: fflush(NULL); + if (cmd->close_object_store) + close_object_store(the_repository->objects); + #ifndef GIT_WINDOWS_NATIVE { int notify_pipe[2]; @@ -1044,6 +1048,7 @@ int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir, cmd.use_shell = opt & RUN_USING_SHELL ? 1 : 0; cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0; cmd.wait_after_clean = opt & RUN_WAIT_AFTER_CLEAN ? 1 : 0; + cmd.close_object_store = opt & RUN_CLOSE_OBJECT_STORE ? 1 : 0; cmd.dir = dir; cmd.env = env; cmd.trace2_child_class = tr2_class; diff --git a/run-command.h b/run-command.h index 3893193f32f..ad207daced7 100644 --- a/run-command.h +++ b/run-command.h @@ -134,6 +134,14 @@ struct child_process { */ unsigned use_shell:1; + /** + * Release any open file handles to the object store before running + * the command; This is necessary e.g. when the spawned process may + * want to repack because that would delete `.pack` files (and on + * Windows, you cannot delete files that are still in use). + */ + unsigned close_object_store:1; + unsigned stdout_to_stderr:1; unsigned clean_on_exit:1; unsigned wait_after_clean:1; @@ -240,6 +248,7 @@ int run_auto_maintenance(int quiet); #define RUN_USING_SHELL (1<<4) #define RUN_CLEAN_ON_EXIT (1<<5) #define RUN_WAIT_AFTER_CLEAN (1<<6) +#define RUN_CLOSE_OBJECT_STORE (1<<7) /** * Convenience functions that encapsulate a sequence of From patchwork Thu Sep 9 09:47:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12482823 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.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 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 68484C433F5 for ; Thu, 9 Sep 2021 09:47:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4ADE2611BF for ; Thu, 9 Sep 2021 09:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233376AbhIIJsY (ORCPT ); Thu, 9 Sep 2021 05:48:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233298AbhIIJsW (ORCPT ); Thu, 9 Sep 2021 05:48:22 -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 B8E1EC061757 for ; Thu, 9 Sep 2021 02:47:13 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id q26so1630364wrc.7 for ; Thu, 09 Sep 2021 02:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=No0m+FC8vTeDAjRvJpQi7E/Q85MXPRqDHqXhZ+8Yp1Q=; b=jfxLwPEQ40gUU7k/Pnm4B/hmRbBT8uclPUmN1bKK905pxaoJiLSOGUL3hREAoLmXfT Hafm4hQ2ZGCGZKNIYmueBSzHiw1T4EAetz8s1HTlvPyfYcZ7k+O7ycCmsUgcVIQTCQZd F92fuAc0kqgpQ3k3Ucjs3Bfkeqr4GmL1qF8v/dzQxHcPPiOqMgpkhlu3kQOigtBcELvw vqIMk2h3HIcVJr006iB9GeOcezXlmcEbe+N0d4bjeMplDD9fyMOaIi8hfEBQmY677TVH P2RnBxtKfKoWtN3kp2s7CvcoiTuy6GfXzZSY8s9iHN6VR7Bw6bjL6XpSiUvgtZtkPhzW 8zig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=No0m+FC8vTeDAjRvJpQi7E/Q85MXPRqDHqXhZ+8Yp1Q=; b=O1nF75Bbvuh641zvmMr91QQDot7WsUV/Q6AgwL9PO1RnDBu5jbAJSd+p22kPFuMkBt c3brcvaEeTagP+udPBVwgwZmr8mWnB79bDGuO9/5lSl5JE2S/6gXInYL1kkCpAP1/rYU BsOydrt2MXooUT4Z+gj7MHm9EWD7HwOaUkA0StDvStr/opjRRjjR9LlEa3x2OLrRqE2w 970p5dp3NZwkiYu+FCRoLwfiBcEnZxA8B32pTfVdmtJfmy7G86ANKrRsn/EBf3zD7FUS ujdb7RA40wa2cbe7DYy0u0YVr3YvYWyK/p7wNjQ7GjCBuSlechuCIqJpT7dKxZG10SQc 3sMw== X-Gm-Message-State: AOAM531H2zDDKr8tS8DkG39siEKpZ5EnarhyFuNXRUEYwIso6kGBcHXe a/wbuD8Qp3vR2hUdgZr/kxdGMLOMHC8= X-Google-Smtp-Source: ABdhPJyDHW4kKAubpjYK4bj+v0DrLlZ8aemGhm7e6Y6Ke6XjoE6uEqzOmt+c3hAPDssw8gCUGLgCQg== X-Received: by 2002:a05:6000:1563:: with SMTP id 3mr2516817wrz.139.1631180832415; Thu, 09 Sep 2021 02:47:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g1sm1292542wmk.2.2021.09.09.02.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 02:47:12 -0700 (PDT) Message-Id: <990d4ca934862845429506583b73bc2fd4ad2405.1631180828.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 09 Sep 2021 09:47:07 +0000 Subject: [PATCH 3/4] run_auto_maintenance(): implicitly close the object store Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Before spawning the auto maintenance, we need to make sure that we release all open file handles to all the `.pack` files (and MIDX files and commit-graph files and...) so that the maintenance process has the freedom to delete those files. So far, we did this manually every time before calling `run_auto_maintenance()`. With the new `close_object_store` flag, we can do that implicitly in that function, which is more robust because future callers won't be able to forget to close the object store. Note: this changes behavior slightly, as we previously _always_ closed the object store, but now we only close the object store when actually running the auto maintenance. In practice, this should not matter (if anything, it might speed up operations where auto maintenance is disabled). Suggested-by: Junio C Hamano Signed-off-by: Johannes Schindelin --- builtin/am.c | 1 - builtin/fetch.c | 2 -- builtin/merge.c | 1 - builtin/rebase.c | 1 - run-command.c | 1 + 5 files changed, 1 insertion(+), 5 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 0c2ad96b70e..f239e4ddde0 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1848,7 +1848,6 @@ next: */ if (!state->rebasing) { am_destroy(state); - close_object_store(the_repository->objects); run_auto_maintenance(state->quiet); } } diff --git a/builtin/fetch.c b/builtin/fetch.c index 25740c13df1..c9ac8664e18 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -2133,8 +2133,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) NULL); } - close_object_store(the_repository->objects); - if (enable_auto_gc) run_auto_maintenance(verbosity < 0); diff --git a/builtin/merge.c b/builtin/merge.c index 22f23990b37..e4994e369af 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -469,7 +469,6 @@ static void finish(struct commit *head_commit, * We ignore errors in 'gc --auto', since the * user should see them. */ - close_object_store(the_repository->objects); run_auto_maintenance(verbosity < 0); } } diff --git a/builtin/rebase.c b/builtin/rebase.c index 33e09619005..ba09ebb9e66 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -740,7 +740,6 @@ static int finish_rebase(struct rebase_options *opts) delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); unlink(git_path_auto_merge(the_repository)); apply_autostash(state_dir_path("autostash", opts)); - close_object_store(the_repository->objects); /* * We ignore errors in 'git maintenance run --auto', since the * user should see them. diff --git a/run-command.c b/run-command.c index e2dc6243774..229bdff9971 100644 --- a/run-command.c +++ b/run-command.c @@ -1891,6 +1891,7 @@ int run_auto_maintenance(int quiet) return 0; maint.git_cmd = 1; + maint.close_object_store = 1; strvec_pushl(&maint.args, "maintenance", "run", "--auto", NULL); strvec_push(&maint.args, quiet ? "--quiet" : "--no-quiet"); From patchwork Thu Sep 9 09:47:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12482825 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.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 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 A366BC433FE for ; Thu, 9 Sep 2021 09:47:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82875611C3 for ; Thu, 9 Sep 2021 09:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233362AbhIIJs0 (ORCPT ); Thu, 9 Sep 2021 05:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbhIIJsX (ORCPT ); Thu, 9 Sep 2021 05:48:23 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E558C061575 for ; Thu, 9 Sep 2021 02:47:14 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso905544wmi.5 for ; Thu, 09 Sep 2021 02:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=lRLRAwzz8Uo3OJpONkw1O0Db0i4OOTboCPE1JdXn1zA=; b=B2/AyyVc6bJJPjAGwd7Ff3l0/mjptHb6dJLwCqjU6gfWDt6r+jHhCFxq4EFiVVAtUv r5txU7rHVTTbmKwDsm7NQ/ThSa96s0HiTqBZkFOt2okRna+18tQdl5h5ag4mnIZnBfGl QvtfX7zBMX92IOOdWEU/Ts22h2emU22n/CKGGQYpvN2L+M63mZKjsV+bE0FzUmIhGDUl UurF55r/FTAxno8+hQVvfff8Lo0g9qtyOMnom5beI8CoQ2qljmo5RKVyy4B++5QbWpiT Jt/n6XoijukY8zjg3ySyaHFEkEHR4mZqagj9PBwHoHam3tS2Dbaug2DAaPlRFHc02Of6 K8qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=lRLRAwzz8Uo3OJpONkw1O0Db0i4OOTboCPE1JdXn1zA=; b=3Ixf6MEz4JJIsQ4dM7Zty0s5bD/nc/dd0+XHLxTyG38MSn1CjZ0I81o1EDWSXNmJv8 JjGC1W+7R9tv3pMNRjkih7grtI/PtkbeYX16zYIsJ2jHyVfIUu918FbEWwGgDEJxlQ9p 1wV1F3/fgyETmlFlhBdZYS0XBBlDsCKakcsPTUMJgJmuoLpIIsngnjd4zBVVG++OSAOW n/GQogAtQdhqv4PUZyGURZsbKHaBdgx2XtzUM+date7reK2F/miSVMpP2Ru8agFB/nx+ smGUbLk2EtXvLg1ZA1A9gWdMK5S2ggQ+VJ8GL/TvlRgmX95c++r3r4ofkJodGHUUAmOp lQ5Q== X-Gm-Message-State: AOAM531ox/+bUUmxzkSClU8MvNnvxWhL1mtYr8JxGYd3Rao2EmZhE4k6 bz038V4bay2SmQhECtt0+DMhZmtF6mE= X-Google-Smtp-Source: ABdhPJyCU3e9Jc3yV8dAhLmFdIQm+wKHKemjwLrOYOpoPYFsOuUSb+sELSYj8OKSDChVQ2JARmGiyA== X-Received: by 2002:a05:600c:4e87:: with SMTP id f7mr2020814wmq.191.1631180833090; Thu, 09 Sep 2021 02:47:13 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w15sm1065188wmi.4.2021.09.09.02.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 02:47:12 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 09 Sep 2021 09:47:08 +0000 Subject: [PATCH 4/4] Close object store closer to spawning child processes Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In many cases where we spawned child processes that _may_ trigger a repack, we explicitly closed the object store first (so that the `repack` process can delete the `.pack` files, which would otherwise not be possible on Windows since files cannot be deleted as long as they as still in use). Wherever possible, we now use the new `close_object_store` bit of the `run_command()` API, to delay closing the object store even further. This makes the code easier to maintain because it is now more obvious that we only release those file handles because of those child processes. Signed-off-by: Johannes Schindelin --- builtin/gc.c | 18 ++++++------------ builtin/pull.c | 3 +-- builtin/receive-pack.c | 3 +-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index f05d2f0a1ac..ddee9f8324f 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -663,8 +663,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) gc_before_repack(); if (!repository_format_precious_objects) { - close_object_store(the_repository->objects); - if (run_command_v_opt(repack.v, RUN_GIT_CMD)) + if (run_command_v_opt(repack.v, + RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE)) die(FAILED_RUN, repack.v[0]); if (prune_expire) { @@ -848,7 +848,7 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; - child.git_cmd = 1; + child.git_cmd = child.close_object_store = 1; strvec_pushl(&child.args, "commit-graph", "write", "--split", "--reachable", NULL); @@ -864,7 +864,6 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) if (!the_repository->settings.core_commit_graph) return 0; - close_object_store(the_repository->objects); if (run_write_commit_graph(opts)) { error(_("failed to write commit-graph")); return 1; @@ -913,7 +912,7 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; - child.git_cmd = 1; + child.git_cmd = child.close_object_store = 1; strvec_push(&child.args, "gc"); if (opts->auto_flag) @@ -923,7 +922,6 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) else strvec_push(&child.args, "--no-quiet"); - close_object_store(the_repository->objects); return run_command(&child); } @@ -1097,14 +1095,12 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; - child.git_cmd = 1; + child.git_cmd = child.close_object_store = 1; strvec_pushl(&child.args, "multi-pack-index", "expire", NULL); if (opts->quiet) strvec_push(&child.args, "--no-progress"); - close_object_store(the_repository->objects); - if (run_command(&child)) return error(_("'git multi-pack-index expire' failed")); @@ -1155,7 +1151,7 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; - child.git_cmd = 1; + child.git_cmd = child.close_object_store = 1; strvec_pushl(&child.args, "multi-pack-index", "repack", NULL); if (opts->quiet) @@ -1164,8 +1160,6 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts) strvec_pushf(&child.args, "--batch-size=%"PRIuMAX, (uintmax_t)get_auto_pack_size()); - close_object_store(the_repository->objects); - if (run_command(&child)) return error(_("'git multi-pack-index repack' failed")); diff --git a/builtin/pull.c b/builtin/pull.c index d9f0156d969..751372041c2 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -578,7 +578,7 @@ static int run_fetch(const char *repo, const char **refspecs) strvec_pushv(&args, refspecs); } else if (*refspecs) BUG("refspecs without repo?"); - ret = run_command_v_opt(args.v, RUN_GIT_CMD); + ret = run_command_v_opt(args.v, RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE); strvec_clear(&args); return ret; } @@ -999,7 +999,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix) oidclr(&rebase_fork_point); } - close_object_store(the_repository->objects); if (run_fetch(repo, refspecs)) return 1; diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 2d1f97e1ca7..9d5e0e3d11c 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2580,10 +2580,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) proc.no_stdin = 1; proc.stdout_to_stderr = 1; proc.err = use_sideband ? -1 : 0; - proc.git_cmd = 1; + proc.git_cmd = proc.close_object_store = 1; proc.argv = argv_gc_auto; - close_object_store(the_repository->objects); if (!start_command(&proc)) { if (use_sideband) copy_to_sideband(proc.err, -1, NULL);