From patchwork Tue Aug 13 09:13:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761604 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 09AB717C7CA for ; Tue, 13 Aug 2024 09:13:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540405; cv=none; b=ZwHfIhFaCO9B7aDUQJafErbOVYdDauFZzjLxGMRXTTAFnUxmvDiQYJSCEd8erFYi7ulT4XqDewFPowrkrzRea+53eGIOufDuzWF1pxQoS8bYpltLb30lL4/3GbABT5+S4wS3Ibp5YIV21apiallD3hqwEjsq4IzsdOyNkd7nxEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540405; c=relaxed/simple; bh=KZ1JrdbvsgRTo49Dn6byy63cMfHyrITqzuXt3eisQkc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l+quQ9ijjVOy46qkNNegPdorjwVxYxdk/3w6cWDn2jbBGqpeOsS9R99+HLilf/x7oyuV7AD53Ooy4/txrLkh7bisgo/Yob2vq4ZaEjV9+bA66zcCChd6QXV91m/8mYzL33hYNXAULKpGR2m0wj18dSH+NEUaHk6hP1Uf99+4dOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=BFRoZtKS; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XwxbO5s6; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="BFRoZtKS"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XwxbO5s6" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 29D62138FBA9; Tue, 13 Aug 2024 05:13:23 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:13:23 -0400 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=fm3; t=1723540403; x=1723626803; bh=Wvof6QhJ4i k3v/hMXbSPJmemQOiJiInu0GlWaHo5PPo=; b=BFRoZtKSDb8daMw3S23CP7vuGE 7qzLbWo7EZ1OJlxena7zF0ILZVxGgwfxOgBuCU072z2ROCpQ1hkK6LfABGZrtDZ+ Y4FCavNpKiJ0UZ23oei1+NoChEW+UPpee8XnPGJvsqviFR7cdsMRV/eORZm2HlbM idfrNWG195xjbjd4Lctedoq+PwswFeX1Gk8kypjcJ7+1PU4l6dHuagRhJ05J8p9g kRM658BM1jsJnuGCM950eUXQKmK5oFftVMz2vUE7mmtwnMzDjb7TrxsKEyARFMoW PVHyWjHIM4Fq6z0Mf2ehSmrFGdU+NZXYtKFeud2H4l6dPYG90LkytYKOs+Ow== 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= fm3; t=1723540403; x=1723626803; bh=Wvof6QhJ4ik3v/hMXbSPJmemQOiJ iInu0GlWaHo5PPo=; b=XwxbO5s6WJ7bYH9lAREgu4ty5eyTWkLp8o8nctr9MgVg +vVICiROsqpRqgP0hpSHAnsD+eF9EX7RIyGUeFJj4w4ifBAQHmvQSgdYpO61RJ+l qm/dXv+VhFqmY0ok1Ltqb9wHN02pEBDZEO5LydfRCmVdXBvP7v+dA/99kgKqLjZS jHklHGQXrx4Tv7yWT6mTxHgznN9KBeluB793G86L3p25727ws2QdSKEkqWE0L0rg 3ZJgO+Lo4Dj+FdHq1bwjbdbA7M5xoOvQJjb2L4+y2ZN9DhKP9uh4+QWCwquj7xUB KARFOWU5ue2Qr6Ra0qMKvmKxj9kEBx+63ZLPPUUwzA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fed6a4da (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:05 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 01/20] path: expose `do_git_path()` as `repo_git_pathv()` 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: We're about to move functions of the "path" subsytem that do not use a `struct repository` into "path.h" as static inlined functions. This will require us to call `do_git_path()`, which is internal to "path.c". Expose the function as `repo_git_pathv()` to prepare for the change. Signed-off-by: Patrick Steinhardt --- path.c | 20 ++++++++++---------- path.h | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/path.c b/path.c index 19f7684f38..71f1cb4dfb 100644 --- a/path.c +++ b/path.c @@ -417,9 +417,9 @@ static void strbuf_worktree_gitdir(struct strbuf *buf, strbuf_git_common_path(buf, repo, "worktrees/%s", wt->id); } -static void do_git_path(const struct repository *repo, - const struct worktree *wt, struct strbuf *buf, - const char *fmt, va_list args) +void repo_git_pathv(const struct repository *repo, + const struct worktree *wt, struct strbuf *buf, + const char *fmt, va_list args) { int gitdir_len; strbuf_worktree_gitdir(buf, repo, wt); @@ -438,7 +438,7 @@ char *repo_git_path(const struct repository *repo, struct strbuf path = STRBUF_INIT; va_list args; va_start(args, fmt); - do_git_path(repo, NULL, &path, fmt, args); + repo_git_pathv(repo, NULL, &path, fmt, args); va_end(args); return strbuf_detach(&path, NULL); } @@ -449,7 +449,7 @@ void strbuf_repo_git_path(struct strbuf *sb, { va_list args; va_start(args, fmt); - do_git_path(repo, NULL, sb, fmt, args); + repo_git_pathv(repo, NULL, sb, fmt, args); va_end(args); } @@ -458,7 +458,7 @@ char *git_path_buf(struct strbuf *buf, const char *fmt, ...) va_list args; strbuf_reset(buf); va_start(args, fmt); - do_git_path(the_repository, NULL, buf, fmt, args); + repo_git_pathv(the_repository, NULL, buf, fmt, args); va_end(args); return buf->buf; } @@ -467,7 +467,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) { va_list args; va_start(args, fmt); - do_git_path(the_repository, NULL, sb, fmt, args); + repo_git_pathv(the_repository, NULL, sb, fmt, args); va_end(args); } @@ -476,7 +476,7 @@ const char *git_path(const char *fmt, ...) struct strbuf *pathname = get_pathname(); va_list args; va_start(args, fmt); - do_git_path(the_repository, NULL, pathname, fmt, args); + repo_git_pathv(the_repository, NULL, pathname, fmt, args); va_end(args); return pathname->buf; } @@ -486,7 +486,7 @@ char *git_pathdup(const char *fmt, ...) struct strbuf path = STRBUF_INIT; va_list args; va_start(args, fmt); - do_git_path(the_repository, NULL, &path, fmt, args); + repo_git_pathv(the_repository, NULL, &path, fmt, args); va_end(args); return strbuf_detach(&path, NULL); } @@ -517,7 +517,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...) struct strbuf *pathname = get_pathname(); va_list args; va_start(args, fmt); - do_git_path(the_repository, wt, pathname, fmt, args); + repo_git_pathv(the_repository, wt, pathname, fmt, args); va_end(args); return pathname->buf; } diff --git a/path.h b/path.h index a6f0b70692..94e7030f0b 100644 --- a/path.h +++ b/path.h @@ -66,6 +66,14 @@ char *repo_git_path(const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 2, 3))); +/* + * Print a path into the git directory of repository `repo` into the provided + * buffer. + */ +void repo_git_pathv(const struct repository *repo, + const struct worktree *wt, struct strbuf *buf, + const char *fmt, va_list args); + /* * Construct a path into the git directory of repository `repo` and append it * to the provided buffer `sb`. From patchwork Tue Aug 13 09:13:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761605 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 40776181317 for ; Tue, 13 Aug 2024 09:13:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540407; cv=none; b=uhdD1G9F7f6boy+VoL1fLKIve6UCUfZurlzfEErjB6yd/jaGdcyuAQr8y3IVUER1SWJClLaR2PKxF9vfElyoWv9gsIirDAXAymihNkKn0T7Z51uV+aAdZmsQkgqo4ROYtyzS4xu2sFRTJs2118JCwxOssnXd8OYZkGtsYSp9hog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540407; c=relaxed/simple; bh=bKQXJncqxbzAqW/wG955RcyqZ4C0S9BwXaCzPXd9qVs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HUj8OBGz0OorOp2Bl7qptYWOL1wKorq/LWk2l1gbAFl/YZu1jVpmN+GUwPw9a2UnXsiUKpOfZlxdCBQ5P3lMNYDjbrDIthhKAHu7NIuGJjEkLAqBzBL53cGhwf02VmVZRo8BbLFsRXk89cEDglkEijtHmOOrByd1B7uxYq6xKdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=F9FrJzn7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=F/X+epaW; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="F9FrJzn7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="F/X+epaW" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 5C59F1151A82; Tue, 13 Aug 2024 05:13:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:13:25 -0400 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=fm3; t=1723540405; x=1723626805; bh=nh8QavN4Cv e4RLHq9qROScs9J2rGwCHmaj9FCnbCybk=; b=F9FrJzn7d+HeZwk0MqferbgoIp WorciXWuop7MG9lIiNFpBCxph00aGLKTipjcXb1ymFaldXbKYMOHoSPtN6de4v7Z V9zcA9HHS82E45LyPDdt9JJX7IBnhQStcyrxX7bOFJDjgCtQNINy4cmqWlywE4dK P6itf6uOaWpHyb8/hr4CysDq5G5Nbrr0Dr4sSgplXbKTvib4kN7hxvOou/aBQ9Vt /P9rTZJDwypbSqnIhSzmkPtLWpdq8GYLA070yq7vTAma+Ql/ulBlKLEPzx0yl54h 9+6djYOAnHZ4H6OQUJusf0yrUWdA6NwtdatnntV4vxT04GCRgp2ZBFepV8XA== 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= fm3; t=1723540405; x=1723626805; bh=nh8QavN4Cve4RLHq9qROScs9J2rG wCHmaj9FCnbCybk=; b=F/X+epaWnIPgeST91VleF/vxP9IH7rBXP/xUvF+I8Tvv eSFu2MkktzfDEiGGZAkViQdv52viRer4jRfQTdz7wdsN+LggIOaUwzPEqhDjLlZE NY5/S9IublUMHaPRHUtf6thLx/ErFHv+TB+6xxf53JGiXEwj76MoiUmZQugulvav X1BRibM1oEBFNVC2VlFWQ+vfoAnPuS7p+QEndauZJpYceTye1wThhUx4rOUHhWBt IaYu45At0DaomcL7UMtxvebHkpnjxzvVXfFKFeqCj85vqZg0+J9ToTUZ6yc870Ip HOteXjJ/YgtWAPvOV3+aL3V6SI7JQHIVMGy1G0//mA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0889a2c4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:08 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 02/20] path: expose `do_git_common_path()` as `repo_common_pathv()` Message-ID: <2e3f474e5d7df6e8ad676d50f2191a28e580f5fe.1723540226.git.ps@pks.im> 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: With the same reasoning as the preceding commit, expose the function `do_git_common_path()` as `repo_common_pathv()`. While at it, reorder parameters such that they match the order we have in `repo_git_pathv()`. Signed-off-by: Patrick Steinhardt --- path.c | 22 +++++++++++----------- path.h | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/path.c b/path.c index 71f1cb4dfb..069db6ff8f 100644 --- a/path.c +++ b/path.c @@ -617,16 +617,16 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path, return err; } -static void do_git_common_path(const struct repository *repo, - struct strbuf *buf, - const char *fmt, - va_list args) +void repo_common_pathv(const struct repository *repo, + struct strbuf *sb, + const char *fmt, + va_list args) { - strbuf_addstr(buf, repo->commondir); - if (buf->len && !is_dir_sep(buf->buf[buf->len - 1])) - strbuf_addch(buf, '/'); - strbuf_vaddf(buf, fmt, args); - strbuf_cleanup_path(buf); + strbuf_addstr(sb, repo->commondir); + if (sb->len && !is_dir_sep(sb->buf[sb->len - 1])) + strbuf_addch(sb, '/'); + strbuf_vaddf(sb, fmt, args); + strbuf_cleanup_path(sb); } const char *git_common_path(const char *fmt, ...) @@ -634,7 +634,7 @@ const char *git_common_path(const char *fmt, ...) struct strbuf *pathname = get_pathname(); va_list args; va_start(args, fmt); - do_git_common_path(the_repository, pathname, fmt, args); + repo_common_pathv(the_repository, pathname, fmt, args); va_end(args); return pathname->buf; } @@ -645,7 +645,7 @@ void strbuf_git_common_path(struct strbuf *sb, { va_list args; va_start(args, fmt); - do_git_common_path(repo, sb, fmt, args); + repo_common_pathv(repo, sb, fmt, args); va_end(args); } diff --git a/path.h b/path.h index 94e7030f0b..05aff5f4c3 100644 --- a/path.h +++ b/path.h @@ -37,6 +37,10 @@ void strbuf_git_common_path(struct strbuf *sb, const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +void repo_common_pathv(const struct repository *repo, + struct strbuf *buf, + const char *fmt, + va_list args); /* * Return a statically allocated path into the main repository's @@ -45,7 +49,6 @@ void strbuf_git_common_path(struct strbuf *sb, const char *git_common_path(const char *fmt, ...) __attribute__((format (printf, 1, 2))); - /* * The `git_path` family of functions will construct a path into a repository's * git directory. From patchwork Tue Aug 13 09:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761606 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 63D55187552 for ; Tue, 13 Aug 2024 09:13:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540410; cv=none; b=WkOqKnqVrr9vrvO5OAwRTNnoosvrQfBCJazExMvJ3lV5jjUHsTNUTkB28FKpc5xVsFidYEQJKAo1jxG9fQrdqP1V7H7TwQ1YDq3Be1m8qgkGWW2hq7z1BBNKnqZpeiqS0CYNdXa9e190B6pRj9la0VPE2pqctWIx40NDTtB8mPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540410; c=relaxed/simple; bh=eTd85LiwD/0TYRbbrdMNzi9XlLbGBR9kiqF7Ddi1k5A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ch5rBSso6jlFKLcQCl36PSzUbUgzxC0k6UOs6AhfmEnLw6AZRpS3uko4uIzq5cXn/sZ2+bHtGdSX1GxwEQpzuwiWqTs+ctD8AX8dJBwoBiHBLcjug/5AuN6KUjl3nakdYDXz56ILpvh6+KH+gtMHJCWo75wJmZlmo3NVaucl7s4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=S+DQH1Ml; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U9xOaiUb; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="S+DQH1Ml"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U9xOaiUb" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 941C7138FD24; Tue, 13 Aug 2024 05:13:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:13:28 -0400 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=fm3; t=1723540408; x=1723626808; bh=DYLiJD/qLN W3wxiUFB7QyIpwwmvInSS5N9yItzMJcK0=; b=S+DQH1MloK/XYPkYM+Vq+pFV9h d5b7tp8I0p0eFI5OrekT/Dir+uR6BTP4XAM+fMrda/5b2j/85t1WZWZ0whGBVWuh a9jQeXaJK9By8R1DQq5etx4N/gLfw22/aKqiMEVEAdE7pwTocyWMP6wVCtdTm20s Idd0d8eDCIoHFqxcAgO0eF/FHfTHAn1rmytNgmh3RjLOftzPbmiVLDmTiiVTs01s QlRiFA6Ik+C1T7KoyQg06lWoDqn1mAZoU4Vgd10xDe77Yqk81FX9OkE/fwOLSXQB bzmRLnuuU9cB98nO2zi+qVcVFi5/X4Kn72i5tL2ar3CRIrVujpnohb0+vUoQ== 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= fm3; t=1723540408; x=1723626808; bh=DYLiJD/qLNW3wxiUFB7QyIpwwmvI nSS5N9yItzMJcK0=; b=U9xOaiUbOhBdR+G17AzY5kI121iJfZsmqOk0vExc/XXf YlcXC1b1u1aTeRYEzUs4xSqNv7qFFCd4uIY6B/odTm0BWnPPablmi0FGaH/45E91 PBN8++PPC6eTC7yNAAu2jarF8YeqCNe0+z/ZJNnvqeLjV5P5OaVOZ5JRVrLU1eP7 qSWf6cTBXu3QBUcUnfNHUDJ8yWylPAGXjk5IoSAXcbmdeVV6Ur6XWLjFuh7gTDMP AHhD91bvb8RKr3itYI76zxJcQL7OmMJ0t/5X6thafGP5p02Ujn/oGaxJ0Ex37Cg8 /GejAdlKqnHjcnD1YtqzVLrdPc4nwNCocRAjylxSuQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b19166f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:10 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 03/20] editor: do not rely on `the_repository` for interactive edits Message-ID: <2f73e0efcd4304d191636edf662564dabc48e18c.1723540226.git.ps@pks.im> 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: We implicitly rely on `the_repository` when editing a file interactively because we call `git_path()`. Adapt the function to instead take a `struct repository` as a parameter so that we can remove this hidden dependency. Signed-off-by: Patrick Steinhardt --- add-patch.c | 3 ++- editor.c | 13 ++++++++----- editor.h | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/add-patch.c b/add-patch.c index 46f6bddfe5..218dda3e79 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1140,7 +1140,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk) "removed, then the edit is\n" "aborted and the hunk is left unchanged.\n")); - if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0) + if (strbuf_edit_interactively(the_repository, &s->buf, + "addp-hunk-edit.diff", NULL) < 0) return -1; /* strip out commented lines */ diff --git a/editor.c b/editor.c index d1ba2d7c34..e93b4fdb09 100644 --- a/editor.c +++ b/editor.c @@ -133,14 +133,17 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer, return launch_specified_editor(git_sequence_editor(), path, buffer, env); } -int strbuf_edit_interactively(struct strbuf *buffer, const char *path, +int strbuf_edit_interactively(struct repository *r, + struct strbuf *buffer, const char *path, const char *const *env) { - char *path2 = NULL; + struct strbuf sb = STRBUF_INIT; int fd, res = 0; - if (!is_absolute_path(path)) - path = path2 = xstrdup(git_path("%s", path)); + if (!is_absolute_path(path)) { + strbuf_repo_git_path(&sb, r, "%s", path); + path = sb.buf; + } fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) @@ -157,6 +160,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path, unlink(path); } - free(path2); + strbuf_release(&sb); return res; } diff --git a/editor.h b/editor.h index 8016bb5e00..f1c41df378 100644 --- a/editor.h +++ b/editor.h @@ -1,6 +1,7 @@ #ifndef EDITOR_H #define EDITOR_H +struct repository; struct strbuf; const char *git_editor(void); @@ -28,7 +29,7 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer, * * If `path` is relative, it refers to a file in the `.git` directory. */ -int strbuf_edit_interactively(struct strbuf *buffer, const char *path, - const char *const *env); +int strbuf_edit_interactively(struct repository *r, struct strbuf *buffer, + const char *path, const char *const *env); #endif From patchwork Tue Aug 13 09:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761607 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 AD6861898EE for ; Tue, 13 Aug 2024 09:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540413; cv=none; b=syDgNEIpRCapI3SWDwnQwYDLwpC7NweKQ9VVbHId47Od/WJtxweYyXZvSXfAXQ1FYXVHtzC2fzYeNGoFITm90KRC/ZUS1pVjAAgFMNvSasKeRfur+bK5P6v8JQbK0ZIJ6vsT4+nweG9DultdYVEhVOKp8AHCKm1nCB6P3gh3gws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540413; c=relaxed/simple; bh=Z7NOGPlpGlk8jjBh8hdy+Yoq8QAM3PZIEPHTebMPUEE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dhcm2DFgt35lt3uUo/8AmmofdlrolCmOnrdSKBcAFvy6Mb97x69vqloGG4KUit0WW55zqAcTXs3rENMlnVPlOC5ghyA8lqkgY/KZz0xBgZqHaNssTzgeukUmvo22ZcwUk7gdmW7Vok9QSeGnZP4M6FDHl0ztWOf+ZFhlxZDavWI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=AE0iR7Cm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FNUNS28V; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="AE0iR7Cm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FNUNS28V" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BD2A411519E2; Tue, 13 Aug 2024 05:13:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 05:13:30 -0400 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=fm3; t=1723540410; x=1723626810; bh=TQpjw3XRiE MZyOn9PtkKhYY8rRMuySL43EOD6sMe1XQ=; b=AE0iR7CmmeX4fEb9fZ2W7Ia+pg LDMPEfH57vvLMr2WAAsuTi9DuliT7q6f0LYsm+0lYb2W1yqHBQccZWr1GXMD/msG cKJpgBZ4XRceOIhbSy9nfu5yhtrBHntThl8ESv0JmdB837JqoA6Fc4AFWlFhldUs TiJYAQ+m+hFdNQrahDk/ceLCB6t36eQOC2VXacP6wCeCWWlhqayNLJD/3FTAN+At xynOdAJIqzNSHf91fToq96v9ZEmQrDrcdMWwrqr/lVVZRnCmVNHB1PFAJbOnb0NZ 9KUNm82G02gupCBtRXBAbumcvLy5a2l8XD7G0UVwy1lUJksu2GqcRJDCcV7Q== 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= fm3; t=1723540410; x=1723626810; bh=TQpjw3XRiEMZyOn9PtkKhYY8rRMu ySL43EOD6sMe1XQ=; b=FNUNS28V4XDZLONEeiWgQxRqL8G2TxO0Qi1fdNDTSOfS 9y2WsuPH5ff5qKgcCRk9h47W9NJ+Moy17XXO1MY/POdCn5DBtoEleuKGFE5VqGkT DkrM0LasrAonLo7WoJJ9QAU0YhlV398XF0h4l4dy5S/yRwB6bN9nzyu/L+WcWRk0 tXEF2RDwpk/hBVmW/Mc8U2UfZkCgJjtA0e4DsTCwDb6oekNGfEagCXheM/3MWQ0U +4drgSFZvU6bBznVeXSdBgCdUXqPXSYIRkN8Cihb/0ZwX4Z3S+qvld+jBevVDB5n YDa55ANzJbom/AkBicr5LyMRFe9YmPPE4CIBbWYRVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:29 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 406d34dc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:13 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 04/20] hooks: remove implicit dependency on `the_repository` Message-ID: <688d705179e0d8692c635e20f15eb18ae8e500eb.1723540226.git.ps@pks.im> 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: We implicitly depend on `the_repository` in our hook subsystem because we use `strbuf_git_path()` to compute hook paths. Remove this dependency by accepting a `struct repository` as parameter instead. Signed-off-by: Patrick Steinhardt --- builtin/am.c | 9 +++++---- builtin/bugreport.c | 2 +- builtin/checkout.c | 2 +- builtin/clone.c | 2 +- builtin/gc.c | 2 +- builtin/hook.c | 2 +- builtin/merge.c | 2 +- builtin/rebase.c | 2 +- builtin/receive-pack.c | 10 +++++----- builtin/worktree.c | 2 +- commit.c | 2 +- hook.c | 21 +++++++++++---------- hook.h | 13 ++++++++----- read-cache.c | 6 +++--- refs.c | 2 +- reset.c | 2 +- sequencer.c | 6 +++--- transport.c | 2 +- 18 files changed, 47 insertions(+), 42 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index a12be088f7..d8875ad402 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -490,7 +490,8 @@ static int run_applypatch_msg_hook(struct am_state *state) assert(state->msg); if (!state->no_verify) - ret = run_hooks_l("applypatch-msg", am_path(state, "final-commit"), NULL); + ret = run_hooks_l(the_repository, "applypatch-msg", + am_path(state, "final-commit"), NULL); if (!ret) { FREE_AND_NULL(state->msg); @@ -512,7 +513,7 @@ static int run_post_rewrite_hook(const struct am_state *state) strvec_push(&opt.args, "rebase"); opt.path_to_stdin = am_path(state, "rewritten"); - return run_hooks_opt("post-rewrite", &opt); + return run_hooks_opt(the_repository, "post-rewrite", &opt); } /** @@ -1663,7 +1664,7 @@ static void do_commit(const struct am_state *state) const char *reflog_msg, *author, *committer = NULL; struct strbuf sb = STRBUF_INIT; - if (!state->no_verify && run_hooks("pre-applypatch")) + if (!state->no_verify && run_hooks(the_repository, "pre-applypatch")) exit(1); if (write_index_as_tree(&tree, the_repository->index, get_index_file(), 0, NULL)) @@ -1716,7 +1717,7 @@ static void do_commit(const struct am_state *state) fclose(fp); } - run_hooks("post-applypatch"); + run_hooks(the_repository, "post-applypatch"); free_commit_list(parents); strbuf_release(&sb); diff --git a/builtin/bugreport.c b/builtin/bugreport.c index b3cc77af53..bdfed3d8f1 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -58,7 +58,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit) for (p = hook_name_list; *p; p++) { const char *hook = *p; - if (hook_exists(hook)) + if (hook_exists(the_repository, hook)) strbuf_addf(hook_info, "%s\n", hook); } } diff --git a/builtin/checkout.c b/builtin/checkout.c index 0f21ddd2c6..89543b3054 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -125,7 +125,7 @@ static void branch_info_release(struct branch_info *info) static int post_checkout_hook(struct commit *old_commit, struct commit *new_commit, int changed) { - return run_hooks_l("post-checkout", + return run_hooks_l(the_repository, "post-checkout", oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()), oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()), changed ? "1" : "0", NULL); diff --git a/builtin/clone.c b/builtin/clone.c index af6017d41a..29d4b79eb5 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -788,7 +788,7 @@ static int checkout(int submodule_progress, int filter_submodules) if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) die(_("unable to write new index file")); - err |= run_hooks_l("post-checkout", oid_to_hex(null_oid()), + err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()), oid_to_hex(&oid), "1", NULL); if (!err && (option_recurse_submodules.nr > 0)) { diff --git a/builtin/gc.c b/builtin/gc.c index 72bac2554f..2ca6288c6b 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -463,7 +463,7 @@ static int need_to_gc(void) else return 0; - if (run_hooks("pre-auto-gc")) + if (run_hooks(the_repository, "pre-auto-gc")) return 0; return 1; } diff --git a/builtin/hook.c b/builtin/hook.c index 5234693a94..cc37438fde 100644 --- a/builtin/hook.c +++ b/builtin/hook.c @@ -58,7 +58,7 @@ static int run(int argc, const char **argv, const char *prefix) hook_name = argv[0]; if (!ignore_missing) opt.error_if_missing = 1; - ret = run_hooks_opt(hook_name, &opt); + ret = run_hooks_opt(the_repository, hook_name, &opt); if (ret < 0) /* error() return */ ret = 1; return ret; diff --git a/builtin/merge.c b/builtin/merge.c index c896b18d1a..662a49a0e8 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -478,7 +478,7 @@ static void finish(struct commit *head_commit, } /* Run a post-merge hook */ - run_hooks_l("post-merge", squash ? "1" : "0", NULL); + run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL); if (new_head) apply_autostash_ref(the_repository, "MERGE_AUTOSTASH"); diff --git a/builtin/rebase.c b/builtin/rebase.c index e3a8e74cfc..fa0ca613e1 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1774,7 +1774,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) /* If a hook exists, give it a chance to interrupt*/ if (!ok_to_skip_pre_rebase && - run_hooks_l("pre-rebase", options.upstream_arg, + run_hooks_l(the_repository, "pre-rebase", options.upstream_arg, argc ? argv[0] : NULL, NULL)) die(_("The pre-rebase hook refused to rebase.")); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 339524ae2a..4ff22d8b15 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -792,7 +792,7 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, struct child_process proc = CHILD_PROCESS_INIT; struct async muxer; int code; - const char *hook_path = find_hook(hook_name); + const char *hook_path = find_hook(the_repository, hook_name); if (!hook_path) return 0; @@ -922,7 +922,7 @@ static int run_update_hook(struct command *cmd) { struct child_process proc = CHILD_PROCESS_INIT; int code; - const char *hook_path = find_hook("update"); + const char *hook_path = find_hook(the_repository, "update"); if (!hook_path) return 0; @@ -1098,7 +1098,7 @@ static int run_proc_receive_hook(struct command *commands, int hook_use_push_options = 0; int version = 0; int code; - const char *hook_path = find_hook("proc-receive"); + const char *hook_path = find_hook(the_repository, "proc-receive"); if (!hook_path) { rp_error("cannot find hook 'proc-receive'"); @@ -1409,7 +1409,7 @@ static const char *push_to_checkout(unsigned char *hash, strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_pushv(&opt.env, env->v); strvec_push(&opt.args, hash_to_hex(hash)); - if (run_hooks_opt(push_to_checkout_hook, &opt)) + if (run_hooks_opt(the_repository, push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; else return NULL; @@ -1618,7 +1618,7 @@ static void run_update_post_hook(struct command *commands) struct child_process proc = CHILD_PROCESS_INIT; const char *hook; - hook = find_hook("post-update"); + hook = find_hook(the_repository, "post-update"); if (!hook) return; diff --git a/builtin/worktree.c b/builtin/worktree.c index 1d51e54fcd..a4b7f24e1e 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -573,7 +573,7 @@ static int add_worktree(const char *path, const char *refname, NULL); opt.dir = path; - ret = run_hooks_opt("post-checkout", &opt); + ret = run_hooks_opt(the_repository, "post-checkout", &opt); } strvec_clear(&child_env); diff --git a/commit.c b/commit.c index 087cb19f4f..24ab5c1b50 100644 --- a/commit.c +++ b/commit.c @@ -1960,5 +1960,5 @@ int run_commit_hook(int editor_is_used, const char *index_file, va_end(args); opt.invoked_hook = invoked_hook; - return run_hooks_opt(name, &opt); + return run_hooks_opt(the_repository, name, &opt); } diff --git a/hook.c b/hook.c index 7e90787bca..a9320cb0ce 100644 --- a/hook.c +++ b/hook.c @@ -10,14 +10,14 @@ #include "environment.h" #include "setup.h" -const char *find_hook(const char *name) +const char *find_hook(struct repository *r, const char *name) { static struct strbuf path = STRBUF_INIT; int found_hook; strbuf_reset(&path); - strbuf_git_path(&path, "hooks/%s", name); + strbuf_repo_git_path(&path, r, "hooks/%s", name); found_hook = access(path.buf, X_OK) >= 0; #ifdef STRIP_EXTENSION if (!found_hook) { @@ -48,9 +48,9 @@ const char *find_hook(const char *name) return path.buf; } -int hook_exists(const char *name) +int hook_exists(struct repository *r, const char *name) { - return !!find_hook(name); + return !!find_hook(r, name); } static int pick_next_hook(struct child_process *cp, @@ -121,7 +121,8 @@ static void run_hooks_opt_clear(struct run_hooks_opt *options) strvec_clear(&options->args); } -int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) +int run_hooks_opt(struct repository *r, const char *hook_name, + struct run_hooks_opt *options) { struct strbuf abs_path = STRBUF_INIT; struct hook_cb_data cb_data = { @@ -129,7 +130,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) .hook_name = hook_name, .options = options, }; - const char *const hook_path = find_hook(hook_name); + const char *const hook_path = find_hook(r, hook_name); int ret = 0; const struct run_process_parallel_opts opts = { .tr2_category = "hook", @@ -173,14 +174,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) return ret; } -int run_hooks(const char *hook_name) +int run_hooks(struct repository *r, const char *hook_name) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; - return run_hooks_opt(hook_name, &opt); + return run_hooks_opt(r, hook_name, &opt); } -int run_hooks_l(const char *hook_name, ...) +int run_hooks_l(struct repository *r, const char *hook_name, ...) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; va_list ap; @@ -191,5 +192,5 @@ int run_hooks_l(const char *hook_name, ...) strvec_push(&opt.args, arg); va_end(ap); - return run_hooks_opt(hook_name, &opt); + return run_hooks_opt(r, hook_name, &opt); } diff --git a/hook.h b/hook.h index 6511525aeb..11863fa734 100644 --- a/hook.h +++ b/hook.h @@ -2,6 +2,8 @@ #define HOOK_H #include "strvec.h" +struct repository; + struct run_hooks_opt { /* Environment vars to be set for each hook */ @@ -55,12 +57,12 @@ struct hook_cb_data { * or disabled. Note that this points to static storage that will be * overwritten by further calls to find_hook and run_hook_*. */ -const char *find_hook(const char *name); +const char *find_hook(struct repository *r, const char *name); /** * A boolean version of find_hook() */ -int hook_exists(const char *hookname); +int hook_exists(struct repository *r, const char *hookname); /** * Takes a `hook_name`, resolves it to a path with find_hook(), and @@ -70,13 +72,14 @@ int hook_exists(const char *hookname); * Returns the status code of the run hook, or a negative value on * error(). */ -int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options); +int run_hooks_opt(struct repository *r, const char *hook_name, + struct run_hooks_opt *options); /** * A wrapper for run_hooks_opt() which provides a dummy "struct * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". */ -int run_hooks(const char *hook_name); +int run_hooks(struct repository *r, const char *hook_name); /** * Like run_hooks(), a wrapper for run_hooks_opt(). @@ -87,5 +90,5 @@ int run_hooks(const char *hook_name); * hook. This function behaves like the old run_hook_le() API. */ LAST_ARG_MUST_BE_NULL -int run_hooks_l(const char *hook_name, ...); +int run_hooks_l(struct repository *r, const char *hook_name, ...); #endif diff --git a/read-cache.c b/read-cache.c index 48bf24f87c..742369b295 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3156,9 +3156,9 @@ static int do_write_locked_index(struct index_state *istate, else ret = close_lock_file_gently(lock); - run_hooks_l("post-index-change", - istate->updated_workdir ? "1" : "0", - istate->updated_skipworktree ? "1" : "0", NULL); + run_hooks_l(the_repository, "post-index-change", + istate->updated_workdir ? "1" : "0", + istate->updated_skipworktree ? "1" : "0", NULL); istate->updated_workdir = 0; istate->updated_skipworktree = 0; diff --git a/refs.c b/refs.c index e082fc59b0..0afc70b51b 100644 --- a/refs.c +++ b/refs.c @@ -2132,7 +2132,7 @@ static int run_transaction_hook(struct ref_transaction *transaction, const char *hook; int ret = 0, i; - hook = find_hook("reference-transaction"); + hook = find_hook(transaction->ref_store->repo, "reference-transaction"); if (!hook) return ret; diff --git a/reset.c b/reset.c index 9550dea03d..b22b1be792 100644 --- a/reset.c +++ b/reset.c @@ -79,7 +79,7 @@ static int update_refs(const struct reset_head_opts *opts, reflog_head); } if (!ret && run_hook) - run_hooks_l("post-checkout", + run_hooks_l(the_repository, "post-checkout", oid_to_hex(head ? head : null_oid()), oid_to_hex(oid), "1", NULL); strbuf_release(&msg); diff --git a/sequencer.c b/sequencer.c index 0291920f0b..edeeec6f15 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1316,7 +1316,7 @@ static int run_rewrite_hook(const struct object_id *oldoid, struct child_process proc = CHILD_PROCESS_INIT; int code; struct strbuf sb = STRBUF_INIT; - const char *hook_path = find_hook("post-rewrite"); + const char *hook_path = find_hook(the_repository, "post-rewrite"); if (!hook_path) return 0; @@ -1614,7 +1614,7 @@ static int try_to_commit(struct repository *r, } } - if (hook_exists("prepare-commit-msg")) { + if (hook_exists(r, "prepare-commit-msg")) { res = run_prepare_commit_msg_hook(r, msg, hook_commit); if (res) goto out; @@ -5149,7 +5149,7 @@ static int pick_commits(struct repository *r, hook_opt.path_to_stdin = rebase_path_rewritten_list(); strvec_push(&hook_opt.args, "rebase"); - run_hooks_opt("post-rewrite", &hook_opt); + run_hooks_opt(r, "post-rewrite", &hook_opt); } apply_autostash(rebase_path_autostash()); diff --git a/transport.c b/transport.c index 12cc5b4d96..f8cd2810a5 100644 --- a/transport.c +++ b/transport.c @@ -1271,7 +1271,7 @@ static int run_pre_push_hook(struct transport *transport, struct ref *r; struct child_process proc = CHILD_PROCESS_INIT; struct strbuf buf; - const char *hook_path = find_hook("pre-push"); + const char *hook_path = find_hook(the_repository, "pre-push"); if (!hook_path) return 0; From patchwork Tue Aug 13 09:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761608 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 B63391898EE for ; Tue, 13 Aug 2024 09:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540419; cv=none; b=KzXB1ZBtAWDUZ9bu7X/2bFIWoEnMALQcYe9Xk33hLTPA/LYbutVNqMnDmxJLVDboEtobOBImMLqo8XXKYhwBMtZF8i/pRK7KwpJdLFnTou9Ff0DRFPuXOhyJn/stA5aX5iAMrKm3oPgFNrPOuJ/0hoxn6kl1WhSqlGRDCKmiCB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540419; c=relaxed/simple; bh=/ic9MIHL3QyTMu7M7/29asdKmxS5mXFLyhMQuIix2lY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RIzd49hdR24aRrtn+cac7AjlWl/U04Wuq/yyyCvaGg1XOcSvF6GMc1ctlHhULuqmUsP14lyHP52cbIsPPvPiulPGZGD9E8D7WxeJHkeJOXRqqJwG1gvCDUDyBzNHbQ9EvSolauxU1HTicylBdiuOT6pIFI1YiVLP78aNL58UqwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Xauqv8HG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=klo/wk48; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="Xauqv8HG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="klo/wk48" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id E2077138F115; Tue, 13 Aug 2024 05:13:36 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:13:36 -0400 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=fm3; t=1723540416; x=1723626816; bh=hFRlzcjczf pxK1ueQ0shAFnbyuNdIiQF5YUy2aP39eg=; b=Xauqv8HGZH0U1K9sYgl/vr5P4H R3Og36+L0CIM+kMYZ1bTabWMEZG/LvoGFzUIgCCV94bwLPMw+dG63JLRKBZtwx3n PBVylybATLkXgBin1I/MIJkLXzlOyxGjfzqQBlFGnnutMFPPv30JIAwtK+VAo1sJ TAqQzLyDGtmDOVDgwZWa451+vpjkwK0d0QnnfIpRtIe35V7e4QjO/pgXzgI766y+ cQ5Fd3WG7FlP2floup0kXVnYM0fopURUazKaV9Ua/gaHUZ3l2sF1nGlcDoXY8XNk Cm7VxIkYm+MaSNHq9br2hVM7DZrf1JL59PsclWeMkKC8AXCoSWe0SfuPhYUQ== 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= fm3; t=1723540416; x=1723626816; bh=hFRlzcjczfpxK1ueQ0shAFnbyuNd IiQF5YUy2aP39eg=; b=klo/wk48I8YMwlOvOdAbdgT4dlajNG/3f2TA5qlh4NlB NMWvwONeu29VWJC7zjSq0aQUxI+6FGe4s5cateTj7twJ0GBLGKzyZbKWPd9lwMY2 RTP3gtxpBmUsfX04Dy74wk3RnD9SkjSSfh9SZuqEDOWYBeYksRHNnWT05VU19ITk UHAHRzEXBLm+sttIOfNlXwRuQcC/9gChaudD9qdkp797e9hrM6FkLq0MEoa/wXVm Nul00czzj1yCgi48sSg+MZBNUEziRvm7l8X4X91wJ3sWKI6izLNWNG4KXWagr4Zk WXDiHBLVOn0FztnWK9NmYG8i2e55kEu0RHHZ5I9zZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 844a0126 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:19 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 05/20] path: stop relying on `the_repository` when reporting garbage 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: We access `the_repository` in `report_linked_checkout_garbage()` both directly and indirectly via `get_git_dir()`. Remove this dependency by instead passing a `struct repository` as parameter. Signed-off-by: Patrick Steinhardt --- builtin/count-objects.c | 2 +- path.c | 6 +++--- path.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index 2d4bb5e8d0..ec6098a149 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -113,7 +113,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) usage_with_options(count_objects_usage, opts); if (verbose) { report_garbage = real_report_garbage; - report_linked_checkout_garbage(); + report_linked_checkout_garbage(the_repository); } for_each_loose_file_in_objdir(get_object_directory(), diff --git a/path.c b/path.c index 069db6ff8f..97a07fafc7 100644 --- a/path.c +++ b/path.c @@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len, strbuf_addstr(buf, LOCK_SUFFIX); } -void report_linked_checkout_garbage(void) +void report_linked_checkout_garbage(struct repository *r) { struct strbuf sb = STRBUF_INIT; const struct common_dir *p; int len; - if (!the_repository->different_commondir) + if (!r->different_commondir) return; - strbuf_addf(&sb, "%s/", get_git_dir()); + strbuf_addf(&sb, "%s/", r->gitdir); len = sb.len; for (p = common_list; p->path; p++) { const char *path = p->path; diff --git a/path.h b/path.h index 05aff5f4c3..9a4a4a8fb3 100644 --- a/path.h +++ b/path.h @@ -158,7 +158,7 @@ int strbuf_git_path_submodule(struct strbuf *sb, const char *path, const char *fmt, ...) __attribute__((format (printf, 3, 4))); -void report_linked_checkout_garbage(void); +void report_linked_checkout_garbage(struct repository *r); /* * You can define a static memoized git path like: From patchwork Tue Aug 13 09:13:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761609 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 E955E18A6C0 for ; Tue, 13 Aug 2024 09:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540422; cv=none; b=Fnh+S2egaJE94Z21nuJNotQHxh9SAvrIocljMnWkXtKqwWk2XLsJo1calQYhmau5LxrMPyf+sOZuCsbDlkH/RNcmrqR5fO9MHCBCf2A5bvofT9+pT9Y0wFtgPi6dPUteqUYU/sKhC7LA5rdU1WB/MdfsFmzzGgG0wEPo6Ym0KP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540422; c=relaxed/simple; bh=M+ZKxNr5ofnKSWwEJNiSXjol015LbiXpd5HI46Ws0QE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JrnHdT8sL8jKQTErNh4GXQ4f30QEtgWuVK5xc4z4oXLA4PoCskJjv2cFUvVfDV/jgNhqoP5kcppIjAnkOm7vTO+5FPkXDdg3QfbAsszLFhnnTIEHFif523iwFEv9NW6EcNhgTKTBArA7kHw6XYVY+tuOCB+Tj4+F0mqG0VRg90g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=NSA/1+Q9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tBjRrPHW; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="NSA/1+Q9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tBjRrPHW" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 157BF1151A82; Tue, 13 Aug 2024 05:13:40 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:13:40 -0400 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=fm3; t=1723540420; x=1723626820; bh=JA5jc1lzBj vq3S5BD5yvn+9eWYGwMjNkNfCW6b3mI+4=; b=NSA/1+Q920OHuBcpYZEEJqHN9l bLNDfiFC/xBhFGNmmyh/QHARgoTIelkypAmZNsbrb5AhPO84Nn6t2tzJr7JVQVUk /FZjgAs0K8yduz7r1eBMYRdvLGnNgT57seXjOhpFL3Ag5sdIxjGWbqDHrjturQCA VEP40WvTdWF6v5doG6HlQy1jOFil1tE7j+A88BDG2F9LzvPPCbOumiPU5KsUr3+N e4lesBtpDEUKhvc52Y6CVLXnNne3Ee3FAAHlxrfu1QEikJS41n6RpkBIY0hWT9uT 4Vtc815nu5erUhoCAzDKvlQc/w0XXzC19m+MNfVws+2xxsqN4lH8F/3yLGJw== 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= fm3; t=1723540420; x=1723626820; bh=JA5jc1lzBjvq3S5BD5yvn+9eWYGw MjNkNfCW6b3mI+4=; b=tBjRrPHWdg9zqTT09ARbKOHhR/8ZBN7vp+WsqYu4yWsv nFlD474cnoK333UzAo1ZkTsmdAsECCH2Q5c4uP1Xpd0jp8GPClma87tYNFJyaYVo yzNfD6lTk6qmLeQk9i32Xi09cTcFylKqyClopFP4JstITB7VVg7nkUCRMlvuwb6w 2gbQWc3/COv9RTE0GpnEUqdER8bkk+CU9LjfIU79AmWQxzvONkcSe5h14+wPaADX HLt02fCCJQuuBF8Car+0pe4lnkU8JHDtMnTCM3KH0j23vA1mdGB4DGtIgEVdAap4 xrV+KT4GfyHacnBjfBXtfl1HyqiXFaYrjfrZSzYM1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:39 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c188fe45 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:22 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 06/20] path: stop relying on `the_repository` in `worktree_git_path()` Message-ID: <29302f4b14c29323bd85f25e0585c5383e7303e0.1723540226.git.ps@pks.im> 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: When not provided a worktree, then `worktree_git_path()` will fall back to returning a path relative to the main repository. In this case, we implicitly rely on `the_repository` to derive the path. Remove this dependency by passing a `struct repository` as parameter. Signed-off-by: Patrick Steinhardt --- builtin/fsck.c | 2 +- builtin/worktree.c | 4 ++-- path.c | 9 +++++++-- path.h | 8 +++++--- revision.c | 2 +- worktree.c | 2 +- wt-status.c | 14 +++++++------- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2e..ad36df9628 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1050,7 +1050,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) * and may get overwritten by other calls * while we're examining the index. */ - path = xstrdup(worktree_git_path(wt, "index")); + path = xstrdup(worktree_git_path(the_repository, wt, "index")); read_index_from(&istate, path, get_worktree_git_dir(wt)); fsck_index(&istate, path, wt->is_current); discard_index(&istate); diff --git a/builtin/worktree.c b/builtin/worktree.c index a4b7f24e1e..eb0a386992 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1146,14 +1146,14 @@ static void validate_no_submodules(const struct worktree *wt) struct strbuf path = STRBUF_INIT; int i, found_submodules = 0; - if (is_directory(worktree_git_path(wt, "modules"))) { + if (is_directory(worktree_git_path(the_repository, wt, "modules"))) { /* * There could be false positives, e.g. the "modules" * directory exists but is empty. But it's a rare case and * this simpler check is probably good enough for now. */ found_submodules = 1; - } else if (read_index_from(&istate, worktree_git_path(wt, "index"), + } else if (read_index_from(&istate, worktree_git_path(the_repository, wt, "index"), get_worktree_git_dir(wt)) > 0) { for (i = 0; i < istate.cache_nr; i++) { struct cache_entry *ce = istate.cache[i]; diff --git a/path.c b/path.c index 97a07fafc7..2949261193 100644 --- a/path.c +++ b/path.c @@ -512,12 +512,17 @@ const char *mkpath(const char *fmt, ...) return cleanup_path(pathname->buf); } -const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...) +const char *worktree_git_path(struct repository *r, + const struct worktree *wt, const char *fmt, ...) { struct strbuf *pathname = get_pathname(); va_list args; + + if (wt && wt->repo != r) + BUG("worktree not connected to expected repository"); + va_start(args, fmt); - repo_git_pathv(the_repository, wt, pathname, fmt, args); + repo_git_pathv(r, wt, pathname, fmt, args); va_end(args); return pathname->buf; } diff --git a/path.h b/path.h index 9a4a4a8fb3..78e9230de9 100644 --- a/path.h +++ b/path.h @@ -95,11 +95,13 @@ const char *git_path(const char *fmt, ...) /* * Similar to git_path() but can produce paths for a specified - * worktree instead of current one + * worktree instead of current one. When no worktree is given, then the path is + * computed relative to main worktree of the given repository. */ -const char *worktree_git_path(const struct worktree *wt, +const char *worktree_git_path(struct repository *r, + const struct worktree *wt, const char *fmt, ...) - __attribute__((format (printf, 2, 3))); + __attribute__((format (printf, 3, 4))); /* * Return a path into the main repository's (the_repository) git directory. diff --git a/revision.c b/revision.c index 1c0192f522..0b92a13af5 100644 --- a/revision.c +++ b/revision.c @@ -1872,7 +1872,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) continue; /* current index already taken care of */ if (read_index_from(&istate, - worktree_git_path(wt, "index"), + worktree_git_path(the_repository, wt, "index"), get_worktree_git_dir(wt)) > 0) do_add_index_objects_to_pending(revs, &istate, flags); discard_index(&istate); diff --git a/worktree.c b/worktree.c index f3c4c8ec54..886c5db691 100644 --- a/worktree.c +++ b/worktree.c @@ -252,7 +252,7 @@ const char *worktree_lock_reason(struct worktree *wt) if (!wt->lock_reason_valid) { struct strbuf path = STRBUF_INIT; - strbuf_addstr(&path, worktree_git_path(wt, "locked")); + strbuf_addstr(&path, worktree_git_path(the_repository, wt, "locked")); if (file_exists(path.buf)) { struct strbuf lock_reason = STRBUF_INIT; if (strbuf_read_file(&lock_reason, path.buf, 0) < 0) diff --git a/wt-status.c b/wt-status.c index b778eef989..b477239039 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1618,7 +1618,7 @@ static char *get_branch(const struct worktree *wt, const char *path) struct object_id oid; const char *branch_name; - if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0) + if (strbuf_read_file(&sb, worktree_git_path(the_repository, wt, "%s", path), 0) <= 0) goto got_nothing; while (sb.len && sb.buf[sb.len - 1] == '\n') @@ -1716,18 +1716,18 @@ int wt_status_check_rebase(const struct worktree *wt, { struct stat st; - if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) { - if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) { + if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) { + if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) { state->am_in_progress = 1; - if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size) + if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size) state->am_empty_patch = 1; } else { state->rebase_in_progress = 1; state->branch = get_branch(wt, "rebase-apply/head-name"); state->onto = get_branch(wt, "rebase-apply/onto"); } - } else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) { - if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st)) + } else if (!stat(worktree_git_path(the_repository, wt, "rebase-merge"), &st)) { + if (!stat(worktree_git_path(the_repository, wt, "rebase-merge/interactive"), &st)) state->rebase_interactive_in_progress = 1; else state->rebase_in_progress = 1; @@ -1743,7 +1743,7 @@ int wt_status_check_bisect(const struct worktree *wt, { struct stat st; - if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) { + if (!stat(worktree_git_path(the_repository, wt, "BISECT_LOG"), &st)) { state->bisect_in_progress = 1; state->bisecting_from = get_branch(wt, "BISECT_START"); return 1; From patchwork Tue Aug 13 09:13:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761610 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 36DE118A95E for ; Tue, 13 Aug 2024 09:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540426; cv=none; b=XcHDQbUfxTLRt+ICfczL+aaFhggBweDD773kg/ETR1nS8ZsbF9lSg30/yc2qw/ev6CNM//0pMWJT4a63NzCo7C30LERA0w1GpSze+OxtrLgTjP189fVb31l4Hs1n3lgt+R8uXn/PhaH/BEjMHgAn/aFBDDQ7UeFXXBknE0NHi6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540426; c=relaxed/simple; bh=+e9advTAN0KMTSvLA2EXjjMkTIuJb4s/Wm0kpWXCN/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uX32WKv/PwhpHmfZ6C0v1b19kh93Kr1fD67n46M3c0YG7kbPZHlsSAfviCFQq4zme+lZtVjI4LQQXDZR5rYNk5C/Xm6XfsyPqExnyee4eLGMzwq33K0QmtMYnSOP9Ivq3v6oX7AJuyhJWHNQvSlrEKvSNlyZ6nmFGjL32oQJTqc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=TyWNan8h; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=GB3T7T2u; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="TyWNan8h"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="GB3T7T2u" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 39CAD11519D0; Tue, 13 Aug 2024 05:13:43 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:13:43 -0400 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=fm3; t=1723540423; x=1723626823; bh=YsbqfhRman lck0BU7x5nKUQ/AjDnLazONUeekSz+tMo=; b=TyWNan8h83v8mxuYTt+G9GYH+g uqVsWpFW5Qi9eF1+QKGshjskMZfs3o82So66fuB6HEm4mbIqDIGtzBp0KSnjhmB+ 03htSmfK5jtdBao26SNW2j/qtI71k2TpQBZeewV/tGoktjMkgBswzBnu8T07IKDw zDb58wfJwAmd+YmHUzS5NaN42DFbWp3VVypwXslYRRtB/Ehp5yDFIqJrGn2F/cl8 yokl/ki52oNmK+uDOJpfYMtQlinzAKMwcMKjDSePZqfXwVeoi0Vf9a/J2h97YeE0 7D4xZuDv5t9ZKWINbSTIoqwQW3QXxuhqB8IzCREnalpsLwZ/cSUC6Cx8aiXg== 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= fm3; t=1723540423; x=1723626823; bh=YsbqfhRmanlck0BU7x5nKUQ/AjDn LazONUeekSz+tMo=; b=GB3T7T2ugDAa2Fk1k1vEMJQ4qazXInshJG4vY99Rghzf XP06KZ2jrjneD36k+Min9vqc7weglKd5cHTYRDl5Kn2viNBGYIVUe5GU943+PJ8c iMfcZXy4pOrtxV+NoJMFBDFHZGbNWluFUS7StIvGg7p0Ak86i1nkjM3VmhGMMyf3 kvDdVs5jqUbgLSfU88T0i35TAXGhasMwDEnVCeDg0Wt4NlWEDo35CjI9oBiGzlGQ SgsAPGaQlxTyMeNcVDSPq7Z2k39ldhVpQJZqO3SkAJ1Ipsp5IOCn7GlOksMFCKK5 YnWmsmRBRdLsbbJzO+j96CWaONh6Jqu9TBDAb66Aeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:42 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 134c8217 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:25 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 07/20] path: hide functions using `the_repository` by default Message-ID: <1b6651770a7aab0885222ad3425918635648e8ac.1723540226.git.ps@pks.im> 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: The path subsystem provides a bunch of legacy functions that compute paths relative to the "gitdir" and "commondir" directories of the global `the_repository` variable. Use of those functions is discouraged, and it is easy to miss the implicit dependency on `the_repository` that calls to those functions may cause. With `USE_THE_REPOSITORY_VARIABLE`, we have recently introduced a tool that allows us to get rid of such functions over time. With this macro, we can hide away functions that have such implicit dependency such that other subsystems that want to be free of `the_repository` will not use them by accident. Move all path-related functions that use `the_repository` into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "path.c", allowing us to remove the definition of said preprocessor macro. Signed-off-by: Patrick Steinhardt --- path.c | 52 +------------------- path.h | 147 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 100 insertions(+), 99 deletions(-) diff --git a/path.c b/path.c index 2949261193..a3bf25b7de 100644 --- a/path.c +++ b/path.c @@ -2,8 +2,6 @@ * Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "environment.h" @@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode) return 0; } -static struct strbuf *get_pathname(void) +struct strbuf *get_pathname(void) { static struct strbuf pathname_array[4] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT @@ -453,44 +451,6 @@ void strbuf_repo_git_path(struct strbuf *sb, va_end(args); } -char *git_path_buf(struct strbuf *buf, const char *fmt, ...) -{ - va_list args; - strbuf_reset(buf); - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, buf, fmt, args); - va_end(args); - return buf->buf; -} - -void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, sb, fmt, args); - va_end(args); -} - -const char *git_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - -char *git_pathdup(const char *fmt, ...) -{ - struct strbuf path = STRBUF_INIT; - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, &path, fmt, args); - va_end(args); - return strbuf_detach(&path, NULL); -} - char *mkpathdup(const char *fmt, ...) { struct strbuf sb = STRBUF_INIT; @@ -634,16 +594,6 @@ void repo_common_pathv(const struct repository *repo, strbuf_cleanup_path(sb); } -const char *git_common_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_common_pathv(the_repository, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - void strbuf_git_common_path(struct strbuf *sb, const struct repository *repo, const char *fmt, ...) diff --git a/path.h b/path.h index 78e9230de9..e91d19fff6 100644 --- a/path.h +++ b/path.h @@ -25,7 +25,7 @@ char *mkpathdup(const char *fmt, ...) __attribute__((format (printf, 1, 2))); /* - * The `git_common_path` family of functions will construct a path into a + * The `strbuf_git_common_path` family of functions will construct a path into a * repository's common git directory, which is shared by all worktrees. */ @@ -43,14 +43,7 @@ void repo_common_pathv(const struct repository *repo, va_list args); /* - * Return a statically allocated path into the main repository's - * (the_repository) common git directory. - */ -const char *git_common_path(const char *fmt, ...) - __attribute__((format (printf, 1, 2))); - -/* - * The `git_path` family of functions will construct a path into a repository's + * The `repo_git_path` family of functions will construct a path into a repository's * git directory. * * These functions will perform adjustments to the resultant path to account @@ -87,14 +80,7 @@ void strbuf_repo_git_path(struct strbuf *sb, __attribute__((format (printf, 3, 4))); /* - * Return a statically allocated path into the main repository's - * (the_repository) git directory. - */ -const char *git_path(const char *fmt, ...) - __attribute__((format (printf, 1, 2))); - -/* - * Similar to git_path() but can produce paths for a specified + * Similar to repo_git_path() but can produce paths for a specified * worktree instead of current one. When no worktree is given, then the path is * computed relative to main worktree of the given repository. */ @@ -103,27 +89,6 @@ const char *worktree_git_path(struct repository *r, const char *fmt, ...) __attribute__((format (printf, 3, 4))); -/* - * Return a path into the main repository's (the_repository) git directory. - */ -char *git_pathdup(const char *fmt, ...) - __attribute__((format (printf, 1, 2))); - -/* - * Construct a path into the main repository's (the_repository) git directory - * and place it in the provided buffer `buf`, the contents of the buffer will - * be overridden. - */ -char *git_path_buf(struct strbuf *buf, const char *fmt, ...) - __attribute__((format (printf, 2, 3))); - -/* - * Construct a path into the main repository's (the_repository) git directory - * and append it to the provided buffer `sb`. - */ -void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) - __attribute__((format (printf, 2, 3))); - /* * Return a path into the worktree of repository `repo`. * @@ -165,19 +130,10 @@ void report_linked_checkout_garbage(struct repository *r); /* * You can define a static memoized git path like: * - * static GIT_PATH_FUNC(git_path_foo, "FOO") + * static REPO_GIT_PATH_FUNC(git_path_foo, "FOO") * * or use one of the global ones below. */ -#define GIT_PATH_FUNC(func, filename) \ - const char *func(void) \ - { \ - static char *ret; \ - if (!ret) \ - ret = git_pathdup(filename); \ - return ret; \ - } - #define REPO_GIT_PATH_FUNC(var, filename) \ const char *git_path_##var(struct repository *r) \ { \ @@ -261,4 +217,99 @@ char *xdg_cache_home(const char *filename); */ void safe_create_dir(const char *dir, int share); +/* + * Do not use this function. It is only exported to other subsystems until we + * can get rid of the below block of functions that implicitly rely on + * `the_repository`. + */ +struct strbuf *get_pathname(void); + +# ifdef USE_THE_REPOSITORY_VARIABLE +# include "strbuf.h" +# include "repository.h" + +/* + * Return a statically allocated path into the main repository's + * (the_repository) common git directory. + */ +__attribute__((format (printf, 1, 2))) +static inline const char *git_common_path(const char *fmt, ...) +{ + struct strbuf *pathname = get_pathname(); + va_list args; + va_start(args, fmt); + repo_common_pathv(the_repository, pathname, fmt, args); + va_end(args); + return pathname->buf; +} + +/* + * Construct a path into the main repository's (the_repository) git directory + * and place it in the provided buffer `buf`, the contents of the buffer will + * be overridden. + */ +__attribute__((format (printf, 2, 3))) +static inline char *git_path_buf(struct strbuf *buf, const char *fmt, ...) +{ + va_list args; + strbuf_reset(buf); + va_start(args, fmt); + repo_git_pathv(the_repository, NULL, buf, fmt, args); + va_end(args); + return buf->buf; +} + +/* + * Construct a path into the main repository's (the_repository) git directory + * and append it to the provided buffer `sb`. + */ +__attribute__((format (printf, 2, 3))) +static inline void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + repo_git_pathv(the_repository, NULL, sb, fmt, args); + va_end(args); +} + +/* + * Return a statically allocated path into the main repository's + * (the_repository) git directory. + */ +__attribute__((format (printf, 1, 2))) +static inline const char *git_path(const char *fmt, ...) +{ + struct strbuf *pathname = get_pathname(); + va_list args; + va_start(args, fmt); + repo_git_pathv(the_repository, NULL, pathname, fmt, args); + va_end(args); + return pathname->buf; +} + +#define GIT_PATH_FUNC(func, filename) \ + const char *func(void) \ + { \ + static char *ret; \ + if (!ret) \ + ret = git_pathdup(filename); \ + return ret; \ + } + +/* + * Return a path into the main repository's (the_repository) git directory. + */ +__attribute__((format (printf, 1, 2))) +static inline char *git_pathdup(const char *fmt, ...) +{ + struct strbuf path = STRBUF_INIT; + va_list args; + va_start(args, fmt); + repo_git_pathv(the_repository, NULL, &path, fmt, args); + va_end(args); + return strbuf_detach(&path, NULL); +} + +# endif /* USE_THE_REPOSITORY_VARIABLE */ + #endif /* PATH_H */ From patchwork Tue Aug 13 09:13:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761611 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 3B8F118B486 for ; Tue, 13 Aug 2024 09:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540429; cv=none; b=rmrowz6R795E2HKmj0Ak4d72pLXaXIY/Bs9O4l6y2wxsx5y6fp3ZS3hGLY+56oqurHqvwNyvPyGZGSnxfPAjtlfsqwFmzUDySeV8K3Er4V9cgK8QYwNkbr8oL+jZoft9iunZN6++yO/CrJLHBcJs02jMZmfnH6V5kGWVAjWNzXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540429; c=relaxed/simple; bh=I15fssooDh6Pchtrdh3RHaJgk4wfx2/5caKMLFe4pTE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=k00VwL/KeWdQTD9+4QHjzVu2p4kn4+3SY+K1TdhNEiSjlfOK9j/0y6FXNXMwIxVBayrEIJcM3U66dsWLhQg9UWjkeQ/wZX3WHGZN1mOrDC9BiPJP4clfY96f+8oGK7tIxC/ZEwgdrEz2RIopyw0lD20jmdSAmu/bTiR8OWOkGOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=ZhJWobHg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=H9Rdaax8; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ZhJWobHg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H9Rdaax8" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 6465E138FD24; Tue, 13 Aug 2024 05:13:46 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:13:46 -0400 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=fm3; t=1723540426; x=1723626826; bh=PAck6YOPSS wo1ZSboxF1439Nd2EubxenVhoKYPXd4WE=; b=ZhJWobHg4Ga6OoP1Mb4TC1UXmr 8AlW5AvNRD66OphGmdk4eiLDoWT8Gb+7e2htkrv1v+8zkGuGS/UJCfkQ5lYJFv29 rVIyuJ5nWWus/Q9tEQEytCP1974wn4b1T2g0/VAQnEelxgnF+8aD46LcALVnLV+y mW+siH4480X8BlIb68Cv3H1uOpyrg5K1olJ8paGOQXbJmlze+C46GJ91ju/jK1RS wRkO+KtQUWwJuPnCNYRBCkXXcBeyua2yWh5YCigp0MDwk28PNeX8B6WhsOdrJ0G9 n4nfZULtvigNgAN1iQ9BKBVS5p8LIiGRMIi919U0BH4/rvKqumhfm/5xJGig== 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= fm3; t=1723540426; x=1723626826; bh=PAck6YOPSSwo1ZSboxF1439Nd2Eu bxenVhoKYPXd4WE=; b=H9Rdaax8S+z5ivjui4OiBYr4tCIurdu+zcaZTPc3eRqM utJgWVLnSoVWv/bZRYSItqtdlHzwbido6DNUvhiU4oLIEes/jmV/qKxytZJv0kXp 5pKvJoPZB0avZhfITDNEcxehxhvI3XReqjE8JFxk4cwPw+AJM1ZzUROLDCfpE9pT 2eaUKNisvjw+r3MqMAbll3zJ4HneSxKcLmvW4cJeOpJCTW5FSv936pfDZc65k7ZZ DqBLsxhAnEL6MuXt1+qBQsS1tBKTLiMiyPKG+xJ6bxwkL8EDiv+g25ij5DQFhvbj 5TM8Q6vfa75oDz6YZh8ElU/XyxyDYWMbvAEJF5niiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 654aad23 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:28 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 08/20] config: introduce missing setters that take repo as parameter 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: While we already provide some of the config-setting interfaces with a `struct repository` as parameter, others only have a variant that implicitly depends on `the_repository`. Fill in those gaps such that we can start to deprecate the repo-less variants. Signed-off-by: Patrick Steinhardt --- config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------ config.h | 15 ++++++++- 2 files changed, 87 insertions(+), 21 deletions(-) diff --git a/config.c b/config.c index 6421894614..ac89b708e7 100644 --- a/config.c +++ b/config.c @@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store, *end_offset = store->parsed[store->parsed_nr - 1].end; } +int repo_config_set_in_file_gently(struct repository *r, const char *config_filename, + const char *key, const char *comment, const char *value) +{ + return repo_config_set_multivar_in_file_gently(r, config_filename, key, value, NULL, comment, 0); +} + int git_config_set_in_file_gently(const char *config_filename, const char *key, const char *comment, const char *value) { - return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, comment, 0); + return repo_config_set_in_file_gently(the_repository, config_filename, + key, comment, value); +} + +void repo_config_set_in_file(struct repository *r, const char *config_filename, + const char *key, const char *value) +{ + repo_config_set_multivar_in_file(r, config_filename, key, value, NULL, 0); } void git_config_set_in_file(const char *config_filename, const char *key, const char *value) { - git_config_set_multivar_in_file(config_filename, key, value, NULL, 0); + repo_config_set_in_file(the_repository, config_filename, key, value); +} + +int repo_config_set_gently(struct repository *r, const char *key, const char *value) +{ + return repo_config_set_multivar_gently(r, key, value, NULL, 0); } int git_config_set_gently(const char *key, const char *value) { - return git_config_set_multivar_gently(key, value, NULL, 0); + return repo_config_set_gently(the_repository, key, value); } int repo_config_set_worktree_gently(struct repository *r, @@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r, return repo_config_set_multivar_gently(r, key, value, NULL, 0); } -void git_config_set(const char *key, const char *value) +void repo_config_set(struct repository *r, const char *key, const char *value) { - git_config_set_multivar(key, value, NULL, 0); + repo_config_set_multivar(r, key, value, NULL, 0); trace2_cmd_set_config(key, value); } +void git_config_set(const char *key, const char *value) +{ + repo_config_set(the_repository, key, value); +} + char *git_config_prepare_comment_string(const char *comment) { size_t leading_blanks; @@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment) * - the config file is removed and the lock file rename()d to it. * */ -int git_config_set_multivar_in_file_gently(const char *config_filename, - const char *key, const char *value, - const char *value_pattern, - const char *comment, - unsigned flags) +int repo_config_set_multivar_in_file_gently(struct repository *r, + const char *config_filename, + const char *key, const char *value, + const char *value_pattern, + const char *comment, + unsigned flags) { int fd = -1, in_fd = -1; int ret; @@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.multi_replace = (flags & CONFIG_FLAGS_MULTI_REPLACE) != 0; if (!config_filename) - config_filename = filename_buf = git_pathdup("config"); + config_filename = filename_buf = repo_git_path(r, "config"); /* * The lock serves a purpose in addition to locking: the new @@ -3526,7 +3550,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, ret = 0; /* Invalidate the config cache */ - git_config_clear(); + repo_config_clear(r); out_free: rollback_lock_file(&lock); @@ -3543,12 +3567,24 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, goto out_free; } -void git_config_set_multivar_in_file(const char *config_filename, - const char *key, const char *value, - const char *value_pattern, unsigned flags) +int git_config_set_multivar_in_file_gently(const char *config_filename, + const char *key, const char *value, + const char *value_pattern, + const char *comment, + unsigned flags) { - if (!git_config_set_multivar_in_file_gently(config_filename, key, value, - value_pattern, NULL, flags)) + return repo_config_set_multivar_in_file_gently(the_repository, config_filename, + key, value, value_pattern, + comment, flags); +} + +void repo_config_set_multivar_in_file(struct repository *r, + const char *config_filename, + const char *key, const char *value, + const char *value_pattern, unsigned flags) +{ + if (!repo_config_set_multivar_in_file_gently(r, config_filename, key, value, + value_pattern, NULL, flags)) return; if (value) die(_("could not set '%s' to '%s'"), key, value); @@ -3556,6 +3592,14 @@ void git_config_set_multivar_in_file(const char *config_filename, die(_("could not unset '%s'"), key); } +void git_config_set_multivar_in_file(const char *config_filename, + const char *key, const char *value, + const char *value_pattern, unsigned flags) +{ + repo_config_set_multivar_in_file(the_repository, config_filename, + key, value, value_pattern, flags); +} + int git_config_set_multivar_gently(const char *key, const char *value, const char *value_pattern, unsigned flags) { @@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key, return res; } +void repo_config_set_multivar(struct repository *r, + const char *key, const char *value, + const char *value_pattern, unsigned flags) +{ + char *file = repo_git_path(r, "config"); + git_config_set_multivar_in_file(file, key, value, + value_pattern, flags); + free(file); +} + void git_config_set_multivar(const char *key, const char *value, const char *value_pattern, unsigned flags) { - git_config_set_multivar_in_file(git_path("config"), - key, value, value_pattern, - flags); + repo_config_set_multivar(the_repository, key, value, + value_pattern, flags); } static size_t section_name_match (const char *buf, const char *name) diff --git a/config.h b/config.h index 54b47dec9e..b13e1bfb8d 100644 --- a/config.h +++ b/config.h @@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *); int git_config_expiry_date(timestamp_t *, const char *, const char *); int git_config_color(char *, const char *, const char *); int git_config_set_in_file_gently(const char *, const char *, const char *, const char *); +int repo_config_set_in_file_gently(struct repository *r, const char *config_filename, + const char *key, const char *comment, const char *value); /** * write config values to a specific config file, takes a key/value pair as * parameter. */ void git_config_set_in_file(const char *, const char *, const char *); +void repo_config_set_in_file(struct repository *, const char *, const char *, const char *); int git_config_set_gently(const char *, const char *); +int repo_config_set_gently(struct repository *r, const char *, const char *); /** * Write a config value that should apply to the current worktree. If @@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha * write config values to `.git/config`, takes a key/value pair as parameter. */ void git_config_set(const char *, const char *); +void repo_config_set(struct repository *, const char *, const char *); int git_config_parse_key(const char *, char **, size_t *); @@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *); #define CONFIG_FLAGS_FIXED_VALUE (1 << 1) int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned); -void git_config_set_multivar(const char *, const char *, const char *, unsigned); int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned); +void git_config_set_multivar(const char *, const char *, const char *, unsigned); +void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned); int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned); +int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned); char *git_config_prepare_comment_string(const char *); @@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename, const char *value, const char *value_pattern, unsigned flags); +void repo_config_set_multivar_in_file(struct repository *r, + const char *config_filename, + const char *key, + const char *value, + const char *value_pattern, + unsigned flags); /** * rename or remove sections in the config file From patchwork Tue Aug 13 09:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761612 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 6211B18C323 for ; Tue, 13 Aug 2024 09:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540431; cv=none; b=nefrR+T7/llyK7AA03wRLcj3s13fxwgpqnma8B6m3Yeb4IYpwT2Ojq3+Mvnsw2QCy/ztJU5BjWFwOZeyUIUxkRzWc9V22DHqRrH9RaO+LKZpE1J9bRTCL2hfF14EgWVAIk3homGKeHscKNuFOJW1TAEJpGh/kA63TKyKnGjobBI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540431; c=relaxed/simple; bh=Rd2BZ320rkppg29DKbnsJgIylyzgcIUnKXnmhKfu3i4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PUCvVmD8r+baG64jzo+hUT/VN3tZoc5qe+vgxFY+EQGpphLst3hxaIdw1By2mCpCqDAxv1xfmjdTCJku+/JuTiYV3ADiDSQHpXS4eOEkfDgPZHPms/tWGkbGq8A9QpLO8pvefCINSJwnswgXIxCFCzkxUYM6aTP4v1gDaJNq6Lo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=FOaDuGBU; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dBalP4P6; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="FOaDuGBU"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dBalP4P6" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 8BB9711519D0; Tue, 13 Aug 2024 05:13:49 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:13:49 -0400 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=fm3; t=1723540429; x=1723626829; bh=w2UOh0YL7c jCA2fff3BDWRUgHS5FgtCOGQ5CbWeLT4I=; b=FOaDuGBU5yitQTbxkgO1XiKRiA PvO3LPSUtI6APqkQHcVcXMDpkJB9CB4ozdk5eOcyD0mx+VEBzvDX9Ll/y/DXZHse zx2o833t0I95BMiVAKR4UIzTEszdd5K88/rMoKUUt4TKtfbChHUoWtMjERemDJdW h1gH7zV27GePd1gRd4nrUyIF66KfC5INpJCBxk6g5mQqCSha/LUs6SgFYqYiV+zt TuXwIPS4gEICNZhCtN3ybYzqg34XAcM522suQp5T/WclpV02zhY3DeAjIO7m/AP+ /+9AMGWRZChGZ7UpD67ihULfXJrZuJltWMQWlHjcxdyamGIZ0ZcBXcJ8IsnQ== 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= fm3; t=1723540429; x=1723626829; bh=w2UOh0YL7cjCA2fff3BDWRUgHS5F gtCOGQ5CbWeLT4I=; b=dBalP4P6Ol1dcsMSApiR3dV2vQyeIQeDS7LwM8IPmKm1 zBiziT3annN1r2Ymr94BJ4AOxXcpRlol0PSrJiHsLw0wcUCais1syJ3LHrkO0BVB paZ07Udn0Tih/VZVAjLS2jiu08JhXCR5Vjj1yKVhqkt0km1i+VaXqj7CYHUuo7FK uOh6b+htkg2UnboJ0wUfCK4N4gNiFulPJNhrCR+imfhedjFXXpYjb/I77m+xDc+Y EaadYN8/2VoUTLBysDhf/iIv29H4vHaG9bAabN8fJ/S3cszjp8CgMHBtTurYzqRS d9Q5PHMaAoZLL2RY4P5NNO/Kd5X2FYfPFJ+MwVuqLQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c4057ef9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:31 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:46 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 09/20] config: expose `repo_config_clear()` Message-ID: <5e73ef6cec809a3f1009d302b8721b56b048898d.1723540226.git.ps@pks.im> 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: While we already have `repo_config_clear()` as an alternative to `git_config_clear()` that doesn't rely on `the_repository`, it is not exposed to callers outside of the config subsystem. Do so. Signed-off-by: Patrick Steinhardt --- config.c | 2 +- config.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index ac89b708e7..476cd73c9e 100644 --- a/config.c +++ b/config.c @@ -2564,7 +2564,7 @@ static void git_config_check_init(struct repository *repo) repo_read_config(repo); } -static void repo_config_clear(struct repository *repo) +void repo_config_clear(struct repository *repo) { if (!repo->config || !repo->config->hash_initialized) return; diff --git a/config.h b/config.h index b13e1bfb8d..8eb3efa0c4 100644 --- a/config.h +++ b/config.h @@ -651,6 +651,7 @@ int git_config_get_string_multi(const char *key, * Resets and invalidates the config cache. */ void git_config_clear(void); +void repo_config_clear(struct repository *repo); /** * Allocates and copies the retrieved string into the `dest` parameter for From patchwork Tue Aug 13 09:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761613 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 B4C7B17BB34 for ; Tue, 13 Aug 2024 09:13:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540436; cv=none; b=bqZb+eEuFoTGcF+NllzTRz8+GjKFqV1iF3JP0BmXxs/QTKdOxv5BSmwc+nDiJvPJ0iRyR2N3yO6HT6juf4pbiAsH1u0oiSuRkAKr5N82JLRHLR2TZkJD/aYYgHtgnky/ZlBJJnw5ww3uTNH1VmDCK8B1IlChvtiHmyIM+XiwR3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540436; c=relaxed/simple; bh=/EFj+1y8Ny3evhRDxTz1R2Da1BZMxqhDfrZz+KTjA6s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YCn5sO2Q6BMy/5CEJwX8qVVgku11F+W1YL9lp6Utwm2I4RoJ9dQLHFRTD2hpaIhwpcXgZgpYXP+34Yc90tkNoMKCX73GIUhEtn7MFRkfXlxdbjktpRAkBsNH6imWySWkYowdV6M40M2NM9SF0Y/8oqOGaK1L7A8KhzfMOSItMl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=HCVvLRIb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LZZtSgy2; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="HCVvLRIb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LZZtSgy2" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B88D611519D0; Tue, 13 Aug 2024 05:13:53 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 05:13:53 -0400 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=fm3; t=1723540433; x=1723626833; bh=/ZkGNfDzxi G7TcdqMd9hWolC1zRKJSSwqlj0CDgbsL8=; b=HCVvLRIbcnSBLu9p89e/FVEaOW MdtmOIiZhwXiJnv9rtmNpp0wkiKquSpzk3+cT9QBn5xBFTBEIsfhc2VHT7GXQKQo hXTsTc50SOBj84HRyd8p0vHYI4WDlKju7T0xtWaGMeChyFhSskR3kQVkRqpVYDkz E/jSJ8HqNSIo2wPy3lCt6mj6ur9cBHPCcv7slsUbMABiU6cfgzN1bSaxb8WNztub rYnU6YCOY4TB63ge/o+f7w8iMcTVcH+abQGwyCD2m1WMD8siKAgEHTNRA/N1X0sK mGbyHElcpNaj1ceL7vPJrvcK3AMBHl75JUE23mCgL7knozGff+wb/yE3vU+Q== 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= fm3; t=1723540433; x=1723626833; bh=/ZkGNfDzxiG7TcdqMd9hWolC1zRK JSSwqlj0CDgbsL8=; b=LZZtSgy2+NFiuNqJiQvgpOCI9xtWuRn7TCE1uG9VJ3mX 6lp1JgaKTMi64PAwIsyPI4IEOwlW4IW9eKXsYt2oAJ3NPhci+76GRBocigcAqv8j aiS4H++UiyEUQkN4HPRATuAHkiX+HCzUlNTx9ld/bRW5Nwm/5vEwSUxcM/VEoLno 2kUwLDxZrMkhuyaIHALJBLqU0851mIyLqyEfDPbG85xp2DetvwmWaFfSo8b9HsXM vLly6SIpwNJYLV6TlgC3tTwuaAhBvBcXW6XRV8DCU7wxxi31hVYFrHzJuArZOu7A +FDZo6JJsLnlLPEqJrGhClMmbnf0oR5WgZukDblA0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 699f6840 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:36 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:49 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 10/20] config: pass repo to `git_config_get_index_threads()` Message-ID: <35e0f4579cdd17ec098f210e9f00079d412a4180.1723540226.git.ps@pks.im> 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: Refactor `git_config_get_index_threads()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- config.c | 4 ++-- config.h | 2 +- read-cache.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config.c b/config.c index 476cd73c9e..387c7282e9 100644 --- a/config.c +++ b/config.c @@ -2826,7 +2826,7 @@ int git_config_get_max_percent_split_change(void) return -1; /* default value */ } -int git_config_get_index_threads(int *dest) +int repo_config_get_index_threads(struct repository *r, int *dest) { int is_bool, val; @@ -2836,7 +2836,7 @@ int git_config_get_index_threads(int *dest) return 0; } - if (!git_config_get_bool_or_int("index.threads", &is_bool, &val)) { + if (!repo_config_get_bool_or_int(r, "index.threads", &is_bool, &val)) { if (is_bool) *dest = val ? 0 : 1; else diff --git a/config.h b/config.h index 8eb3efa0c4..3f68b30047 100644 --- a/config.h +++ b/config.h @@ -710,7 +710,7 @@ int git_config_get_maybe_bool(const char *key, int *dest); */ int git_config_get_pathname(const char *key, char **dest); -int git_config_get_index_threads(int *dest); +int repo_config_get_index_threads(struct repository *r, int *dest); int git_config_get_split_index(void); int git_config_get_max_percent_split_change(void); diff --git a/read-cache.c b/read-cache.c index 742369b295..ad09950153 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2267,7 +2267,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset = sizeof(*hdr); - if (git_config_get_index_threads(&nr_threads)) + if (repo_config_get_index_threads(the_repository, &nr_threads)) nr_threads = 1; /* TODO: does creating more threads than cores help? */ @@ -2787,7 +2787,7 @@ static int record_eoie(void) * used for threading is written by default if the user * explicitly requested threaded index reads. */ - return !git_config_get_index_threads(&val) && val != 1; + return !repo_config_get_index_threads(the_repository, &val) && val != 1; } static int record_ieot(void) @@ -2802,7 +2802,7 @@ static int record_ieot(void) * written by default if the user explicitly requested * threaded index reads. */ - return !git_config_get_index_threads(&val) && val != 1; + return !repo_config_get_index_threads(the_repository, &val) && val != 1; } enum write_extensions { @@ -2875,7 +2875,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, hashwrite(f, &hdr, sizeof(hdr)); - if (!HAVE_THREADS || git_config_get_index_threads(&nr_threads)) + if (!HAVE_THREADS || repo_config_get_index_threads(the_repository, &nr_threads)) nr_threads = 1; if (nr_threads != 1 && record_ieot()) { From patchwork Tue Aug 13 09:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761614 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 CEC4A183CAD for ; Tue, 13 Aug 2024 09:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540439; cv=none; b=AZJ6fSHCWSl9CNejAPy/E88O0i23bx5tnjf/onYnnU1ZwjXLaPHjkmkxF5BsVY4/kvVRmtS5dcHPqktxJKv6tz+WyoKhTVC60vt8XHF8ppB7NlVmlCZX1HCZbmHs3QlLXSKpEtvSKGwQVW84lTL5x/LnPopkFm+Eiwplzpj4mOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540439; c=relaxed/simple; bh=zlvUGAPy4oWq3QSNpYQEr4743u+yqfkCgaAkMkPOXrg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Mbxq6sdg1frwrBHtL09cc2k88C8DpiOdohhGS+drDZb9jqYkI5SsrEzHrFUGHAO2P8ctBFJWafOrn+yxappXoeUp6yHA0XVzuZ9nOpJXuBunHDyCA5InIFY46QwKOjGvgQYYS22LiX3VlRPMs41uw5pVO3w1pWvUwllWb5Zjjak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Pqg8Ctee; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=pAzVU3gP; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="Pqg8Ctee"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pAzVU3gP" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0049B11519D0; Tue, 13 Aug 2024 05:13:57 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 05:13:56 -0400 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=fm3; t=1723540436; x=1723626836; bh=51DSmygbhj 1ayYq5ZCeWnbo0x7D+1+5hY2Qnjpph0oo=; b=Pqg8CteezqA98nHfOB9bk8t+mW LaTJIHA3IN4X+T55uxRxoKAzaG2TmSZv4Dtcig+5tEbgXEjyUl/rr2bMAp9yoNic D2BjxuPg9AVLGxNzr7ri+eYtSuvppoDviC0IqllJ9q27BTRlM3aHBIfY5sqDFSQE uRpl4xNhXW9it7Lz41BO5HxjX8X9rAdGIiUWmbzlbJKWNxWXpl40/xVI8Y9Lo2Wr l0zJtnUNWnyBFUCwZxYroP0TPIX+EsSGKJsfpuN7sLSXdYPY3vd8qTWu0bDdhCfe /WP/BsszVWEIlxmI65uK/7OGPaWrA7Cau7Ba1tidxoDnnql21E5EJ0qQka0Q== 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= fm3; t=1723540436; x=1723626836; bh=51DSmygbhj1ayYq5ZCeWnbo0x7D+ 1+5hY2Qnjpph0oo=; b=pAzVU3gPH5jkgekC4sxUBrkCkEPmdB3itxbOSFbzFZnK 57Z+9viu7UQbLqZ2k43CAVUBgL12fVohmHQxHY63dmm/YAQ7cBe79DK0RnL5IunV NzgzRNoCKu6fCyMwKp8tsQPkel/KnFJ5eYLqfzF1eqTtrXwU2flEd+qzJbktlxUQ yoLjXAjzyf6mpUMgTWqj3BCSG+An+PCJmTcns7GxlxdiTey5WQ/3yCspDpC133G9 urbLJ/O/e5mD2DDcpgZei9mAXafXOB8FlGdGJsxDxG5COZp/I4LBRC6T1zhLVtbN poRXJV+mWkan5y3bO8N//YlcL1WQsT8+XItPhHhWAg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f0bea408 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:39 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 11/20] config: pass repo to `git_config_get_split_index()` 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: Refactor `git_config_get_split_index()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- builtin/update-index.c | 4 ++-- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index d343416ae2..35a1f957ad 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1156,7 +1156,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) end_odb_transaction(); if (split_index > 0) { - if (git_config_get_split_index() == 0) + if (repo_config_get_split_index(the_repository) == 0) warning(_("core.splitIndex is set to false; " "remove or change it, if you really want to " "enable split index")); @@ -1165,7 +1165,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) else add_split_index(the_repository->index); } else if (!split_index) { - if (git_config_get_split_index() == 1) + if (repo_config_get_split_index(the_repository) == 1) warning(_("core.splitIndex is set to true; " "remove or change it, if you really want to " "disable split index")); diff --git a/config.c b/config.c index 387c7282e9..89fb7ce6b1 100644 --- a/config.c +++ b/config.c @@ -2801,11 +2801,11 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestam return -1; /* thing exists but cannot be parsed */ } -int git_config_get_split_index(void) +int repo_config_get_split_index(struct repository *r) { int val; - if (!git_config_get_maybe_bool("core.splitindex", &val)) + if (!repo_config_get_maybe_bool(r, "core.splitindex", &val)) return val; return -1; /* default value */ diff --git a/config.h b/config.h index 3f68b30047..35cee9d4ca 100644 --- a/config.h +++ b/config.h @@ -711,7 +711,7 @@ int git_config_get_maybe_bool(const char *key, int *dest); int git_config_get_pathname(const char *key, char **dest); int repo_config_get_index_threads(struct repository *r, int *dest); -int git_config_get_split_index(void); +int repo_config_get_split_index(struct repository *r); int git_config_get_max_percent_split_change(void); /* This dies if the configured or default date is in the future */ diff --git a/read-cache.c b/read-cache.c index ad09950153..12c2da5a8b 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1945,7 +1945,7 @@ static void tweak_untracked_cache(struct index_state *istate) static void tweak_split_index(struct index_state *istate) { - switch (git_config_get_split_index()) { + switch (repo_config_get_split_index(the_repository)) { case -1: /* unset: do nothing */ break; case 0: /* false */ From patchwork Tue Aug 13 09:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761615 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 2149118F2FB for ; Tue, 13 Aug 2024 09:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540442; cv=none; b=fSHdzNl69mfHBh/QEDBwBqqFS29uwx3Lc3xYFuYLDToadU6p1wZ1akXVOuuNsLjPHyPzfPtnESr/AT2kqu9+gSeqGTFdM3uqHoMjzDl+ky/0yHfoIGSVMvUP+rem+3nP4ZwvROm5Bnfa4+rp/6/EZA+FgDQhrTSOr7hqeaAkNQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540442; c=relaxed/simple; bh=C3eBMAYgypUrGtw5QbL7nAXFpF6zqaPnqTL//e3y8ww=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UGyQLLc53KHwgiGXnYPjD/o/hD3ihXyYxN78rqtE89SkxVIX8V/Wq9maFZ/NSgv6mRlJX4duweUCx0lWQq/zEV0OvHDKB+W76y/mk8e385AXOQoqSltr5ho6jdzNXAljnY8C8P5jWUMhITlZChCII5CqskCoYVnLSTv7oPiljoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=FnwPZS4i; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KRDFJtzw; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="FnwPZS4i"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KRDFJtzw" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 2BF8F138FACF; Tue, 13 Aug 2024 05:14:00 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 05:14:00 -0400 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=fm3; t=1723540440; x=1723626840; bh=GDh9XV0K/m DiOtIKJJgPmT0KG/3IIc6KBKCE6VEC/98=; b=FnwPZS4iu1LlSW9t6hKFieKiJk VGuNv0Lss3G97M6eBRvylLjw4CFJ7+8Z+RY/cAPEV7zburK6R7i6XLAuOO1dcZaQ OpjkghaG4GMNdy3caK0OWZdlaDxQJgg56PECChPvtWWSfKilpV2iIHSQk+CNyj57 vT07FmfaNbXOLrIL7bwDLgQkh/CBolFF+cGA7BvO4jfmRdX8+IAOwGxAYDEVF/OM tP9OMUtK81vjMCDRf6i3cDo/RVX0Mr9BgOqo52TXZVfPWrgW8zdv2jSJHGQyUlns xlkf2XL+WQjz1RXlKEl14Tk54436V0L0SeL4l3HR4Iuq+9SEGJ6HK9DjFqVA== 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= fm3; t=1723540440; x=1723626840; bh=GDh9XV0K/mDiOtIKJJgPmT0KG/3I Ic6KBKCE6VEC/98=; b=KRDFJtzw+nelXtqRhxtS5VBFnabbuBphUGLvC84cSvC6 nH1EZRQiha2/xcaxNqAR9s43cSBz/a5Sqd9b4bqBsru7iXn1eCDacTKlzTG5TyJX 3AB6e8LGVLq/ZnDmxwVZTozKHxWYeVS0pxZcFCPd5QisZ/xo4M9eyuV42mjV7dMU EIPuHLHfyvcwfh/PTQRxN2uGldx/6a+aQiB4fEEDGUmP4rmpw0tQK2EnfTnAgXYA WnkfYfpMSujP88zHkLUO22lqHvjC0qyWQ90Ax7vLwds7FN1pUGIBZt4C423yr3E8 ujCM2Z/dncnagr4qnB+Rl3DJ+QgpkpO6366dA48khw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:13:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f362fb5a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:42 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 12/20] config: pass repo to `git_config_get_max_percent_split_change()` Message-ID: <17c5420d6386f46a730940de15eed03d2f9db75a.1723540226.git.ps@pks.im> 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: Refactor `git_config_get_max_percent_split_change()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 89fb7ce6b1..f1d2fb6d4c 100644 --- a/config.c +++ b/config.c @@ -2811,11 +2811,11 @@ int repo_config_get_split_index(struct repository *r) return -1; /* default value */ } -int git_config_get_max_percent_split_change(void) +int repo_config_get_max_percent_split_change(struct repository *r) { int val = -1; - if (!git_config_get_int("splitindex.maxpercentchange", &val)) { + if (!repo_config_get_int(r, "splitindex.maxpercentchange", &val)) { if (0 <= val && val <= 100) return val; diff --git a/config.h b/config.h index 35cee9d4ca..dd7127b8e9 100644 --- a/config.h +++ b/config.h @@ -712,7 +712,7 @@ int git_config_get_pathname(const char *key, char **dest); int repo_config_get_index_threads(struct repository *r, int *dest); int repo_config_get_split_index(struct repository *r); -int git_config_get_max_percent_split_change(void); +int repo_config_get_max_percent_split_change(struct repository *r); /* This dies if the configured or default date is in the future */ int git_config_get_expiry(const char *key, const char **output); diff --git a/read-cache.c b/read-cache.c index 12c2da5a8b..1e52db7f36 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3275,7 +3275,7 @@ static const int default_max_percent_split_change = 20; static int too_many_not_shared_entries(struct index_state *istate) { int i, not_shared = 0; - int max_split = git_config_get_max_percent_split_change(); + int max_split = repo_config_get_max_percent_split_change(the_repository); switch (max_split) { case -1: From patchwork Tue Aug 13 09:13:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761616 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 24C5118FDB4 for ; Tue, 13 Aug 2024 09:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540444; cv=none; b=HtmCAABobvarl9dU/6jD4ae0MAE9QJRY7HBXRFz6hJ8C+Ot/Y9ekQXwSdEqZCQ4jMCgjPQR0MYf1Az106D/sRAq21QRVyOIDp0dEOMGN5htP7ROCPaY7CtQVox5HxxsUXScEsN5tiiUCLuGibjHq24xW6hHAHVcFipDoyRsu+YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540444; c=relaxed/simple; bh=wGnkQEbPQt5xiNsTYyKqVM7K+xawWo8C+gyzvjyMCGc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g0b1nf8IAu1+1aF82zQsRHiBtmlh4DHkcvcq+bDY62NqPegqE1yTCGpKC3ButRljLNwYksCN035lOOaiyxibm9GjRFzuw5o7U/Md8O5pJgjVNcimpe1hxM1talplT/1MjIJGwDxrjepxFJInLc1PL2/o4IVWahprNo11prvh45E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=DQKYMn1J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NZk9BTf4; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="DQKYMn1J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NZk9BTf4" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 46D4F1389D07; Tue, 13 Aug 2024 05:14:02 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:14:02 -0400 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=fm3; t=1723540442; x=1723626842; bh=hNglt+326e /ioZE/3bX2D9q7gOFwv1B6eN5eVR8W4Vs=; b=DQKYMn1JxdLNwapsnAwNGV1NqB fcTZ+JPBpdqKWx5qG4j+aC5pYWbbr48cKkOLhyf1I/b5861U16WIqWu75oNZK1/c dqwrXfW6ybiyJ1nHCgSOe1oNcDdHWTUb2I9WqaBQvgWLgEpOh+GMjWPZ+6s2B2hv kND49ejigbcsIhPBqdk+sA1rM77SuSa4SrcTsBsSb3iUQTBoN5rMq2Zrs6qtsg9h EjerozqPRWgVfiYxf5Vs8j9BpRJTbvQERQ4qFtzbUkop3tf0LVE1u19ItlGqLg/2 om4eU5oSNT+IATpb1KZ3qh4vNY/RicSe+xgLfpg0TzjJcZCUoC/p4urMbnKg== 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= fm3; t=1723540442; x=1723626842; bh=hNglt+326e/ioZE/3bX2D9q7gOFw v1B6eN5eVR8W4Vs=; b=NZk9BTf4HW3iRsV9wmvc55kQxO9IGiFGriOTHLd3hfHe NagF9X6imXAkqhmJ1XKFplOrVArX4UJ4IPNKpzCSSKLinO6U9wIY95zHuapv5DV/ ruDuST4zNFs5j5wK+4a51eYq8b2nGaKS/VU9Ns9hUnDTUSH0o94kOs8J92k8ZfLf Ubr7LUG4s4J7hSoQX+JNcRmWKUz3CmIQ1IkKwlOk7CY9HGAxUKMoYsYTC0Cj0G22 d5SDB2q11Ytkzjdcceir2pAqyQRVHsVcWndkRU22Kg0OrhNy1fUch4ASggLDqMoE 11f5YG3SO5658ZRayuSZJMPvlJRuJgg9TstjpAv3Qw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0552e414 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:45 +0000 (UTC) Date: Tue, 13 Aug 2024 11:13:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 13/20] config: pass repo to `git_config_get_expiry()` 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: Refactor `git_config_get_expiry()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- builtin/gc.c | 6 +++--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 2ca6288c6b..dc87c65906 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -167,9 +167,9 @@ static void gc_config(void) git_config_get_bool("gc.autodetach", &detach_auto); git_config_get_bool("gc.cruftpacks", &cruft_packs); git_config_get_ulong("gc.maxcruftsize", &max_cruft_size); - git_config_get_expiry("gc.pruneexpire", &prune_expire); - git_config_get_expiry("gc.worktreepruneexpire", &prune_worktrees_expire); - git_config_get_expiry("gc.logexpiry", &gc_log_expire); + repo_config_get_expiry(the_repository, "gc.pruneexpire", &prune_expire); + repo_config_get_expiry(the_repository, "gc.worktreepruneexpire", &prune_worktrees_expire); + repo_config_get_expiry(the_repository, "gc.logexpiry", &gc_log_expire); git_config_get_ulong("gc.bigpackthreshold", &big_pack_threshold); git_config_get_ulong("pack.deltacachesize", &max_delta_cache_size); diff --git a/config.c b/config.c index f1d2fb6d4c..4138dc50ce 100644 --- a/config.c +++ b/config.c @@ -2766,9 +2766,9 @@ int git_config_get_pathname(const char *key, char **dest) return repo_config_get_pathname(the_repository, key, dest); } -int git_config_get_expiry(const char *key, const char **output) +int repo_config_get_expiry(struct repository *r, const char *key, const char **output) { - int ret = git_config_get_string(key, (char **)output); + int ret = repo_config_get_string(r, key, (char **)output); if (ret) return ret; if (strcmp(*output, "now")) { diff --git a/config.h b/config.h index dd7127b8e9..7674617a1d 100644 --- a/config.h +++ b/config.h @@ -715,7 +715,7 @@ int repo_config_get_split_index(struct repository *r); int repo_config_get_max_percent_split_change(struct repository *r); /* This dies if the configured or default date is in the future */ -int git_config_get_expiry(const char *key, const char **output); +int repo_config_get_expiry(struct repository *r, const char *key, const char **output); /* parse either "this many days" integer, or "5.days.ago" approxidate */ int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now); diff --git a/read-cache.c b/read-cache.c index 1e52db7f36..18394d7180 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3184,8 +3184,8 @@ static unsigned long get_shared_index_expire_date(void) static int shared_index_expire_date_prepared; if (!shared_index_expire_date_prepared) { - git_config_get_expiry("splitindex.sharedindexexpire", - &shared_index_expire); + repo_config_get_expiry(the_repository, "splitindex.sharedindexexpire", + &shared_index_expire); shared_index_expire_date = approxidate(shared_index_expire); shared_index_expire_date_prepared = 1; } From patchwork Tue Aug 13 09:14:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761617 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 44C59184521 for ; Tue, 13 Aug 2024 09:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540448; cv=none; b=EBvXhz3JC2Xzwu+J8DHEcbCH0Hsj8RTWkcJqYcekNnlkn2KhRoJn4G1+z5ociR/pRgSrs1TYGSzLP80+ejDNpG7fraTqa+gN/FIAmOXUlqnu7kKVMIOkJvobfGSKjyTziq4xhQH8QReQO0/Xc1bslXC5TCPrqk/upTlPNNu6z4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540448; c=relaxed/simple; bh=Y8w+L/kVPeGpJYAoD7+TQpwCcWhYaTKygaRpBCibwr0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jxW8UCYi6P8g6Ru8zJ6jU1Wa/D6J7aA9flCmPmeS2g9UNOULhXOxC2C4LqYeqqexuKYSOAo02+AljiU63e4m94CJnU5bEnHlTk5BD4ePUnB3SBxxu2Y8TVSC3493yEyM7FiBHM4VyIAp4neDV4QbOldkepAHzs2wsHJC1biRlFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=ZwHJ1t6n; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eJ/NUtSH; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="ZwHJ1t6n"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eJ/NUtSH" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 7629011519E2; Tue, 13 Aug 2024 05:14:06 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 05:14:06 -0400 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=fm3; t=1723540446; x=1723626846; bh=qIIew3FqMY ULj44Kxta8S0flgiz169fjtM7TNReBSE8=; b=ZwHJ1t6nVdA3VV0u6UgVcHQxFN bIkS+oZuf+b9Dri/AfBdrnvvhGcMrk7a71hZz3N2GSObXWAtRhYUCDeGnLBL3XXc H82viSTO/1zp8+wnhU9TvcYxaX5BLP4Xn7izrFpAliaJOA78gzO8p77eB+Y/gU3a mQJos9BE+aCr+fk3OTIU/8U0H8Jq2xXsLJ3mS17ZSo1MBcDs1HndD1qXBnlAKAj4 GCXHepdsiBq3gvp3lbqeIOSsk6z9zL7SoBBD4R51sIBiCGSdK4TxG3rnKKuw3BnL PjPRNZS7gH0kPwFS1iNb3qBEFnurLuyokNlis69vG/8nbPIFCKxUfVXKYs3A== 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= fm3; t=1723540446; x=1723626846; bh=qIIew3FqMYULj44Kxta8S0flgiz1 69fjtM7TNReBSE8=; b=eJ/NUtSHDJSoUPWlAYQYs1u56iBQF11oVJUGFctMgV0A V2S0eIvoH//xC+Xioyy9kGr5r7kIoibo4M4Qp8Q+AURLgtcuk8U7PHHfKgN+JuCt Vsa/D9OyY0oAPrD/ywHZUy3kLgqwx0G06ajGJ5MZZR4ddj9GV4mpOW9oUwN0KJab m4nFu83Mv634wqtoc67mDbp7cerxcEaepy+jZS78iWx+ir/8UatmWW/cbpNpL/1a QWuxBj3NQpJHHhxJnjcHYc2N25aOPxNMwAxJFCzfwj5KfgMqNIR8EvBIbSYkGgxs YnoJtKiRP+PQJyUzF+r0L/AUaX22Op33ddjt1ewY8w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1f93f7f0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:49 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 14/20] config: pass repo to `git_config_get_expiry_in_days()` Message-ID: <111f77e653a2f67e4f315ba553d65155bbc75066.1723540226.git.ps@pks.im> 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: Refactor `git_config_get_expiry_in_days()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- config.c | 5 +++-- config.h | 3 ++- rerere.c | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config.c b/config.c index 4138dc50ce..33d9af29c8 100644 --- a/config.c +++ b/config.c @@ -2779,13 +2779,14 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **o return ret; } -int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now) +int repo_config_get_expiry_in_days(struct repository *r, const char *key, + timestamp_t *expiry, timestamp_t now) { const char *expiry_string; intmax_t days; timestamp_t when; - if (git_config_get_string_tmp(key, &expiry_string)) + if (repo_config_get_string_tmp(r, key, &expiry_string)) return 1; /* no such thing */ if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) { diff --git a/config.h b/config.h index 7674617a1d..3a5016afea 100644 --- a/config.h +++ b/config.h @@ -718,7 +718,8 @@ int repo_config_get_max_percent_split_change(struct repository *r); int repo_config_get_expiry(struct repository *r, const char *key, const char **output); /* parse either "this many days" integer, or "5.days.ago" approxidate */ -int git_config_get_expiry_in_days(const char *key, timestamp_t *, timestamp_t now); +int repo_config_get_expiry_in_days(struct repository *r, const char *key, + timestamp_t *, timestamp_t now); /** * First prints the error message specified by the caller in `err` and then diff --git a/rerere.c b/rerere.c index 3a3888cce2..578a4fe378 100644 --- a/rerere.c +++ b/rerere.c @@ -1203,8 +1203,10 @@ void rerere_gc(struct repository *r, struct string_list *rr) if (setup_rerere(r, rr, 0) < 0) return; - git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now); - git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now); + repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved", + &cutoff_resolve, now); + repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved", + &cutoff_noresolve, now); git_config(git_default_config, NULL); dir = opendir(git_path("rr-cache")); if (!dir) From patchwork Tue Aug 13 09:14:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761618 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 6A1D5186E5C for ; Tue, 13 Aug 2024 09:14:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540454; cv=none; b=dNXndTp4H5aDHCOxVW+U1wTdcCKy2gl1t63/MRU6lQFuVGjiXnm25gRON8AcHiCBuUC6B9JtZpUwjg02siwQHYzV8XPvC1dmoTEggbtTwMZt4Vdz/Z93DGEZ7h/YKd02LzBX7zRGRIBho80XCrBsW48pD5uM41jYzPuqjzAZDEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540454; c=relaxed/simple; bh=CjJmXta6OcMagX60QqVuqo4FuxM4yGhTJYWk8W1ppfs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m/THdwN2vEbUnUUXZtTK1jf9jnAJv33pFYrsiClevFxKdjw1zMnBRDBc/XKXTCJVx1yVZX4f7SqTLP+t9nY+LlO1FCMyago2IlQlcaUdZJHb5P1a+j5fDfs1zTgkm3DYj6G2dBTSsLGjxMpyZMLoPd3TX57qS7zg6Thbt89drOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=iVj3LapI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SnvHn8UD; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="iVj3LapI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SnvHn8UD" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id 9A356138F115; Tue, 13 Aug 2024 05:14:12 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:14:12 -0400 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=fm3; t=1723540452; x=1723626852; bh=Dkzd5jsWtW K9l3CPcatWP9VXihDnz1pzbC4nawMZKdE=; b=iVj3LapIUimkfqc04aFr/gPaln 9z+4MGXjD0lbweyheNGUD9jYMK+xLu8WWULqWxWadCBmxOODfs0s0kfaY4ea+0PI fYVpLIp5jgpMjSsnJMdkt85tMyJ/Jh3QZ62Yq2ZQg3Bj6FqP/jhbEXUBahQtqPxm UinI26Y8pzd55yHGDiVdfW1q3FYEikEwP0Z9lxQQNGYReqeVO61k3xENXCEMeVkM TTIWDrSogOcZCdbOHNYMqNTlSADb6mdfTp2ej0kofJiMQMXHdSy0EZ/FOziWWa6x 4RsyhYFk5WxLg787s9VTXtMvBEJuLhIZCbTpUIfrbiWYd21tI7AI1oTIGWNQ== 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= fm3; t=1723540452; x=1723626852; bh=Dkzd5jsWtWK9l3CPcatWP9VXihDn z1pzbC4nawMZKdE=; b=SnvHn8UDaIPr4W/DHyRQeMqCo+apVt/aW6x6SGD2G3D2 nKXQ9Q2NK0TR1Ak70965jITazo+iMHCHs0Rwv3bj2OFHO6Wvk/yhgHWWHhGTMTp5 jx0AaGewHg7D3fttvpAL8W27Z7e/2e89Ja3sYxw4SZKafXmKy4NJAPkww6J+ugPK jyPSOXoQW50yyW6RMfmHS448DyrBFvvk+Y9erJ/Zq9FoNyd4YIVnapW5+PCAHjD9 +0387v53oye/WBHWtn9hA4TdsYfBCLZLzHFYeaRQ3/2F74luWlvlyd74+u9Auqjr 2DI7wHa5TITfB4+sIeC0wHl6zZbX3UZCiAxpq9Q9Ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 858ad1d5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:54 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 15/20] config: pass repo to `git_die_config()` Message-ID: <6adee5633a7093f62c7b3041ae23afb528bb9452.1723540226.git.ps@pks.im> 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: Refactor `git_die_config()` to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the function accordingly. Signed-off-by: Patrick Steinhardt --- builtin/fast-import.c | 4 ++-- builtin/notes.c | 2 +- config.c | 12 ++++++------ config.h | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/builtin/fast-import.c b/builtin/fast-import.c index d21c4053a7..0249503c70 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -3481,8 +3481,8 @@ static void git_pack_config(void) if (!git_config_get_int("pack.indexversion", &indexversion_value)) { pack_idx_opts.version = indexversion_value; if (pack_idx_opts.version > 2) - git_die_config("pack.indexversion", - "bad pack.indexVersion=%"PRIu32, pack_idx_opts.version); + git_die_config(the_repository, "pack.indexversion", + "bad pack.indexVersion=%"PRIu32, pack_idx_opts.version); } if (!git_config_get_ulong("pack.packsizelimit", &packsizelimit_value)) max_packsize = packsizelimit_value; diff --git a/builtin/notes.c b/builtin/notes.c index d9c356e354..c0fa86d847 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -868,7 +868,7 @@ static int git_config_get_notes_strategy(const char *key, if (git_config_get_string(key, &value)) return 1; if (parse_notes_merge_strategy(value, strategy)) - git_die_config(key, _("unknown notes merge strategy %s"), value); + git_die_config(the_repository, key, _("unknown notes merge strategy %s"), value); free(value); return 0; diff --git a/config.c b/config.c index 33d9af29c8..e35fc90238 100644 --- a/config.c +++ b/config.c @@ -2611,7 +2611,7 @@ int repo_config_get_string(struct repository *repo, git_config_check_init(repo); ret = git_configset_get_string(repo->config, key, dest); if (ret < 0) - git_die_config(key, NULL); + git_die_config(repo, key, NULL); return ret; } @@ -2622,7 +2622,7 @@ int repo_config_get_string_tmp(struct repository *repo, git_config_check_init(repo); ret = git_configset_get_string_tmp(repo->config, key, dest); if (ret < 0) - git_die_config(key, NULL); + git_die_config(repo, key, NULL); return ret; } @@ -2668,7 +2668,7 @@ int repo_config_get_pathname(struct repository *repo, git_config_check_init(repo); ret = git_configset_get_pathname(repo->config, key, dest); if (ret < 0) - git_die_config(key, NULL); + git_die_config(repo, key, NULL); return ret; } @@ -2774,7 +2774,7 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **o if (strcmp(*output, "now")) { timestamp_t now = approxidate("now"); if (approxidate(*output) >= now) - git_die_config(key, _("Invalid %s: '%s'"), key, *output); + git_die_config(r, key, _("Invalid %s: '%s'"), key, *output); } return ret; } @@ -2858,7 +2858,7 @@ void git_die_config_linenr(const char *key, const char *filename, int linenr) key, filename, linenr); } -void git_die_config(const char *key, const char *err, ...) +void git_die_config(struct repository *r, const char *key, const char *err, ...) { const struct string_list *values; struct key_value_info *kv_info; @@ -2870,7 +2870,7 @@ void git_die_config(const char *key, const char *err, ...) error_fn(err, params); va_end(params); } - if (git_config_get_value_multi(key, &values)) + if (repo_config_get_value_multi(r, key, &values)) BUG("for key '%s' we must have a value to report on", key); kv_info = values->items[values->nr - 1].util; git_die_config_linenr(key, kv_info->filename, kv_info->linenr); diff --git a/config.h b/config.h index 3a5016afea..947307c591 100644 --- a/config.h +++ b/config.h @@ -726,7 +726,8 @@ int repo_config_get_expiry_in_days(struct repository *r, const char *key, * dies printing the line number and the file name of the highest priority * value for the configuration variable `key`. */ -NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); +NORETURN void git_die_config(struct repository *r, const char *key, const char *err, ...) + __attribute__((format(printf, 3, 4))); /** * Helper function which formats the die error message according to the From patchwork Tue Aug 13 09:14:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761619 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 64AF5187849 for ; Tue, 13 Aug 2024 09:14:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540457; cv=none; b=guel7AISAD2DpLPYWMjlOYhQqgB5CQKPacxFj0cWr58fgb6if2SsusBE1W8YtjwqdxGyGffX7TF6xPApAp/ClGcvJFP1eVSzaVf9rUGqjMvverV68pGrMYvIEu3GHIM2iLo2YYy9x2PSe+7jUSHvNMMSZZVvrNuvtLqzwimSx8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540457; c=relaxed/simple; bh=TXEnzdD7jQszQmrzi8NZ0oImfpLCgBM57pZAakXd9Pc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DK6KsGiSwMlHdDDcdVPZ8KNc3o+/s9b0i0Hph84QsimKDcL1FfEf2KN7jAjpZxhBuEB6aBvuBocRIWMmBE10ScjfYB2CeIgBVzSvxXk/Ywbw145Tg1CYWfhFjp2oP0Rfxz5NBaizoDTH/JX5/PBBfXinWqS0g06LQY/Acl8sVvM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=Wwpsl+ae; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ptCvMoLQ; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="Wwpsl+ae"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ptCvMoLQ" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id BBB42138FD0C; Tue, 13 Aug 2024 05:14:14 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:14:14 -0400 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=fm3; t=1723540454; x=1723626854; bh=ykKr/aebco 7WycGOlGM/v04Ua29N7r0VChb7g6bKG7g=; b=Wwpsl+aeOnoeiDz35H3KgfA5iK I5mxS4xvLc12jKRJJlFUOJBzY/G7mKi8tOpNUN85tHn/yVg7Tg21H5c8RSEFtqE+ cVfApiaE92KpR5x5hLNO2qD1NIqKt/QSBD69fD0Mc/b+7/Zd/Huam/68dhQwC4wZ LipKOr0xVgqZIobLkN4idqa+Uh2LelLtEqpIAJfOITTjolbGsa6IFNo26xUUJ/5j 2oz4fzQjl/tEK0r9vUpTrSwtm/NIQjXKQerHts0rPtBF3aKlriG/25L7aRJ8soQD y1T0KISzZUL3aaplPLWMl7trhicOEMScrk2Ehu9+5HZ9HzHib7CvDcdEu8Fw== 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= fm3; t=1723540454; x=1723626854; bh=ykKr/aebco7WycGOlGM/v04Ua29N 7r0VChb7g6bKG7g=; b=ptCvMoLQU9u/WwqoKc8jg2v7o6rGu3joBpQ7bOxe8n2y UTkQRiA/j/EA2vmAzPC30GvQdn6YcY/qbvskfa/m63I0thby3FEBdeZpKjIACEST S19QrzktTXmmyEIemrDuIZOQNgkTQArPjbsNOwxQYUDt3tipjtPazRLlBhHJZffE ztVU7dFMOx/HndLKEMLyZBGEw8FPcGl2d9ulHCNnkppQq9B85BCiWLkzwrlZr2Dn CdLUUChjV9CuUMOnT0O6uNFA7h30pg2lFdeMyY/hWqibn+3MJOUu8od/zJ7+2FaS RtTdOjKAI3iXr6Qi0WYYfMUKLVGeYfiKvCXEAvDJzA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a963195f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:13:57 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 16/20] config: pass repo to functions that rename or copy sections 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: Refactor functions that rename or copy config sections to accept a `struct repository` such that we can get rid of the implicit dependency on `the_repository`. Rename the functions accordingly. Signed-off-by: Patrick Steinhardt --- builtin/branch.c | 7 ++++--- builtin/config.c | 16 ++++++++-------- builtin/remote.c | 4 ++-- builtin/submodule--helper.c | 2 +- config.c | 30 ++++++++++++++++-------------- config.h | 8 ++++---- submodule.c | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index 48cac74f97..3f870741bf 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -210,7 +210,7 @@ static void delete_branch_config(const char *branchname) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "branch.%s", branchname); - if (git_config_rename_section(buf.buf, NULL) < 0) + if (repo_config_rename_section(the_repository, buf.buf, NULL) < 0) warning(_("update of config-file failed")); strbuf_release(&buf); } @@ -659,9 +659,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int strbuf_addf(&oldsection, "branch.%s", interpreted_oldname); strbuf_addf(&newsection, "branch.%s", interpreted_newname); - if (!copy && git_config_rename_section(oldsection.buf, newsection.buf) < 0) + if (!copy && repo_config_rename_section(the_repository, oldsection.buf, newsection.buf) < 0) die(_("branch is renamed, but update of config-file failed")); - if (copy && strcmp(interpreted_oldname, interpreted_newname) && git_config_copy_section(oldsection.buf, newsection.buf) < 0) + if (copy && strcmp(interpreted_oldname, interpreted_newname) && + repo_config_copy_section(the_repository, oldsection.buf, newsection.buf) < 0) die(_("branch is copied, but update of config-file failed")); strbuf_release(&oldref); strbuf_release(&newref); diff --git a/builtin/config.c b/builtin/config.c index 20a0b64090..e00d983596 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1026,8 +1026,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr location_options_init(&location_opts, prefix); check_write(&location_opts.source); - ret = git_config_rename_section_in_file(location_opts.source.file, - argv[0], argv[1]); + ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file, + argv[0], argv[1]); if (ret < 0) goto out; else if (!ret) @@ -1055,8 +1055,8 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr location_options_init(&location_opts, prefix); check_write(&location_opts.source); - ret = git_config_rename_section_in_file(location_opts.source.file, - argv[0], NULL); + ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file, + argv[0], NULL); if (ret < 0) goto out; else if (!ret) @@ -1353,8 +1353,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_RENAME_SECTION) { check_write(&location_opts.source); check_argc(argc, 2, 2); - ret = git_config_rename_section_in_file(location_opts.source.file, - argv[0], argv[1]); + ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file, + argv[0], argv[1]); if (ret < 0) goto out; else if (!ret) @@ -1365,8 +1365,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) else if (actions == ACTION_REMOVE_SECTION) { check_write(&location_opts.source); check_argc(argc, 1, 1); - ret = git_config_rename_section_in_file(location_opts.source.file, - argv[0], NULL); + ret = repo_config_rename_section_in_file(the_repository, location_opts.source.file, + argv[0], NULL); if (ret < 0) goto out; else if (!ret) diff --git a/builtin/remote.c b/builtin/remote.c index 08292498bd..fef3026ef4 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -736,7 +736,7 @@ static int mv(int argc, const char **argv, const char *prefix) strbuf_addf(&buf, "remote.%s", rename.old_name); strbuf_addf(&buf2, "remote.%s", rename.new_name); - if (git_config_rename_section(buf.buf, buf2.buf) < 1) + if (repo_config_rename_section(the_repository, buf.buf, buf2.buf) < 1) return error(_("Could not rename config section '%s' to '%s'"), buf.buf, buf2.buf); @@ -944,7 +944,7 @@ static int rm(int argc, const char **argv, const char *prefix) if (!result) { strbuf_addf(&buf, "remote.%s", remote->name); - if (git_config_rename_section(buf.buf, NULL) < 1) + if (repo_config_rename_section(the_repository, buf.buf, NULL) < 1) return error(_("Could not remove config section '%s'"), buf.buf); handle_push_default(remote->name, NULL); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f1218a1995..662c87c06c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1455,7 +1455,7 @@ static void deinit_submodule(const char *path, const char *prefix, * remove the whole section so we have a clean state when * the user later decides to init this submodule again */ - git_config_rename_section_in_file(NULL, sub_key, NULL); + repo_config_rename_section_in_file(the_repository, NULL, sub_key, NULL); if (!(flags & OPT_QUIET)) printf(_("Submodule '%s' (%s) unregistered for path '%s'\n"), sub->name, sub->url, displaypath); diff --git a/config.c b/config.c index e35fc90238..ed39922dbb 100644 --- a/config.c +++ b/config.c @@ -3697,9 +3697,11 @@ static int section_name_is_ok(const char *name) #define GIT_CONFIG_MAX_LINE_LEN (512 * 1024) /* if new_name == NULL, the section is removed instead */ -static int git_config_copy_or_rename_section_in_file(const char *config_filename, - const char *old_name, - const char *new_name, int copy) +static int repo_config_copy_or_rename_section_in_file( + struct repository *r, + const char *config_filename, + const char *old_name, + const char *new_name, int copy) { int ret = 0, remove = 0; char *filename_buf = NULL; @@ -3720,7 +3722,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename } if (!config_filename) - config_filename = filename_buf = git_pathdup("config"); + config_filename = filename_buf = repo_git_path(r, "config"); out_fd = hold_lock_file_for_update(&lock, config_filename, 0); if (out_fd < 0) { @@ -3863,28 +3865,28 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename return ret; } -int git_config_rename_section_in_file(const char *config_filename, - const char *old_name, const char *new_name) +int repo_config_rename_section_in_file(struct repository *r, const char *config_filename, + const char *old_name, const char *new_name) { - return git_config_copy_or_rename_section_in_file(config_filename, + return repo_config_copy_or_rename_section_in_file(r, config_filename, old_name, new_name, 0); } -int git_config_rename_section(const char *old_name, const char *new_name) +int repo_config_rename_section(struct repository *r, const char *old_name, const char *new_name) { - return git_config_rename_section_in_file(NULL, old_name, new_name); + return repo_config_rename_section_in_file(r, NULL, old_name, new_name); } -int git_config_copy_section_in_file(const char *config_filename, - const char *old_name, const char *new_name) +int repo_config_copy_section_in_file(struct repository *r, const char *config_filename, + const char *old_name, const char *new_name) { - return git_config_copy_or_rename_section_in_file(config_filename, + return repo_config_copy_or_rename_section_in_file(r, config_filename, old_name, new_name, 1); } -int git_config_copy_section(const char *old_name, const char *new_name) +int repo_config_copy_section(struct repository *r, const char *old_name, const char *new_name) { - return git_config_copy_section_in_file(NULL, old_name, new_name); + return repo_config_copy_section_in_file(r, NULL, old_name, new_name); } /* diff --git a/config.h b/config.h index 947307c591..589d6dae26 100644 --- a/config.h +++ b/config.h @@ -392,11 +392,11 @@ void repo_config_set_multivar_in_file(struct repository *r, * If NULL is passed through `new_name` parameter, * the section will be removed from the config file. */ -int git_config_rename_section(const char *, const char *); +int repo_config_rename_section(struct repository *, const char *, const char *); -int git_config_rename_section_in_file(const char *, const char *, const char *); -int git_config_copy_section(const char *, const char *); -int git_config_copy_section_in_file(const char *, const char *, const char *); +int repo_config_rename_section_in_file(struct repository *, const char *, const char *, const char *); +int repo_config_copy_section(struct repository *, const char *, const char *); +int repo_config_copy_section_in_file(struct repository *, const char *, const char *, const char *); int git_config_system(void); int config_error_nonbool(const char *); #if defined(__GNUC__) diff --git a/submodule.c b/submodule.c index ab99a30253..bc04fc8284 100644 --- a/submodule.c +++ b/submodule.c @@ -159,7 +159,7 @@ int remove_path_from_gitmodules(const char *path) } strbuf_addstr(§, "submodule."); strbuf_addstr(§, submodule->name); - if (git_config_rename_section_in_file(GITMODULES_FILE, sect.buf, NULL) < 0) { + if (repo_config_rename_section_in_file(the_repository, GITMODULES_FILE, sect.buf, NULL) < 0) { /* Maybe the user already did that, don't error out here */ warning(_("Could not remove .gitmodules entry for %s"), path); strbuf_release(§); From patchwork Tue Aug 13 09:14:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761620 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 B715E18991F for ; Tue, 13 Aug 2024 09:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540460; cv=none; b=N+RPcZ3kjNoo2w5xW9blcpRshPHIA74UK3s5bKtljoUwtB5tZBvpkeFPfkThW/TefodTHFz7qEKOSchlTxiSwNgMbshmhx1kkfGhsXtxDdbh6yHRgSJWFDePSZvTSM5bxmmIzx4teJGc0UwhMTc4fhEgPutI39mrOdj0tPB38dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540460; c=relaxed/simple; bh=dafDExnyr4VPrErAGqepVfwGaUhRzspv0LxVvDYjTk8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=K6ZanyDiogKHt9ljY9RkTrAMiW+nYKW3p9RwEmOtoOhlWuMr06jE+XgsSEQBTLMdgqNhL3p9m4dwD4nCAt0AjgbS7f2axSbBfa1e8DUiX2Jvr48k3w+tR7tCx8qlVkG0plUzn/n/tVgSE8JCmsKeMeTwCYAMMRd0oyctWUF1wpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=IxhUVgvI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=awAZRgUx; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="IxhUVgvI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="awAZRgUx" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EF8111151A3F; Tue, 13 Aug 2024 05:14:17 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 05:14:17 -0400 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=fm3; t=1723540457; x=1723626857; bh=HdoxSwiiyq gdhLgYYW4NG9g03l0Xs3Locg9m2zIHOnI=; b=IxhUVgvITyIQEc9nFKp+hRuuiw kz7+fhlwXNn4j0jFlB6+4yKwLkiXXPz3KoCT1g1HKZ3basUDZV4KQaBUasiA6+PK 5qaGiVX++xycg7CxgZDEXcVGQrPDh93LY2oqU41jJiypHu+pQz0LnyS8nGNoypO2 2we7mTx2c5bTpr+GoBT1e11jbbZe27U47uus4tw2CrBr9jqABZC9MnUJZFxAb1Mw rzLGudCF15Ylsev4J/tO+0EyNqjNW9QYeY3uPz0RM7veUlWyQeWXwL6h74HF0cal xqc5ckMnt8tP/gNelQLXfmFtJB4XuR976EMJ+PUcdm/YkAwfNwlGeyILeaBg== 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= fm3; t=1723540457; x=1723626857; bh=HdoxSwiiyqgdhLgYYW4NG9g03l0X s3Locg9m2zIHOnI=; b=awAZRgUxQ1slfdQWQ/MmUvSOMtfx8kP71KJupb3PWM8Y QJjK9y+oD+vMaQoYAw5ANsVi7jXOWzv5FDKoJQN5MSWRAkyJmPNX6jrNhsrruB/j SuAN2pmUv8W5IWiDhCQ84sjYnoUOWKqxW9tlEHe0QZuEDJ6RPKUIpYgUJBw9WVms drvFcYfLt0v/RQcXSpjcC3H7l9woxpInerkDvDj4RdgO34PkbYGDlIwRDyqLma3s 714GqdbbnB8FgC8Ka7dJo9j9KdHBAotRN1J+IYt3wAEOWmzi2ZqZyPvJ9ZY4fvJK ljFZkiFcAEUjaKq19yfaX1c7SGEOUw/KKoO7aGjMQw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:16 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e024e10d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:14:00 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 17/20] config: don't have setters depend on `the_repository` Message-ID: <1e5cd92e8ed959e83182a6c422cabb68e02dbc52.1723540226.git.ps@pks.im> 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: Some of the setters that accept a `struct repository` still implicitly rely on `the_repository` via `git_config_set_multivar_in_file()`. While this function would typically use the caller-provided path, it knows to fall back to using the configuration path indicated by `the_repository`. Adapt those functions to instead use the caller-provided repository. Signed-off-by: Patrick Steinhardt --- config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index ed39922dbb..831c9eacb0 100644 --- a/config.c +++ b/config.c @@ -3220,8 +3220,8 @@ int repo_config_set_worktree_gently(struct repository *r, /* Only use worktree-specific config if it is already enabled. */ if (r->repository_format_worktree_config) { char *file = repo_git_path(r, "config.worktree"); - int ret = git_config_set_multivar_in_file_gently( - file, key, value, NULL, NULL, 0); + int ret = repo_config_set_multivar_in_file_gently( + r, file, key, value, NULL, NULL, 0); free(file); return ret; } @@ -3613,10 +3613,10 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); - int res = git_config_set_multivar_in_file_gently(file, - key, value, - value_pattern, - NULL, flags); + int res = repo_config_set_multivar_in_file_gently(r, file, + key, value, + value_pattern, + NULL, flags); free(file); return res; } @@ -3626,8 +3626,8 @@ void repo_config_set_multivar(struct repository *r, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); - git_config_set_multivar_in_file(file, key, value, - value_pattern, flags); + repo_config_set_multivar_in_file(r, file, key, value, + value_pattern, flags); free(file); } From patchwork Tue Aug 13 09:14:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761621 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (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 1595818991F for ; Tue, 13 Aug 2024 09:14:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540463; cv=none; b=uxeaY1taSyuNQZa1RfszueDwLLSUQUZobIN9TXGJdAcDvJO7S6AlyzLON13yBvD/LozWmWhVOzwHmGIO1i7UXwSuWGW8IgMsvDxlXgMKVVANCYEI0mFAsJIJd7glLBS6i7I8tbm6YKm/QYf8Tipe41sp5mqAitEhc6BNOrd8k5E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540463; c=relaxed/simple; bh=TFyZ/b1npDX+JKwnwotH9hxBjjaaWL468V2GggrNXAQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BCL1BYzwbrrYubVcXzqhsL/pWqRzO7tKNpaWBkYNK8sN3mr5Puf0auhK/ZYARmQ/VEXZnqktsn3oFpMH3dp7IInmVHYk3fslOEUPvAMnm6cmWQc2+xD9ehp+5aaMXpkCaMynlDy6QIOwuB3He4ETKnLC54gFqmZzJnU0vjfVydo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=QLd7NW+c; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=P2ibVGc0; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="QLd7NW+c"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="P2ibVGc0" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 25F7711519E2; Tue, 13 Aug 2024 05:14:21 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 05:14:21 -0400 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=fm3; t=1723540461; x=1723626861; bh=nlb5x+Cknl MDZbmdgpGY4wVilZNpwJvB3b3/DzG53as=; b=QLd7NW+cJhq2KeZwEbzpT9D60W z1KGlsP8O9zm5ZmE/hquEfWa2ETubAdZEZsYkB3ife15ctK20VkwOhM7RwdAOQGa +l69wQMtwZq7OztQH97WzJeyvcdzaeDv64vRDLNrU4C7pu+ds+ND/86M6fhM6DCE TuV3sbnO+2PxfK+e3cgFfLAHNdEc87nBJ13mJoWvkkl6MsV1OjvuCB9Qvg98345E W4t2+Wumc/FQf5YBv9ppPK9NM2jJuLKp4d1Xl2K8sL3zVs3IVnkSdc59RKFaKSzr NCuSNqsaPLsI8kqUTgxyXVO593/+wVnL2tK0hs4Oji1MYLW1KaBIy8uJRFrA== 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= fm3; t=1723540461; x=1723626861; bh=nlb5x+CknlMDZbmdgpGY4wVilZNp wJvB3b3/DzG53as=; b=P2ibVGc0su7dXVtxjqRoXfhnUjXWPc6yoDJGC2HmWDzV BU7v//9sWTmIO/W9MtYBz23mj3UFH7n/z+T7uTtzC9pMPwr0DIKcy/Wr3/Ugoy3D deNFSldwRnJpoil3bJydgYhVl5KWqnNOxf1jAzlZcEHI9Ezb6yOB4qhTsxU7d2P6 Zw74TastDzYos74kXP31X+6QDU3NYgMZ6uA2NZ2drZb8Utkjlz8+UFI5RlvLnIZ1 UYTgEUQzBFr8sGwKCcF9sXDmukzegkI4UQ2fmZrG2nRrvkOoCpVPmSfzlsglw2Y3 l+LcP66oaF4MbnHrs6kaC7cNLBKCfjZ4mn3CPDoFlQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5c1ca70a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:14:03 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 18/20] config: don't depend on `the_repository` with branch conditions Message-ID: <96963364e75bb7bbeff0a9be3269b372fdf9a577.1723540226.git.ps@pks.im> 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: When computing branch "includeIf" conditions we use `the_repository` to obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us via `struct config_include_data`. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb. Fix this. Signed-off-by: Patrick Steinhardt --- config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 831c9eacb0..08437f75e5 100644 --- a/config.c +++ b/config.c @@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi, return ret; } -static int include_by_branch(const char *cond, size_t cond_len) +static int include_by_branch(struct config_include_data *data, + const char *cond, size_t cond_len) { int flags; int ret; struct strbuf pattern = STRBUF_INIT; - const char *refname = !the_repository->gitdir ? - NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository), + const char *refname = (!data->repo || !data->repo->gitdir) ? + NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo), "HEAD", 0, NULL, &flags); const char *shortname; @@ -406,7 +407,7 @@ static int include_condition_is_true(const struct key_value_info *kvi, else if (skip_prefix_mem(cond, cond_len, "gitdir/i:", &cond, &cond_len)) return include_by_gitdir(kvi, opts, cond, cond_len, 1); else if (skip_prefix_mem(cond, cond_len, "onbranch:", &cond, &cond_len)) - return include_by_branch(cond, cond_len); + return include_by_branch(inc, cond, cond_len); else if (skip_prefix_mem(cond, cond_len, "hasconfig:remote.*.url:", &cond, &cond_len)) return include_by_remote_url(inc, cond, cond_len); From patchwork Tue Aug 13 09:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761622 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 3A892194C8F for ; Tue, 13 Aug 2024 09:14:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540466; cv=none; b=LJAcGhMmjK8zV1xAdWCnFD6ngpiGQdz/CZ5YY4/Mm4tfeRr9RiVaQzxOa+7fPZ4zEAcnbgeuTadjBKiWGdO/A5kd3L7qI+/KlQLMNsSxNoudSZohoAFetTis2ruDsodGa1miXT3/iDVdsqVggyyzf0b/cvQHVqV4SODBuVTnEsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540466; c=relaxed/simple; bh=VhN2nusBpNsoMcZDNAFmuU6DoxySUd43/Ce+5JS6sGA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WVZE8QUMbVf6/0zPgKRQgrHpuX5XQlD2GWG6HEg+MaHOZKSi3ire3NkYXPIKqWiGCefmN8Dbl7YGystdoL0A4JWAetfVrztv3oOj873RtFyqnyiLBimmiHO4KJd5yCAIn7M2SwEwarai/EIgn8p9gC1f8B40zYevfY1/SxgoQ0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=iGpniZqN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DyC32p+U; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="iGpniZqN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DyC32p+U" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 4E1F21389D07; Tue, 13 Aug 2024 05:14:23 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 05:14:23 -0400 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=fm3; t=1723540463; x=1723626863; bh=MU2tiuBb5o l5NBLzvQpEwX0N5Kc+8hyadx1oWbbrORo=; b=iGpniZqNnRKPN0QLpuOCXg+BP9 g6AUeEuHS98OA/R9Bzwu2WVrDCTVVwkZwsIi2nGPCgQytw8RgJ0X/vh1f3HQIZNk lCGXaUsSwBhkCrMeyGnS3vJ3ku1Am9z1CsG2uycVQWbotUUkYQNeURHO0DR/1v1b YIJvxHqgtPR0COkR4XOjAfejWO8D8r74l5XSXgQwgpFrPmCPrnQZ6F/yx58auNQb X02wN3DtYH1WWb79YmmxfCtOyQnQ83iIJo+7O28Nz3Tsd4rp6ckWqyZZwyFeoRae 2liZ3jWHiRgrLXPsgSUbuiXOlAdfffl6/7yerZEb2NKcyA4WkoS9zz2Uht5A== 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= fm3; t=1723540463; x=1723626863; bh=MU2tiuBb5ol5NBLzvQpEwX0N5Kc+ 8hyadx1oWbbrORo=; b=DyC32p+UBkEi/xGC9cPbfX/vlfndwhchIMWrFBiBzN4G 37kOoxD50bqxO2qSc6qBpk6U+M4BMIOnGADb2Bt/oQUXWM6ofIXj/T2uU1r/doQj lPlgix6pHfNvRo8LVaPs41Vr5G1WIzOBcPOPkLG8cLrjoUDUS97KS7DILxnz61/Q 6C9Hv8KV+SFZeLIJgfOUgTdovKGHUaoGmFKKrY8gLmg2Xy7nK1wwe45FbT031Egb s5ThSGpSriDlVH7Gf9UpL+6nzUz7sPl4iGwexRlTVSuKgGeY8JanVQJm9cHUuiB5 SE188RFyxMxjzq2F9CkcsnSQSAUfrlYvZbWd5Tr0sA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepieduieeitdehieeutdejudehkedvgfejudefgfeiuefg jeekudegfefgffeftdehnecuffhomhgrihhnpehgnhhurdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgs pghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithhsth gvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghl rdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id f9d29248 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:14:06 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 19/20] global: prepare for hiding away repo-less config functions Message-ID: <124f5794e6677da0ca3cac1e90c381ebb43fdca6.1723540226.git.ps@pks.im> 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: We're about to hide config functions that implicitly depend on `the_repository` behind the `USE_THE_REPOSITORY_VARIABLE` macro. This will uncover a bunch of dependents that transitively relied on the global variable, but didn't define the macro yet. Adapt them such that we define the macro to prepare for this change. Signed-off-by: Patrick Steinhardt --- compat/fsmonitor/fsm-ipc-darwin.c | 2 ++ compat/precompose_utf8.c | 1 + connect.c | 2 ++ credential.c | 2 ++ daemon.c | 2 ++ editor.c | 2 ++ fsmonitor.c | 2 ++ gpg-interface.c | 2 ++ graph.c | 2 ++ imap-send.c | 2 ++ mailinfo.c | 2 ++ merge-ll.c | 2 ++ parallel-checkout.c | 2 ++ protocol.c | 2 ++ refs.c | 2 ++ refs/packed-backend.c | 2 ++ refs/reftable-backend.c | 2 ++ sideband.c | 2 ++ t/helper/test-advise.c | 2 ++ t/helper/test-config.c | 2 ++ t/helper/test-userdiff.c | 2 ++ trailer.c | 2 ++ versioncmp.c | 2 ++ 23 files changed, 45 insertions(+) diff --git a/compat/fsmonitor/fsm-ipc-darwin.c b/compat/fsmonitor/fsm-ipc-darwin.c index 52f4f29720..fe149a1b37 100644 --- a/compat/fsmonitor/fsm-ipc-darwin.c +++ b/compat/fsmonitor/fsm-ipc-darwin.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "gettext.h" diff --git a/compat/precompose_utf8.c b/compat/precompose_utf8.c index 0bd5c24250..f7cc7b3be5 100644 --- a/compat/precompose_utf8.c +++ b/compat/precompose_utf8.c @@ -4,6 +4,7 @@ */ #define PRECOMPOSE_UNICODE_C +#define USE_THE_REPOSITORY_VARIABLE #include "git-compat-util.h" #include "config.h" diff --git a/connect.c b/connect.c index cf84e631e9..6829ab3974 100644 --- a/connect.c +++ b/connect.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "environment.h" diff --git a/credential.c b/credential.c index 4b1a2b94fe..ee46351ce0 100644 --- a/credential.c +++ b/credential.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "config.h" diff --git a/daemon.c b/daemon.c index 17d331b2f3..c65b068b76 100644 --- a/daemon.c +++ b/daemon.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "config.h" diff --git a/editor.c b/editor.c index e93b4fdb09..6b9ce81d5f 100644 --- a/editor.c +++ b/editor.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "advice.h" diff --git a/fsmonitor.c b/fsmonitor.c index 2b17d60bbb..28130f748f 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "dir.h" diff --git a/gpg-interface.c b/gpg-interface.c index 5c824aeb25..6587085cd1 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "commit.h" #include "config.h" diff --git a/graph.c b/graph.c index 1ca34770ee..091c14cf4f 100644 --- a/graph.c +++ b/graph.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "gettext.h" #include "config.h" diff --git a/imap-send.c b/imap-send.c index 01404e5047..b2eb3d2dd0 100644 --- a/imap-send.c +++ b/imap-send.c @@ -21,6 +21,8 @@ * along with this program; if not, see . */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "credential.h" diff --git a/mailinfo.c b/mailinfo.c index 94b9b0abf2..95228531a6 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "gettext.h" diff --git a/merge-ll.c b/merge-ll.c index 180c19df67..badb6dea57 100644 --- a/merge-ll.c +++ b/merge-ll.c @@ -4,6 +4,8 @@ * Copyright (c) 2007 Junio C Hamano */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "convert.h" diff --git a/parallel-checkout.c b/parallel-checkout.c index 08b960aac8..01736f1352 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "entry.h" diff --git a/protocol.c b/protocol.c index 079ba75acf..bae7226ff4 100644 --- a/protocol.c +++ b/protocol.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "environment.h" diff --git a/refs.c b/refs.c index 0afc70b51b..284c64dfc5 100644 --- a/refs.c +++ b/refs.c @@ -2,6 +2,8 @@ * The backend-independent part of the reference module. */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "advice.h" #include "config.h" diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 89976aa359..ba2ad90d10 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../git-compat-util.h" #include "../config.h" #include "../dir.h" diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index bf4446afd3..df67923d21 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../git-compat-util.h" #include "../abspath.h" #include "../chdir-notify.h" diff --git a/sideband.c b/sideband.c index 5d8907151f..5b6b872a1c 100644 --- a/sideband.c +++ b/sideband.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "color.h" #include "config.h" diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c index 8a3fd0009a..6967c8e25c 100644 --- a/t/helper/test-advise.c +++ b/t/helper/test-advise.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "test-tool.h" #include "advice.h" #include "config.h" diff --git a/t/helper/test-config.c b/t/helper/test-config.c index ed444ca4c2..e193079ed5 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "test-tool.h" #include "config.h" #include "setup.h" diff --git a/t/helper/test-userdiff.c b/t/helper/test-userdiff.c index 0ce31ce59f..94c48ababb 100644 --- a/t/helper/test-userdiff.c +++ b/t/helper/test-userdiff.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "test-tool.h" #include "setup.h" #include "userdiff.h" diff --git a/trailer.c b/trailer.c index 72e5136c73..682d74505b 100644 --- a/trailer.c +++ b/trailer.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "environment.h" diff --git a/versioncmp.c b/versioncmp.c index 45e676cbca..e3b2a6e330 100644 --- a/versioncmp.c +++ b/versioncmp.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "strbuf.h" From patchwork Tue Aug 13 09:14:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761623 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 358FA197A61 for ; Tue, 13 Aug 2024 09:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540469; cv=none; b=jpciSmCX3Yf69IXZzT69snyr8jvDX77jBNpDzRFIueiqAw44vSid2FQ/uY2YgVGfwiq1hnS4lV9fIfYP5e2ZKzNafPhUD7/61snLJo9gVXrHDLtZfq352Cbcuk1tn1HnkHVsfV2dPJWwc3oPujD+esQzM1yzBce748M5gq7A4Pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723540469; c=relaxed/simple; bh=vcvJ2gU0T4725WY1W+MvMV+AevxExkj4K0ujkx/K0aI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NXCdjC51/lQ7opjSi1ttgY9YQMiaJdv2exHlmdpUVrVIAt+dQondD8p6oFeD+siCMs2AdMyCxzDfd3olbgcUi09gjZaTl9GafDE2bbw2xc2K1r0TRUxUqZSS9YzWnX8VNjNT13ieKgn8UPvzwBKXI0nk2EEmHULb8rTPAvmrM7w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=CA8D75w0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Gja20jwD; arc=none smtp.client-ip=103.168.172.145 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject 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="CA8D75w0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Gja20jwD" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 7D7D31389D07; Tue, 13 Aug 2024 05:14:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 05:14:26 -0400 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=fm3; t=1723540466; x=1723626866; bh=Vd/lrhpHZL Tb4FWCV6kvAck7ro2/ITBtYZQThYlMsfU=; b=CA8D75w0W63sFVEfGaOJ8mHLBO /5hNNYSE8r6mjxTVil28iVM1uM0Nef30D8SKgLGotDyYVGytMVDHiRZC8bWoYZ6A 2yOGd2vfYL8VfDbOgfTULZJYrDjKeFnHTf42uukXbIiLTScZ4K4NsueekaS9qbNf PY3nEWoUDRjul3jBRU/el1R4u3vZZJ4sC48VkOywCoWQSaIQd9E0feL4PGSrhMpD O2bRVv+WXPkc5Flt37CJMDG+T5eyR71uf7NffTNUGJQI1cERv/2jNy7x8mZibMAk FQfcbxwXpdvThgGICtbJ2IMiFAg5reqA/4ojxvWvGmeXh+NvyAfUuW8rL+jQ== 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= fm3; t=1723540466; x=1723626866; bh=Vd/lrhpHZLTb4FWCV6kvAck7ro2/ ITBtYZQThYlMsfU=; b=Gja20jwDihTAOnfF52UD1HIUPI5k74I/dFKlDtBsodue s6ZrtbWbgjIoNDb4tSQlXcX4nj3gJOPT7smZtIOB14d5RHfd8/flVT+AObA0htXx yLq8j6KVptpbHRd1rUIix7haxd5n8he/48bU3OwVTiwMb8wGY935EfnsQkH9eOs1 B1vX9AMLqR+I6G72fkLeKd5J9tyOJ6loXCzFW7oW77iu+TPzUOwEj2OjRWVEUtm5 JoU/jjQpJytKPI80XxaG28rin4hfTOHMGSpyLJ+DqVvVBvyN9Lft0munRI+Ev6S/ bvEpK2z5G6wVAsaTykU0i0a+6GOz0Hju3DQR6FrnPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtvddguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepfedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 05:14:25 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 237fa457 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Aug 2024 09:14:09 +0000 (UTC) Date: Tue, 13 Aug 2024 11:14:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Justin Tobler , Junio C Hamano Subject: [PATCH v2 20/20] config: hide functions using `the_repository` by default Message-ID: <467cd481f54e6e8735a221482e435e3cd5419291.1723540226.git.ps@pks.im> 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: The config subsystem provides a bunch of legacy functions that read or set configuration for `the_repository`. The use of those functions is discouraged, and it is easy to miss the implicit dependency on `the_repository` that calls to those functions may cause. Move all config-related functions that use `the_repository` into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "config.c", allowing us to remove the definition of said preprocessor macro. Signed-off-by: Patrick Steinhardt --- config.c | 130 ----------------------------- config.h | 249 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 171 insertions(+), 208 deletions(-) diff --git a/config.c b/config.c index 08437f75e5..c4fdbf6e1b 100644 --- a/config.c +++ b/config.c @@ -6,8 +6,6 @@ * */ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "advice.h" @@ -2695,78 +2693,6 @@ void git_protected_config(config_fn_t fn, void *data) configset_iter(&protected_config, fn, data); } -/* Functions used historically to read configuration from 'the_repository' */ -void git_config(config_fn_t fn, void *data) -{ - repo_config(the_repository, fn, data); -} - -void git_config_clear(void) -{ - repo_config_clear(the_repository); -} - -int git_config_get(const char *key) -{ - return repo_config_get(the_repository, key); -} - -int git_config_get_value(const char *key, const char **value) -{ - return repo_config_get_value(the_repository, key, value); -} - -int git_config_get_value_multi(const char *key, const struct string_list **dest) -{ - return repo_config_get_value_multi(the_repository, key, dest); -} - -int git_config_get_string_multi(const char *key, - const struct string_list **dest) -{ - return repo_config_get_string_multi(the_repository, key, dest); -} - -int git_config_get_string(const char *key, char **dest) -{ - return repo_config_get_string(the_repository, key, dest); -} - -int git_config_get_string_tmp(const char *key, const char **dest) -{ - return repo_config_get_string_tmp(the_repository, key, dest); -} - -int git_config_get_int(const char *key, int *dest) -{ - return repo_config_get_int(the_repository, key, dest); -} - -int git_config_get_ulong(const char *key, unsigned long *dest) -{ - return repo_config_get_ulong(the_repository, key, dest); -} - -int git_config_get_bool(const char *key, int *dest) -{ - return repo_config_get_bool(the_repository, key, dest); -} - -int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest) -{ - return repo_config_get_bool_or_int(the_repository, key, is_bool, dest); -} - -int git_config_get_maybe_bool(const char *key, int *dest) -{ - return repo_config_get_maybe_bool(the_repository, key, dest); -} - -int git_config_get_pathname(const char *key, char **dest) -{ - return repo_config_get_pathname(the_repository, key, dest); -} - int repo_config_get_expiry(struct repository *r, const char *key, const char **output) { int ret = repo_config_get_string(r, key, (char **)output); @@ -3186,35 +3112,17 @@ int repo_config_set_in_file_gently(struct repository *r, const char *config_file return repo_config_set_multivar_in_file_gently(r, config_filename, key, value, NULL, comment, 0); } -int git_config_set_in_file_gently(const char *config_filename, - const char *key, const char *comment, const char *value) -{ - return repo_config_set_in_file_gently(the_repository, config_filename, - key, comment, value); -} - void repo_config_set_in_file(struct repository *r, const char *config_filename, const char *key, const char *value) { repo_config_set_multivar_in_file(r, config_filename, key, value, NULL, 0); } -void git_config_set_in_file(const char *config_filename, - const char *key, const char *value) -{ - repo_config_set_in_file(the_repository, config_filename, key, value); -} - int repo_config_set_gently(struct repository *r, const char *key, const char *value) { return repo_config_set_multivar_gently(r, key, value, NULL, 0); } -int git_config_set_gently(const char *key, const char *value) -{ - return repo_config_set_gently(the_repository, key, value); -} - int repo_config_set_worktree_gently(struct repository *r, const char *key, const char *value) { @@ -3236,11 +3144,6 @@ void repo_config_set(struct repository *r, const char *key, const char *value) trace2_cmd_set_config(key, value); } -void git_config_set(const char *key, const char *value) -{ - repo_config_set(the_repository, key, value); -} - char *git_config_prepare_comment_string(const char *comment) { size_t leading_blanks; @@ -3569,17 +3472,6 @@ int repo_config_set_multivar_in_file_gently(struct repository *r, goto out_free; } -int git_config_set_multivar_in_file_gently(const char *config_filename, - const char *key, const char *value, - const char *value_pattern, - const char *comment, - unsigned flags) -{ - return repo_config_set_multivar_in_file_gently(the_repository, config_filename, - key, value, value_pattern, - comment, flags); -} - void repo_config_set_multivar_in_file(struct repository *r, const char *config_filename, const char *key, const char *value, @@ -3594,21 +3486,6 @@ void repo_config_set_multivar_in_file(struct repository *r, die(_("could not unset '%s'"), key); } -void git_config_set_multivar_in_file(const char *config_filename, - const char *key, const char *value, - const char *value_pattern, unsigned flags) -{ - repo_config_set_multivar_in_file(the_repository, config_filename, - key, value, value_pattern, flags); -} - -int git_config_set_multivar_gently(const char *key, const char *value, - const char *value_pattern, unsigned flags) -{ - return repo_config_set_multivar_gently(the_repository, key, value, - value_pattern, flags); -} - int repo_config_set_multivar_gently(struct repository *r, const char *key, const char *value, const char *value_pattern, unsigned flags) @@ -3632,13 +3509,6 @@ void repo_config_set_multivar(struct repository *r, free(file); } -void git_config_set_multivar(const char *key, const char *value, - const char *value_pattern, unsigned flags) -{ - repo_config_set_multivar(the_repository, key, value, - value_pattern, flags); -} - static size_t section_name_match (const char *buf, const char *name) { size_t i = 0, j = 0; diff --git a/config.h b/config.h index 589d6dae26..4d319a4193 100644 --- a/config.h +++ b/config.h @@ -26,7 +26,7 @@ struct object_id; /* git_config_parse_key() returns these negated: */ #define CONFIG_INVALID_KEY 1 #define CONFIG_NO_SECTION_OR_NAME 2 -/* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */ +/* repo_config_set_gently(), repo_config_set_multivar_gently() return the above or these: */ #define CONFIG_NO_LOCK -1 #define CONFIG_INVALID_FILE 3 #define CONFIG_NO_WRITE 4 @@ -170,9 +170,9 @@ int git_default_config(const char *, const char *, /** * Read a specific file in git-config format. - * This function takes the same callback and data parameters as `git_config`. + * This function takes the same callback and data parameters as `repo_config`. * - * Unlike git_config(), this function does not respect includes. + * Unlike repo_config(), this function does not respect includes. */ int git_config_from_file(config_fn_t fn, const char *, void *); @@ -198,9 +198,9 @@ void read_very_early_config(config_fn_t cb, void *data); /** * Most programs will simply want to look up variables in all config files * that Git knows about, using the normal precedence rules. To do this, - * call `git_config` with a callback function and void data pointer. + * call `repo_config` with a callback function and void data pointer. * - * `git_config` will read all config sources in order of increasing + * `repo_config` will read all config sources in order of increasing * priority. Thus a callback should typically overwrite previously-seen * entries with new ones (e.g., if both the user-wide `~/.gitconfig` and * repo-specific `.git/config` contain `color.ui`, the config machinery @@ -210,11 +210,11 @@ void read_very_early_config(config_fn_t cb, void *data); * * Unlike git_config_from_file(), this function respects includes. */ -void git_config(config_fn_t fn, void *); +void repo_config(struct repository *r, config_fn_t fn, void *); /** * Lets the caller examine config while adjusting some of the default - * behavior of `git_config`. It should almost never be used by "regular" + * behavior of `repo_config`. It should almost never be used by "regular" * Git code that is looking up configuration variables. * It is intended for advanced callers like `git-config`, which are * intentionally tweaking the normal config-lookup process. @@ -223,12 +223,12 @@ void git_config(config_fn_t fn, void *); * - `config_source` * If this parameter is non-NULL, it specifies the source to parse for * configuration, rather than looking in the usual files. See `struct - * git_config_source` in `config.h` for details. Regular `git_config` defaults + * git_config_source` in `config.h` for details. Regular `repo_config` defaults * to `NULL`. * * - `opts` * Specify options to adjust the behavior of parsing config files. See `struct - * config_options` in `config.h` for details. As an example: regular `git_config` + * config_options` in `config.h` for details. As an example: regular `repo_config` * sets `opts.respect_includes` to `1` by default. */ int config_with_options(config_fn_t fn, void *, @@ -297,7 +297,6 @@ int git_config_pathname(char **, const char *, const char *); int git_config_expiry_date(timestamp_t *, const char *, const char *); int git_config_color(char *, const char *, const char *); -int git_config_set_in_file_gently(const char *, const char *, const char *, const char *); int repo_config_set_in_file_gently(struct repository *r, const char *config_filename, const char *key, const char *comment, const char *value); @@ -305,10 +304,8 @@ int repo_config_set_in_file_gently(struct repository *r, const char *config_file * write config values to a specific config file, takes a key/value pair as * parameter. */ -void git_config_set_in_file(const char *, const char *, const char *); void repo_config_set_in_file(struct repository *, const char *, const char *, const char *); -int git_config_set_gently(const char *, const char *); int repo_config_set_gently(struct repository *r, const char *, const char *); /** @@ -321,14 +318,13 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha /** * write config values to `.git/config`, takes a key/value pair as parameter. */ -void git_config_set(const char *, const char *); void repo_config_set(struct repository *, const char *, const char *); int git_config_parse_key(const char *, char **, size_t *); /* * The following macros specify flag bits that alter the behavior - * of the git_config_set_multivar*() methods. + * of the repo_config_set_multivar*() methods. */ /* @@ -345,11 +341,8 @@ int git_config_parse_key(const char *, char **, size_t *); */ #define CONFIG_FLAGS_FIXED_VALUE (1 << 1) -int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned); int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned); -void git_config_set_multivar(const char *, const char *, const char *, unsigned); void repo_config_set_multivar(struct repository *r, const char *, const char *, const char *, unsigned); -int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, const char *, unsigned); int repo_config_set_multivar_in_file_gently(struct repository *, const char *, const char *, const char *, const char *, const char *, unsigned); char *git_config_prepare_comment_string(const char *); @@ -374,11 +367,6 @@ char *git_config_prepare_comment_string(const char *); * * It returns 0 on success. */ -void git_config_set_multivar_in_file(const char *config_filename, - const char *key, - const char *value, - const char *value_pattern, - unsigned flags); void repo_config_set_multivar_in_file(struct repository *r, const char *config_filename, const char *key, @@ -563,39 +551,11 @@ int git_configset_get_bool_or_int(struct config_set *cs, const char *key, int *i int git_configset_get_maybe_bool(struct config_set *cs, const char *key, int *dest); int git_configset_get_pathname(struct config_set *cs, const char *key, char **dest); -/* Functions for reading a repository's config */ -struct repository; -void repo_config(struct repository *repo, config_fn_t fn, void *data); - /** * Run only the discover part of the repo_config_get_*() functions * below, in addition to 1 if not found, returns negative values on * error (e.g. if the key itself is invalid). */ -RESULT_MUST_BE_USED -int repo_config_get(struct repository *repo, const char *key); -int repo_config_get_value(struct repository *repo, - const char *key, const char **value); -RESULT_MUST_BE_USED -int repo_config_get_value_multi(struct repository *repo, const char *key, - const struct string_list **dest); -RESULT_MUST_BE_USED -int repo_config_get_string_multi(struct repository *repo, const char *key, - const struct string_list **dest); -int repo_config_get_string(struct repository *repo, - const char *key, char **dest); -int repo_config_get_string_tmp(struct repository *repo, - const char *key, const char **dest); -int repo_config_get_int(struct repository *repo, - const char *key, int *dest); -int repo_config_get_ulong(struct repository *repo, - const char *key, unsigned long *dest); -int repo_config_get_bool(struct repository *repo, - const char *key, int *dest); -int repo_config_get_bool_or_int(struct repository *repo, - const char *key, int *is_bool, int *dest); -int repo_config_get_maybe_bool(struct repository *repo, - const char *key, int *dest); int repo_config_get_pathname(struct repository *repo, const char *key, char **dest); @@ -611,17 +571,17 @@ void git_protected_config(config_fn_t fn, void *data); * ------------------------------- * * For programs wanting to query for specific variables in a non-callback - * manner, the config API provides two functions `git_config_get_value` - * and `git_config_get_value_multi`. They both read values from an internal + * manner, the config API provides two functions `repo_config_get_value` + * and `repo_config_get_value_multi`. They both read values from an internal * cache generated previously from reading the config files. * - * For those git_config_get*() functions that aren't documented, + * For those repo_config_get*() functions that aren't documented, * consult the corresponding repo_config_get*() function's * documentation. */ RESULT_MUST_BE_USED -int git_config_get(const char *key); +int repo_config_get(struct repository *r, const char *key); /** * Finds the highest-priority value for the configuration variable `key`, @@ -630,7 +590,7 @@ int git_config_get(const char *key); * `value`. The caller should not free or modify `value`, as it is owned * by the cache. */ -int git_config_get_value(const char *key, const char **value); +int repo_config_get_value(struct repository *r, const char *key, const char **value); /** * Finds and returns the value list, sorted in order of increasing priority @@ -641,16 +601,15 @@ int git_config_get_value(const char *key, const char **value); * owned by the cache. */ RESULT_MUST_BE_USED -int git_config_get_value_multi(const char *key, - const struct string_list **dest); -RESULT_MUST_BE_USED -int git_config_get_string_multi(const char *key, +int repo_config_get_value_multi(struct repository *r, const char *key, const struct string_list **dest); +RESULT_MUST_BE_USED +int repo_config_get_string_multi(struct repository *r, const char *key, + const struct string_list **dest); /** * Resets and invalidates the config cache. */ -void git_config_clear(void); void repo_config_clear(struct repository *repo); /** @@ -659,14 +618,15 @@ void repo_config_clear(struct repository *repo); * error message and returns -1. When the configuration variable `key` is * not found, returns 1 without touching `dest`. */ -int git_config_get_string(const char *key, char **dest); +int repo_config_get_string(struct repository *r, const char *key, char **dest); /** - * Similar to `git_config_get_string`, but does not allocate any new + * Similar to `repo_config_get_string`, but does not allocate any new * memory; on success `dest` will point to memory owned by the config * machinery, which could be invalidated if it is discarded and reloaded. */ -int git_config_get_string_tmp(const char *key, const char **dest); +int repo_config_get_string_tmp(struct repository *r, + const char *key, const char **dest); /** * Finds and parses the value to an integer for the configuration variable @@ -674,12 +634,13 @@ int git_config_get_string_tmp(const char *key, const char **dest); * `dest` and returns 0. When the configuration variable `key` is not found, * returns 1 without touching `dest`. */ -int git_config_get_int(const char *key, int *dest); +int repo_config_get_int(struct repository *r, const char *key, int *dest); /** - * Similar to `git_config_get_int` but for unsigned longs. + * Similar to `repo_config_get_int` but for unsigned longs. */ -int git_config_get_ulong(const char *key, unsigned long *dest); +int repo_config_get_ulong(struct repository *r, + const char *key, unsigned long *dest); /** * Finds and parses the value into a boolean value, for the configuration @@ -690,25 +651,21 @@ int git_config_get_ulong(const char *key, unsigned long *dest); * configuration variable `key` is not found, returns 1 without touching * `dest`. */ -int git_config_get_bool(const char *key, int *dest); +int repo_config_get_bool(struct repository *r, const char *key, int *dest); /** - * Similar to `git_config_get_bool`, except that integers are copied as-is, + * Similar to `repo_config_get_bool`, except that integers are copied as-is, * and `is_bool` flag is unset. */ -int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest); +int repo_config_get_bool_or_int(struct repository *r, const char *key, + int *is_bool, int *dest); /** - * Similar to `git_config_get_bool`, except that it returns -1 on error + * Similar to `repo_config_get_bool`, except that it returns -1 on error * rather than dying. */ -int git_config_get_maybe_bool(const char *key, int *dest); - -/** - * Similar to `git_config_get_string`, but expands `~` or `~user` into - * the user's home directory when found at the beginning of the path. - */ -int git_config_get_pathname(const char *key, char **dest); +int repo_config_get_maybe_bool(struct repository *r, + const char *key, int *dest); int repo_config_get_index_threads(struct repository *r, int *dest); int repo_config_get_split_index(struct repository *r); @@ -732,7 +689,7 @@ NORETURN void git_die_config(struct repository *r, const char *key, const char * /** * Helper function which formats the die error message according to the * parameters entered. Used by `git_die_config()`. It can be used by callers - * handling `git_config_get_value_multi()` to print the correct error message + * handling `repo_config_get_value_multi()` to print the correct error message * for the desired value. */ NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr); @@ -741,4 +698,140 @@ NORETURN void git_die_config_linenr(const char *key, const char *filename, int l lookup_config(mapping, ARRAY_SIZE(mapping), var) int lookup_config(const char **mapping, int nr_mapping, const char *var); +# ifdef USE_THE_REPOSITORY_VARIABLE +static inline void git_config(config_fn_t fn, void *data) +{ + repo_config(the_repository, fn, data); +} + +static inline void git_config_clear(void) +{ + repo_config_clear(the_repository); +} + +static inline int git_config_get(const char *key) +{ + return repo_config_get(the_repository, key); +} + +static inline int git_config_get_value(const char *key, const char **value) +{ + return repo_config_get_value(the_repository, key, value); +} + +static inline int git_config_get_value_multi(const char *key, const struct string_list **dest) +{ + return repo_config_get_value_multi(the_repository, key, dest); +} + +static inline int git_config_get_string_multi(const char *key, + const struct string_list **dest) +{ + return repo_config_get_string_multi(the_repository, key, dest); +} + +static inline int git_config_get_string(const char *key, char **dest) +{ + return repo_config_get_string(the_repository, key, dest); +} + +static inline int git_config_get_string_tmp(const char *key, const char **dest) +{ + return repo_config_get_string_tmp(the_repository, key, dest); +} + +static inline int git_config_get_int(const char *key, int *dest) +{ + return repo_config_get_int(the_repository, key, dest); +} + +static inline int git_config_get_ulong(const char *key, unsigned long *dest) +{ + return repo_config_get_ulong(the_repository, key, dest); +} + +static inline int git_config_get_bool(const char *key, int *dest) +{ + return repo_config_get_bool(the_repository, key, dest); +} + +static inline int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest) +{ + return repo_config_get_bool_or_int(the_repository, key, is_bool, dest); +} + +static inline int git_config_get_maybe_bool(const char *key, int *dest) +{ + return repo_config_get_maybe_bool(the_repository, key, dest); +} + +static inline int git_config_get_pathname(const char *key, char **dest) +{ + return repo_config_get_pathname(the_repository, key, dest); +} + +static inline void git_config_set_in_file(const char *config_filename, + const char *key, const char *value) +{ + repo_config_set_in_file(the_repository, config_filename, key, value); +} + +static inline int git_config_set_gently(const char *key, const char *value) +{ + return repo_config_set_gently(the_repository, key, value); +} + +static inline void git_config_set(const char *key, const char *value) +{ + repo_config_set(the_repository, key, value); +} + +static inline int git_config_set_in_file_gently( + const char *config_filename, + const char *key, + const char *comment, + const char *value) +{ + return repo_config_set_in_file_gently(the_repository, config_filename, + key, comment, value); +} + +static inline int git_config_set_multivar_in_file_gently( + const char *config_filename, + const char *key, const char *value, + const char *value_pattern, + const char *comment, + unsigned flags) +{ + return repo_config_set_multivar_in_file_gently(the_repository, config_filename, + key, value, value_pattern, + comment, flags); +} + +static inline void git_config_set_multivar_in_file( + const char *config_filename, + const char *key, + const char *value, + const char *value_pattern, + unsigned flags) +{ + repo_config_set_multivar_in_file(the_repository, config_filename, + key, value, value_pattern, flags); +} + +static inline int git_config_set_multivar_gently(const char *key, const char *value, + const char *value_pattern, unsigned flags) +{ + return repo_config_set_multivar_gently(the_repository, key, value, + value_pattern, flags); +} + +static inline void git_config_set_multivar(const char *key, const char *value, + const char *value_pattern, unsigned flags) +{ + repo_config_set_multivar(the_repository, key, value, + value_pattern, flags); +} +# endif /* USE_THE_REPOSITORY_VARIABLE */ + #endif /* CONFIG_H */