From patchwork Tue Oct 26 22:35:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neeraj Singh (WINDOWS-SFS)" X-Patchwork-Id: 12585857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6111DC433FE for ; Tue, 26 Oct 2021 22:35:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E722610A2 for ; Tue, 26 Oct 2021 22:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240083AbhJZWiA (ORCPT ); Tue, 26 Oct 2021 18:38:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240091AbhJZWh6 (ORCPT ); Tue, 26 Oct 2021 18:37:58 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693BEC0613B9 for ; Tue, 26 Oct 2021 15:35:33 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 136-20020a1c008e000000b0032ccae3b331so727714wma.0 for ; Tue, 26 Oct 2021 15:35:33 -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=4ZT2JLUdNEcjrhJV6TVRcwBGw2uyZfrSxNINrBK83Rg=; b=PonYw2gE2Ud2mOInJwXGJVBeSJsy90rljQfsTTeFK7FGFFULC2uWLTR10YvNWU46Tp x69V8jOxKsFB60W3YvPWpbv9Rht5eRJWyhBO4DtABM9nJo59WdZE9yT4/i8s45B49dGv hPDTMe8FK/ZieTk/yu52XFkudov89ufXuP1ZqZq7N37gmLWzlfwvd3W3+JCjf7KIYjE/ ELMFvImxIXxeK1s0LToUWkNpZsPQOTrsFahThcuhBQTE+hgd5dygJldpmsXKwSkISpqQ U0dStSaun3ErVARVWs7Q+5jy9oG55PPQeCITFbjtXJKfB8X2KHMvpIOBgtr/UWsiivDD fT7Q== 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=4ZT2JLUdNEcjrhJV6TVRcwBGw2uyZfrSxNINrBK83Rg=; b=VfJdxvbalJfA7oyBB3+WtO3KtmA/rtESFy5pIR4Ddu9qVe4nItDW3QbJbO+qAKyE7R +9n5RnAm1b7m9mN9Jt5gkxckALCl2zpUYTmk+xikkeH0lzYsBgXq7wRoeqjAQiyX9QyR Hxw8SDes117QTcT4H5wbUecyA5hlUmPa0it/SLG5XaWfwJSzSFqakcg3YpnIwnxn5nnt 3m9NgxipRFIbazd5S3i/9EF+/sx+gyuUntY3PX1f0f3Bwj1ExrP2xLTWDM/38duZmTkr Xv7QvR8kvhyQ1BJm/eZXPFgMS5pDPhZuXeLw9epqFF1UqXTH711+2hEa7I4iL5mi+HNm 51yw== X-Gm-Message-State: AOAM5305SEQRn5RDgM/oGuX8fKmh8p6evnTJOBeO2hY7r/Ksa5tauU23 CAzn32oOMqvNjlwWZGblq7W6dP0vptw= X-Google-Smtp-Source: ABdhPJyhu3KOAAh7/EHcmbDNw/oQL+8uqcDE17t5VfgTWw1TOWHXUfRE6+HA507957nTKYBWvj4Chw== X-Received: by 2002:a7b:c38b:: with SMTP id s11mr1676407wmj.114.1635287732019; Tue, 26 Oct 2021 15:35:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t1sm23346461wre.32.2021.10.26.15.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 15:35:31 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 26 Oct 2021 22:35:29 +0000 Subject: [PATCH 1/2] fixup! tmp-objdir: new API for creating temporary writable databases Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, "Neeraj K. Singh" , Neeraj Singh Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Neeraj Singh From: Neeraj Singh Fix prune code to be able to delete multiple object directories. I wasn't properly resetting the strbuf with the path. Signed-off-by: Neeraj Singh --- builtin/prune.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/prune.c b/builtin/prune.c index 9c72ecf5a58..6b6b0c7b011 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -31,6 +31,7 @@ static int prune_tmp_file(const char *fullpath) if (show_only || verbose) printf("Removing stale temporary directory %s\n", fullpath); if (!show_only) { + strbuf_reset(&remove_dir_buf); strbuf_addstr(&remove_dir_buf, fullpath); remove_dir_recursively(&remove_dir_buf, 0); } From patchwork Tue Oct 26 22:35:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Neeraj Singh (WINDOWS-SFS)" X-Patchwork-Id: 12585859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02A93C433F5 for ; Tue, 26 Oct 2021 22:35:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB965610A2 for ; Tue, 26 Oct 2021 22:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240090AbhJZWiB (ORCPT ); Tue, 26 Oct 2021 18:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbhJZWh7 (ORCPT ); Tue, 26 Oct 2021 18:37:59 -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 1F074C061220 for ; Tue, 26 Oct 2021 15:35:33 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id g141so815106wmg.4 for ; Tue, 26 Oct 2021 15:35:33 -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=CA2tqvf0iPoQU9EZel2QXt0Wb/Fc1vAjZ5KIReZC3vc=; b=mZwqjM37IJU5pVEbaHWG9EufUwxiEnht2msXLvQ0l1TYhEUpTH96BfVy5pcWX7WpG1 /9Ijlav2+hk4v/NzwYc//zr9Wuz2gs3tiQV+sfT3SxrcwnkMxaIA8l2cQnlSz7HKh0ka slJ4x/l5P9qUVlGXXMG4uWYWvSssCMHRtdB1cGdDrjVzLezgpQxrfIDWiCSnJWedx1vQ 1KHgDBaQ4rMoeLbY+MXhmoDUpRrb2a6QxCQHdKUUSNk9Jv0N//PZV86J5S+pSgxzleXj j6ME8kTaXvXY9CakoIYR4TM/gxiTM/RZXiEpnsvR1wKdxHd1oXdNwM10lb/FJjOEMCGg tNHw== 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=CA2tqvf0iPoQU9EZel2QXt0Wb/Fc1vAjZ5KIReZC3vc=; b=BjiMvjleICpOKgZdMkW5R3t+bD5q0+JfRuvAKVSzqbpjvh2Zg7POMNOqEUO5t4AilH QbjFFaZ/nKWbc6iYkoHAaKUaGF7xRv+oCJOfdf+w4toGEHRxmTSOUoONKlxOz3lD81rg Rsvy+ydO4S5wfU1t1gN1WNwLU9ACfBtV2m6jUy4sMU2Izug8n6Aljqi+fPJi+bdMb1uf 8oqtwWTMffimyHarMVHy4Dj6f2beUnG40NfvKXruPEy0un1AhB4rrhbdZ4A9b9WrmOVb 2CVy8fMg32TJTM0Ng1gh3uFLn+MNVtDC8CFX+/NIUM4OBI7eIXto3wSNoZUNWu7IDKT7 J5iw== X-Gm-Message-State: AOAM533xNRdZ1tsyhgQPNPY7FDLGvQnORpmHSr8cITzgctmFN7y9mBu/ z4lzbQXmE/nhTolikl1HK467p06iKrw= X-Google-Smtp-Source: ABdhPJz58p43HeuR4fa54YNal52ahkfc/+P6YTflVcG2+FghYtPGrawuJrPffpfwCZFfchoxx03J5w== X-Received: by 2002:a7b:c005:: with SMTP id c5mr1669963wmb.150.1635287732609; Tue, 26 Oct 2021 15:35:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t12sm1809769wmq.44.2021.10.26.15.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 15:35:32 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 26 Oct 2021 22:35:30 +0000 Subject: [PATCH 2/2] fixup! tmp-objdir: new API for creating temporary writable databases Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Johannes.Schindelin@gmx.de, "Neeraj K. Singh" , Neeraj Singh Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Neeraj Singh From: Neeraj Singh When setup_work_tree executes, it redoes setup of the object database path and various other aspects of the_repository. This destroys the temporary object database state. This commit removes the temporary object database and reapplies it around the operations in the chdir_notify callback. Signed-off-by: Neeraj Singh --- environment.c | 5 +++++ tmp-objdir.c | 25 +++++++++++++++++++++++++ tmp-objdir.h | 15 +++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/environment.c b/environment.c index 46ec5072c05..7ba5ae06c71 100644 --- a/environment.c +++ b/environment.c @@ -17,6 +17,7 @@ #include "commit.h" #include "strvec.h" #include "object-store.h" +#include "tmp-objdir.h" #include "chdir-notify.h" #include "shallow.h" @@ -344,10 +345,14 @@ static void update_relative_gitdir(const char *name, void *data) { char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir()); + struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); trace_printf_key(&trace_setup_key, "setup: move $GIT_DIR to '%s'", path); + set_git_dir_1(path); + if (tmp_objdir) + tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); free(path); } diff --git a/tmp-objdir.c b/tmp-objdir.c index 45d42a7bcf0..3d38eeab66b 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -1,5 +1,6 @@ #include "cache.h" #include "tmp-objdir.h" +#include "chdir-notify.h" #include "dir.h" #include "sigchain.h" #include "string-list.h" @@ -12,6 +13,7 @@ struct tmp_objdir { struct strbuf path; struct strvec env; struct object_directory *prev_odb; + int will_destroy; }; /* @@ -315,4 +317,27 @@ void tmp_objdir_replace_primary_odb(struct tmp_objdir *t, int will_destroy) if (t->prev_odb) BUG("the primary object database is already replaced"); t->prev_odb = set_temporary_primary_odb(t->path.buf, will_destroy); + t->will_destroy = will_destroy; +} + +struct tmp_objdir *tmp_objdir_unapply_primary_odb(void) +{ + if (!the_tmp_objdir || !the_tmp_objdir->prev_odb) + return NULL; + + restore_primary_odb(the_tmp_objdir->prev_odb, the_tmp_objdir->path.buf); + the_tmp_objdir->prev_odb = NULL; + return the_tmp_objdir; +} + +void tmp_objdir_reapply_primary_odb(struct tmp_objdir *t, const char *old_cwd, + const char *new_cwd) +{ + char *path; + + path = reparent_relative_path(old_cwd, new_cwd, t->path.buf); + strbuf_reset(&t->path); + strbuf_addstr(&t->path, path); + free(path); + tmp_objdir_replace_primary_odb(t, t->will_destroy); } diff --git a/tmp-objdir.h b/tmp-objdir.h index 75754cbfba6..a3145051f25 100644 --- a/tmp-objdir.h +++ b/tmp-objdir.h @@ -59,4 +59,19 @@ void tmp_objdir_add_as_alternate(const struct tmp_objdir *); */ void tmp_objdir_replace_primary_odb(struct tmp_objdir *, int will_destroy); +/* + * If the primary object database was replaced by a temporary object directory, + * restore it to its original value while keeping the directory contents around. + * Returns NULL if the primary object database was not replaced. + */ +struct tmp_objdir *tmp_objdir_unapply_primary_odb(void); + +/* + * Reapplies the former primary temporary object database, after protentially + * changing its relative path. + */ +void tmp_objdir_reapply_primary_odb(struct tmp_objdir *, const char *old_cwd, + const char *new_cwd); + + #endif /* TMP_OBJDIR_H */