From patchwork Mon Jan 8 10:05:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13513240 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEF83134A9 for ; Mon, 8 Jan 2024 10:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="LHyJZgp+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nqKRkicP" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id A96775C17B9; Mon, 8 Jan 2024 05:05:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 08 Jan 2024 05:05:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1704708326; x=1704794726; bh=hb9G6pY8Pi po1RRqxqBA080tuleGoV2TMKPsQtd07TU=; b=LHyJZgp+icLbAB3HKHjBaHIUN1 9hWlIAe8P3FE2otGm8c3wXrAudqK3sJqZxkssviCiZYAt0Wyob9kB1zk6wN7K2hW slEpWK6eDcBzsrDz8cqMNPieBFUMD1pYIPoYfMkil5YykoqA7w+mcmedOmd6oTSt HlWLJeDjTxlU8pp5OL5Jv8yd+DBtHJ5xfxQDeQ54nwaMH8QLk+WW48iyujVTFj7O cixxbfkrSTRRIb7ZrGQF/Yw19QG/e6whTXdhsn5TLVS3dCHer5cibe3Gm1USS96L K0Vbs2WV4X8gJn6RA33/p7eLVzXquLzAbbgyxhtdiJMKggYXeVsoA4UURrXw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1704708326; x=1704794726; bh=hb9G6pY8Pipo1RRqxqBA080tuleG oV2TMKPsQtd07TU=; b=nqKRkicPanLHzFNK5teosiXts+vw1TFI+jaF828oi+xk GzFamgNgNvya4v5Z2vLN+2sLwkCXfWIuyr5XNjAjycw0HlKAwc6GlrrXVkNAkfLw sxyuB6u8PeCiL5F9VIAX11EL30/bxZo5gsPZ4v023rzyWs7+UBQqCWzcNDFD2oUs +HIRXtQ+GIEhJlx6Nr360g/ByxQnCdRKnKmrVj6SKq9BxXPltoyYwtWDc2m0JDPk MJFZuk/KolRJaF1Olh89LbBhoz+YYNeZogS+pC+aB6XyLmoqk6UGbXZMwEAw1Bs9 zDiIdk3qfkutTiWFQEGPDKRZsPhhbMtMY0ml/Z8Qeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdehjedgudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 8 Jan 2024 05:05:25 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 49e53807 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 8 Jan 2024 10:02:47 +0000 (UTC) Date: Mon, 8 Jan 2024 11:05:22 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Karthik Nayak , Eric Sunshine Subject: [PATCH v2 0/6] worktree: initialize refdb via ref backends Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Hi, this is the second version of my patch series that refactors the initialization of worktree refdbs to use the refs API. Changes compared to v1: - Improved commit messages. - This series is now based on `ps/refstorage-extension`, 1b2234079b (t9500: write "extensions.refstorage" into config, 2023-12-29). While there is no functional dependency between those series, merging both topics causes a merge conflict. Patrick Patrick Steinhardt (6): refs: prepare `refs_init_db()` for initializing worktree refs setup: move creation of "refs/" into the files backend refs/files: skip creation of "refs/{heads,tags}" for worktrees builtin/worktree: move setup of commondir file earlier worktree: expose interface to look up worktree by name builtin/worktree: create refdb via ref backend builtin/worktree.c | 53 ++++++++++++++++++++----------------------- refs.c | 6 ++--- refs.h | 4 +++- refs/debug.c | 4 ++-- refs/files-backend.c | 37 +++++++++++++++++++++++++----- refs/packed-backend.c | 1 + refs/refs-internal.h | 4 +++- setup.c | 17 +------------- worktree.c | 27 +++++++++++++--------- worktree.h | 12 ++++++++++ 10 files changed, 96 insertions(+), 69 deletions(-) Range-diff against v1: 1: 6cb4e0a99f ! 1: a4894b3e15 refs: prepare `refs_init_db()` for initializing worktree refs @@ refs/refs-internal.h: typedef struct ref_store *ref_store_init_fn(struct reposit struct ref_transaction *transaction, ## setup.c ## -@@ setup.c: void create_reference_database(const char *initial_branch, int quiet) - safe_create_dir(git_path("refs"), 1); +@@ setup.c: void create_reference_database(unsigned int ref_storage_format, adjust_shared_perm(git_path("refs")); + repo_set_ref_storage_format(the_repository, ref_storage_format); - if (refs_init_db(&err)) + if (refs_init_db(get_main_ref_store(the_repository), 0, &err)) die("failed to set up refs db: %s", err.buf); 2: ae013eaa4a ! 2: f500db51c2 setup: move creation of "refs/" into the files backend @@ Commit message seems a lot more sensible to have it this way round than to require callers to create the directory themselves. + An alternative to this would be to create "refs/" in `refs_init_db()` + directly. This feels conceptually unclean though as the creation of the + refdb is now cluttered across different callsites. Furthermore, both the + "files" and the upcoming "reftable" backend write backend-specific data + into the "refs/" directory anyway, so splitting up this logic would only + make it harder to reason about. + Signed-off-by: Patrick Steinhardt ## refs/files-backend.c ## @@ refs/files-backend.c: static int files_init_db(struct ref_store *ref_store, ## setup.c ## -@@ setup.c: void create_reference_database(const char *initial_branch, int quiet) +@@ setup.c: void create_reference_database(unsigned int ref_storage_format, struct strbuf err = STRBUF_INIT; int reinit = is_reinit(); @@ setup.c: void create_reference_database(const char *initial_branch, int quiet) - safe_create_dir(git_path("refs"), 1); - adjust_shared_perm(git_path("refs")); - + repo_set_ref_storage_format(the_repository, ref_storage_format); if (refs_init_db(get_main_ref_store(the_repository), 0, &err)) die("failed to set up refs db: %s", err.buf); - 3: 3cf6ceb274 ! 3: 9e99efeaa3 refs/files: skip creation of "refs/{heads,tags}" for worktrees @@ Commit message The files ref backend will create both "refs/heads" and "refs/tags" in the Git directory. While this logic makes sense for normal repositories, - it does not fo worktrees because those refs are "common" refs that would - always be contained in the main repository's ref database. + it does not for worktrees because those refs are "common" refs that + would always be contained in the main repository's ref database. Introduce a new flag telling the backend that it is expected to create a per-worktree ref database and skip creation of these dirs in the files 4: 1a6337fc51 = 4: f2eb020288 builtin/worktree: move setup of commondir file earlier 5: f344a915e9 ! 5: 5525a9f9c2 worktree: expose interface to look up worktree by name @@ worktree.c free (worktrees); } -@@ worktree.c: static struct worktree *get_main_worktree(void) +@@ worktree.c: static struct worktree *get_main_worktree(int skip_reading_head) return worktree; } --static struct worktree *get_linked_worktree(const char *id) -+struct worktree *get_linked_worktree(const char *id) +-static struct worktree *get_linked_worktree(const char *id, +- int skip_reading_head) ++struct worktree *get_linked_worktree(const char *id, ++ int skip_reading_head) { struct worktree *worktree = NULL; struct strbuf path = STRBUF_INIT; @@ worktree.h: struct worktree *find_worktree(struct worktree **list, + * Look up the worktree corresponding to `id`, or NULL of no such worktree + * exists. + */ -+struct worktree *get_linked_worktree(const char *id); ++struct worktree *get_linked_worktree(const char *id, ++ int skip_reading_head); + /* * Return the worktree corresponding to `path`, or NULL if no such worktree 6: aae969301f ! 6: 240dc40de1 builtin/worktree: create refdb via ref backend @@ builtin/worktree.c: static int add_worktree(const char *path, const char *refnam - strbuf_reset(&sb); - strbuf_addf(&sb, "%s/HEAD", sb_repo.buf); - write_file(sb.buf, "%s", oid_to_hex(null_oid())); -+ wt = get_linked_worktree(name); ++ wt = get_linked_worktree(name, 1); + if (!wt) { + ret = error(_("could not find created worktree '%s'"), name); + goto done; base-commit: 1b2234079b24da99dd78e4ce4bfe338a2a841aed