From patchwork Thu Sep 12 11:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802026 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 58A2A1A2650 for ; Thu, 12 Sep 2024 11:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140569; cv=none; b=Na0cv1KZ9ylqPy4xugfLWA6t+vPGgYL+Zp8sb1F7F4UGhLlwQ9qQxMeAeb8JOE3kIbdYjaPt470V/t/+ODIc/I/d4tZYNumWzohZqjHjUpRXVlQiNXdAQTbMoMEKv1hX4ZMvHoKgsTvPn0LRRuR4M08ahO7h9FcqKD9x5F8LDjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140569; c=relaxed/simple; bh=sl4yGeJ195Xbh90TprACpWw7EjpckjCBISfn0/4xyHU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dz7kTS+kCz7U178HbIeLi4WjeIbovcJxZIU5VpxuXtz60hzPZ7PsYfXVI3tymeOmF7LTXDcnGGq4IkQzvYdzUdxGVK57QW/jvjTJO06lx9rgOocV9HW2H8avpkX2AMkxs/JOY9RXNViMF0yiIqn+ezTxFzVwCNsWBEHH8pnrJ+o= 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=EMNnRM+C; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z9xRFGKx; arc=none smtp.client-ip=103.168.172.157 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="EMNnRM+C"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z9xRFGKx" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 730BC11405C8; Thu, 12 Sep 2024 07:29:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 12 Sep 2024 07:29: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=fm1; t=1726140566; x=1726226966; bh=58RuHkhnr/ 7VdN5Tc8zxoB3wVHc+SnAaHY65Bun/BwM=; b=EMNnRM+CxHYiEW6C7gyickqgtc za4tyaooxeCRwJNiC9xf6Ocrm5KamTdH+H6NgZDjsO0CjCylWCw9OY6sVEqS3qmN 6AdaVkYZjaNfpd8bbj0rw0UfSoi7m8tmyqAvO6UuVsrzLrMX3IOxWho74OP6SOZi 9ZfFXGUvzD6wS7UmjlnC8qWQ9/6Qq3xsQozKU15ZekC/ohKzYxyr/Caug+ZkmqkY 7BekFDpooNVDXoo7MJZbwRjlYtHFCvhm9mQZkxD2XbwMDbUQFIeZ0jTte3Y5281k pt9Gj8jRJ0mlw/O1SrB4iCYMGVVOUpNEa+yrZ/dc1EUlLYnp8O4W+P6UtZMg== 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= fm1; t=1726140566; x=1726226966; bh=58RuHkhnr/7VdN5Tc8zxoB3wVHc+ SnAaHY65Bun/BwM=; b=Z9xRFGKxLJY28BTkmDP1VIoPqWY6PUavganl3aCvcbCn +hqkEySlc1/Dcq+e57JRioX2xA9uVQ0wKY5Icl7DqNOMSP1QgOBBOmJUsefsZbvA 0nr4YgEwsKF+ZNcVn8EvjRY2J/cha7Dky+7twh2U57LZ5THJg+tt2NHKHjANhGh0 SeQEoD430atcjhNYW9yGVb1f+YmDTRlLkp8gMJ9z6Nr27DeoVeVXZ5rM0945xbir xqDO0/4uYyoQbsJLo5VMe5GotJsAd8Btzia0mylEgzuwr5HWgFo+5vsEQserFMSC hOFBeEePsMLFgjktZPL3MMl6xUSioYiYeYi/8Vx+fA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepieduieeitdehieeutdejudehkedvgfejudefgfeiuefg jeekudegfefgffeftdehnecuffhomhgrihhnpehgnhhurdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgs pghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepkhgrrhhthh hikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesghhm rghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegtrghl vhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:25 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1c037e81 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:16 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 01/21] environment: make `get_git_dir()` accept a repository 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: The `get_git_dir()` function retrieves the path to the Git directory for `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- apply.c | 3 ++- builtin/am.c | 5 +++-- builtin/commit.c | 7 ++++--- builtin/config.c | 2 +- builtin/difftool.c | 5 +++-- builtin/fsmonitor--daemon.c | 3 ++- builtin/merge.c | 4 +++- builtin/stash.c | 3 ++- cache-tree.c | 5 +++-- config.c | 4 +++- environment.c | 10 ++-------- environment.h | 1 - pathspec.c | 2 +- read-cache.c | 6 ++++-- repository.c | 7 +++++++ repository.h | 2 ++ setup.c | 12 ++++++------ setup.h | 2 +- trace.c | 5 ++++- transport-helper.c | 2 +- worktree.c | 4 ++-- 21 files changed, 56 insertions(+), 38 deletions(-) diff --git a/apply.c b/apply.c index 6e1060a952c..426cec32f8f 100644 --- a/apply.c +++ b/apply.c @@ -30,6 +30,7 @@ #include "path.h" #include "quote.h" #include "read-cache.h" +#include "repository.h" #include "rerere.h" #include "apply.h" #include "entry.h" @@ -4111,7 +4112,7 @@ static int read_apply_cache(struct apply_state *state) { if (state->index_file) return read_index_from(state->repo->index, state->index_file, - get_git_dir()); + repo_get_git_dir(the_repository)); else return repo_read_index(state->repo); } diff --git a/builtin/am.c b/builtin/am.c index d8875ad4022..405214e242a 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1544,7 +1544,8 @@ static int run_apply(const struct am_state *state, const char *index_file) if (index_file) { /* Reload index as apply_all_patches() will have modified it. */ discard_index(the_repository->index); - read_index_from(the_repository->index, index_file, get_git_dir()); + read_index_from(the_repository->index, index_file, + repo_get_git_dir(the_repository)); } return 0; @@ -1587,7 +1588,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa return error("could not build fake ancestor"); discard_index(the_repository->index); - read_index_from(the_repository->index, index_path, get_git_dir()); + read_index_from(the_repository->index, index_path, repo_get_git_dir(the_repository)); if (write_index_as_tree(&bases[0], the_repository->index, index_path, 0, NULL)) return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); diff --git a/builtin/commit.c b/builtin/commit.c index b2033c48877..a1c1d16a099 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -26,6 +26,7 @@ #include "path.h" #include "preload-index.h" #include "read-cache.h" +#include "repository.h" #include "string-list.h" #include "rerere.h" #include "unpack-trees.h" @@ -407,7 +408,7 @@ static const char *prepare_index(const char **argv, const char *prefix, discard_index(the_repository->index); read_index_from(the_repository->index, get_lock_file_path(&index_lock), - get_git_dir()); + repo_get_git_dir(the_repository)); if (cache_tree_update(the_repository->index, WRITE_TREE_SILENT) == 0) { if (reopen_lock_file(&index_lock) < 0) die(_("unable to write index file")); @@ -534,7 +535,7 @@ static const char *prepare_index(const char **argv, const char *prefix, discard_index(the_repository->index); ret = get_lock_file_path(&false_lock); - read_index_from(the_repository->index, ret, get_git_dir()); + read_index_from(the_repository->index, ret, repo_get_git_dir(the_repository)); out: string_list_clear(&partial, 0); clear_pathspec(&pathspec); @@ -1072,7 +1073,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, */ discard_index(the_repository->index); } - read_index_from(the_repository->index, index_file, get_git_dir()); + read_index_from(the_repository->index, index_file, repo_get_git_dir(the_repository)); if (cache_tree_update(the_repository->index, 0)) { error(_("Error building trees")); diff --git a/builtin/config.c b/builtin/config.c index e00d983596b..c10697a2efb 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -808,7 +808,7 @@ static void location_options_init(struct config_location_options *opts, opts->options.respect_includes = opts->respect_includes_opt; if (startup_info->have_repository) { opts->options.commondir = get_git_common_dir(); - opts->options.git_dir = get_git_dir(); + opts->options.git_dir = repo_get_git_dir(the_repository); } } diff --git a/builtin/difftool.c b/builtin/difftool.c index dcc68e190c2..8c59411e6e0 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -22,6 +22,7 @@ #include "hex.h" #include "parse-options.h" #include "read-cache-ll.h" +#include "repository.h" #include "sparse-index.h" #include "strvec.h" #include "strbuf.h" @@ -214,7 +215,7 @@ static void changed_files(struct hashmap *result, const char *index_path, struct child_process update_index = CHILD_PROCESS_INIT; struct child_process diff_files = CHILD_PROCESS_INIT; struct strbuf buf = STRBUF_INIT; - const char *git_dir = absolute_path(get_git_dir()); + const char *git_dir = absolute_path(repo_get_git_dir(the_repository)); FILE *fp; strvec_pushl(&update_index.args, @@ -737,7 +738,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (!no_index){ setup_work_tree(); - setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1); + setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1); setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); } else if (dir_diff) die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index"); diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 1593713f4cb..c54e736716a 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1311,7 +1311,8 @@ static int fsmonitor_run_daemon(void) strbuf_addstr(&state.path_gitdir_watch, "/.git"); if (!is_directory(state.path_gitdir_watch.buf)) { strbuf_reset(&state.path_gitdir_watch); - strbuf_addstr(&state.path_gitdir_watch, absolute_path(get_git_dir())); + strbuf_addstr(&state.path_gitdir_watch, + absolute_path(repo_get_git_dir(the_repository))); state.nr_paths_watching = 2; } diff --git a/builtin/merge.c b/builtin/merge.c index 662a49a0e8c..a2bae0700b4 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -17,6 +17,7 @@ #include "object-name.h" #include "parse-options.h" #include "lockfile.h" +#include "repository.h" #include "run-command.h" #include "hook.h" #include "diff.h" @@ -855,7 +856,8 @@ static void prepare_to_commit(struct commit_list *remoteheads) if (invoked_hook) discard_index(the_repository->index); } - read_index_from(the_repository->index, index_file, get_git_dir()); + read_index_from(the_repository->index, index_file, + repo_get_git_dir(the_repository)); strbuf_addbuf(&msg, &merge_msg); if (squash) BUG("the control must not reach here under --squash"); diff --git a/builtin/stash.c b/builtin/stash.c index fcfd97972a4..ad6bcefb770 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -19,6 +19,7 @@ #include "entry.h" #include "preload-index.h" #include "read-cache.h" +#include "repository.h" #include "rerere.h" #include "revision.h" #include "setup.h" @@ -642,7 +643,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s", absolute_path(get_git_work_tree())); strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s", - absolute_path(get_git_dir())); + absolute_path(repo_get_git_dir(the_repository))); strvec_push(&cp.args, "status"); run_command(&cp); } diff --git a/cache-tree.c b/cache-tree.c index 50610c3f3cb..b482167a69a 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -1,7 +1,6 @@ #define USE_THE_REPOSITORY_VARIABLE #include "git-compat-util.h" -#include "environment.h" #include "hex.h" #include "lockfile.h" #include "tree.h" @@ -12,6 +11,7 @@ #include "object-store-ll.h" #include "read-cache-ll.h" #include "replace-object.h" +#include "repository.h" #include "promisor-remote.h" #include "trace.h" #include "trace2.h" @@ -725,7 +725,8 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); - entries = read_index_from(index_state, index_path, get_git_dir()); + entries = read_index_from(index_state, index_path, + repo_get_git_dir(the_repository)); if (entries < 0) { ret = WRITE_TREE_UNREADABLE_INDEX; goto out; diff --git a/config.c b/config.c index 56b5862e59d..1733ba85dcd 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,8 @@ * */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "advice.h" @@ -2212,7 +2214,7 @@ void read_early_config(config_fn_t cb, void *data) if (have_git_dir()) { opts.commondir = get_git_common_dir(); - opts.git_dir = get_git_dir(); + opts.git_dir = repo_get_git_dir(the_repository); /* * When setup_git_directory() was not yet asked to discover the * GIT_DIR, we ask discover_git_directory() to figure out whether there diff --git a/environment.c b/environment.c index 1d6c48b52df..040b1ff1ba8 100644 --- a/environment.c +++ b/environment.c @@ -228,13 +228,6 @@ int have_git_dir(void) || the_repository->gitdir; } -const char *get_git_dir(void) -{ - if (!the_repository->gitdir) - BUG("git environment hasn't been setup"); - return the_repository->gitdir; -} - const char *get_git_common_dir(void) { if (!the_repository->commondir) @@ -352,7 +345,8 @@ static void update_relative_gitdir(const char *name UNUSED, const char *new_cwd, void *data UNUSED) { - char *path = reparent_relative_path(old_cwd, new_cwd, get_git_dir()); + char *path = reparent_relative_path(old_cwd, new_cwd, + repo_get_git_dir(the_repository)); struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); trace_printf_key(&trace_setup_key, diff --git a/environment.h b/environment.h index 0148738ed63..06d37d5c82b 100644 --- a/environment.h +++ b/environment.h @@ -106,7 +106,6 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -const char *get_git_dir(void); const char *get_git_common_dir(void); const char *get_object_directory(void); char *get_index_file(void); diff --git a/pathspec.c b/pathspec.c index fe1f0f41af0..416fe1e3dcc 100644 --- a/pathspec.c +++ b/pathspec.c @@ -497,7 +497,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, copyfrom); hint_path = get_git_work_tree(); if (!hint_path) - hint_path = get_git_dir(); + hint_path = repo_get_git_dir(the_repository); die(_("%s: '%s' is outside repository at '%s'"), elt, copyfrom, absolute_path(hint_path)); } diff --git a/read-cache.c b/read-cache.c index 4e67dc182e7..764fdfec465 100644 --- a/read-cache.c +++ b/read-cache.c @@ -31,6 +31,7 @@ #include "path.h" #include "preload-index.h" #include "read-cache.h" +#include "repository.h" #include "resolve-undo.h" #include "revision.h" #include "strbuf.h" @@ -3238,10 +3239,11 @@ static int should_delete_shared_index(const char *shared_index_path) static int clean_shared_index_files(const char *current_hex) { struct dirent *de; - DIR *dir = opendir(get_git_dir()); + DIR *dir = opendir(repo_get_git_dir(the_repository)); if (!dir) - return error_errno(_("unable to open git dir: %s"), get_git_dir()); + return error_errno(_("unable to open git dir: %s"), + repo_get_git_dir(the_repository)); while ((de = readdir(dir)) != NULL) { const char *sha1_hex; diff --git a/repository.c b/repository.c index 9825a308993..31afc62551e 100644 --- a/repository.c +++ b/repository.c @@ -91,6 +91,13 @@ static void expand_base_dir(char **out, const char *in, *out = xstrfmt("%s/%s", base_dir, def_in); } +const char *repo_get_git_dir(struct repository *repo) +{ + if (!repo->gitdir) + BUG("repository hasn't been set up"); + return repo->gitdir; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index af6ea0a62cd..cf2172c0aa5 100644 --- a/repository.h +++ b/repository.h @@ -206,6 +206,8 @@ struct repository { extern struct repository *the_repository; #endif +const char *repo_get_git_dir(struct repository *repo); + /* * Define a custom repository layout. Any field can be NULL, which * will default back to the path according to the default layout. diff --git a/setup.c b/setup.c index 29f86739212..4a9c60922e7 100644 --- a/setup.c +++ b/setup.c @@ -149,7 +149,7 @@ char *prefix_path(const char *prefix, int len, const char *path) if (!r) { const char *hint_path = get_git_work_tree(); if (!hint_path) - hint_path = get_git_dir(); + hint_path = repo_get_git_dir(the_repository); die(_("'%s' is outside repository at '%s'"), path, absolute_path(hint_path)); } @@ -468,7 +468,7 @@ int is_nonbare_repository_dir(struct strbuf *path) int is_inside_git_dir(void) { if (inside_git_dir < 0) - inside_git_dir = is_inside_dir(get_git_dir()); + inside_git_dir = is_inside_dir(repo_get_git_dir(the_repository)); return inside_git_dir; } @@ -1836,7 +1836,7 @@ void check_repository_format(struct repository_format *fmt) struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; if (!fmt) fmt = &repo_fmt; - check_repository_format_gently(get_git_dir(), fmt, NULL); + check_repository_format_gently(repo_get_git_dir(the_repository), fmt, NULL); startup_info->have_repository = 1; repo_set_hash_algo(the_repository, fmt->hash_algo); repo_set_compat_hash_algo(the_repository, fmt->compat_hash_algo); @@ -2224,7 +2224,7 @@ static int create_default_files(const char *template_path, * shared-repository settings, we would need to fix them up. */ if (get_shared_repository()) { - adjust_shared_perm(get_git_dir()); + adjust_shared_perm(repo_get_git_dir(the_repository)); } initialize_repository_version(fmt->hash_algo, fmt->ref_storage_format, 0); @@ -2434,12 +2434,12 @@ int init_db(const char *git_dir, const char *real_git_dir, die(_("%s already exists"), real_git_dir); set_git_dir(real_git_dir, 1); - git_dir = get_git_dir(); + git_dir = repo_get_git_dir(the_repository); separate_git_dir(git_dir, original_git_dir); } else { set_git_dir(git_dir, 1); - git_dir = get_git_dir(); + git_dir = repo_get_git_dir(the_repository); } startup_info->have_repository = 1; diff --git a/setup.h b/setup.h index cd8dbc24976..fd2df7cd525 100644 --- a/setup.h +++ b/setup.h @@ -176,7 +176,7 @@ int verify_repository_format(const struct repository_format *format, struct strbuf *err); /* - * Check the repository format version in the path found in get_git_dir(), + * Check the repository format version in the path found in repo_get_git_dir(the_repository), * and die if it is a version we don't understand. Generally one would * set_git_dir() before calling this, and use it only for "are we in a valid * repo?". diff --git a/trace.c b/trace.c index 8669ddfca25..32c5cda7afd 100644 --- a/trace.c +++ b/trace.c @@ -21,9 +21,12 @@ * along with this program; if not, see . */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "environment.h" +#include "repository.h" #include "quote.h" #include "setup.h" #include "trace.h" @@ -311,7 +314,7 @@ void trace_repo_setup(void) if (!startup_info->prefix) prefix = "(null)"; - trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(get_git_dir())); + trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository))); trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir())); trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree)); trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd)); diff --git a/transport-helper.c b/transport-helper.c index 09b3560ffdc..abe16eea651 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -143,7 +143,7 @@ static struct child_process *get_helper(struct transport *transport) if (have_git_dir()) strvec_pushf(&helper->env, "%s=%s", - GIT_DIR_ENVIRONMENT, get_git_dir()); + GIT_DIR_ENVIRONMENT, repo_get_git_dir(the_repository)); helper->trace2_child_class = helper->args.v[0]; /* "remote-" */ diff --git a/worktree.c b/worktree.c index 30a947426ee..11335c5d9a3 100644 --- a/worktree.c +++ b/worktree.c @@ -57,7 +57,7 @@ static void add_head_info(struct worktree *wt) static int is_current_worktree(struct worktree *wt) { - char *git_dir = absolute_pathdup(get_git_dir()); + char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository)); const char *wt_git_dir = get_worktree_git_dir(wt); int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir)); free(git_dir); @@ -171,7 +171,7 @@ struct worktree **get_worktrees(void) const char *get_worktree_git_dir(const struct worktree *wt) { if (!wt) - return get_git_dir(); + return repo_get_git_dir(the_repository); else if (!wt->id) return get_git_common_dir(); else From patchwork Thu Sep 12 11:29:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802027 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 B75841A2656 for ; Thu, 12 Sep 2024 11:29:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140571; cv=none; b=UdGM07j7wGrmdXJdbnNGh08gmFPlUA6Y0DESl8FhQifhTGpBsHnTqyeUjh+I6th8KJOHSOE1eSvROpft2xYPAqp7YD4DWftbNinq00tDyoGctSO8QVq10OpiqtNtx8Ri5jBQnPE82ol88GroTeAvcdBNSXHiVMEvCQx/qbDlLqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140571; c=relaxed/simple; bh=1dhdBD7YylxoN3p/VWG8gZBOveydwmo4VGMZF0G8OZ4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=meZoiOacrdq+sAPGvlhE3f3B+r6a/920VKfGB5rI3r4IZihlhXreayljS8cUe08a515Wd0msqsb6a6rLkmEcbOVNMz+0kGBQUdRNnJNZL4aL9KgiL0KMeQeFZv54uYmahAGWxhEvgU0w+6Vqm7/tONVwFPVXkLvHkkzm7qSZFQc= 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=EpGYFq/2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KWi3s0gO; arc=none smtp.client-ip=103.168.172.157 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="EpGYFq/2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KWi3s0gO" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id E260811405E4; Thu, 12 Sep 2024 07:29:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 12 Sep 2024 07:29: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=fm1; t=1726140568; x=1726226968; bh=3DzHcWjV14 DGevbGHDMhbO+LEojUNp1+BIUwiWdj2n4=; b=EpGYFq/2pYjkiMGTld1+iU/3YH EiQPgDpcYswnFLuLAOBlD/PkYO0Xzrz3oaMa0GnoSAvS7J4vjiE/VdJ3NClcCHNH zdpeoYoC2w1+gqYX9vzybTmLw96BPjfzwSyXKHjzlu2yX4/dJ3Zx7CpiwWZw1mqD xNtTA3DKFL0K8DrTsi3Apd9TbH6ErFhmpVu2c5p1tK/pQ2Gq/aR2L8XM7inxYH8E 9v5MpsrUYx6oHbV9lRUeMP3796mkWLqOUGaOFzvAQKvovujUd6pNw2Peh7yFvwhv fmw5b332nri/oG/L3ImtXU4wx4ZfuwnZiCVj1R5vtVK1Ak6HSPkwHxtWOMUw== 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= fm1; t=1726140568; x=1726226968; bh=3DzHcWjV14DGevbGHDMhbO+LEojU Np1+BIUwiWdj2n4=; b=KWi3s0gOn5/fsvN8f3c+XuY9lPmT0DLmb2rPCcWVxKEI jvlmeWRlDN3/rSu7fzJKc0qFMsndX0qvjjkUFI0VQIQqKoufrVlTOCzq23W0lPP7 BV13SOHIf9bNS08Ndp2G5FGdkwNXW2T5FBAR3HdBHmAm/G/lBMC858XD4Ynypbw+ TUy2d/PHup4rfZVJO+dQQLFaiLlWWLTkdKQfmhus4QvwB+UsTC7KIYGKD6+sCzg5 8+e074CCPwbAvapRj2FyPdbyHobMLONqs0gQKhvqdoadrfHJuhbwAYZ8SfTaLm5o sWmvuuq7mioQd8rdeW0CJrYGI1hX+w9DN3BDnUeg2Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptggrlhhv ihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id edc33836 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:18 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:27 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 02/21] environment: make `get_git_common_dir()` accept a repository Message-ID: <2964cfc77901bac58bda4614befa604f16bfec90.1726139990.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 `get_git_common_dir()` function retrieves the path to the common directory for `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 2 +- builtin/gc.c | 2 +- builtin/rev-parse.c | 3 ++- builtin/worktree.c | 4 ++-- config.c | 2 +- environment.c | 7 ------- environment.h | 1 - repository.c | 7 +++++++ repository.h | 1 + setup.c | 2 +- submodule.c | 2 +- trace.c | 2 +- worktree.c | 8 ++++---- 13 files changed, 22 insertions(+), 21 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index c10697a2efb..34a371414e8 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -807,7 +807,7 @@ static void location_options_init(struct config_location_options *opts, else opts->options.respect_includes = opts->respect_includes_opt; if (startup_info->have_repository) { - opts->options.commondir = get_git_common_dir(); + opts->options.commondir = repo_get_common_dir(the_repository); opts->options.git_dir = repo_get_git_dir(the_repository); } } diff --git a/builtin/gc.c b/builtin/gc.c index 427faf1cfe1..0f3d74f8bd0 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -2132,7 +2132,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority get_schedule_cmd(&cmd, NULL); strbuf_addf(&tfilename, "%s/schedule_%s_XXXXXX", - get_git_common_dir(), frequency); + repo_get_common_dir(the_repository), frequency); tfile = xmks_tempfile(tfilename.buf); strbuf_release(&tfilename); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 4285dc34a7b..cd85fe57bb0 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -19,6 +19,7 @@ #include "path.h" #include "diff.h" #include "read-cache-ll.h" +#include "repository.h" #include "revision.h" #include "setup.h" #include "split-index.h" @@ -1042,7 +1043,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--git-common-dir")) { - print_path(get_git_common_dir(), prefix, format, DEFAULT_RELATIVE_IF_SHARED); + print_path(repo_get_common_dir(the_repository), prefix, format, DEFAULT_RELATIVE_IF_SHARED); continue; } if (!strcmp(arg, "--is-inside-git-dir")) { diff --git a/builtin/worktree.c b/builtin/worktree.c index 41e7f6a3271..645b548bf3b 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -219,7 +219,7 @@ static void prune_worktrees(void) } closedir(dir); - strbuf_add_absolute_path(&main_path, get_git_common_dir()); + strbuf_add_absolute_path(&main_path, repo_get_common_dir(the_repository)); /* massage main worktree absolute path to match 'gitdir' content */ strbuf_strip_suffix(&main_path, "/."); string_list_append_nodup(&kept, strbuf_detach(&main_path, NULL)); @@ -492,7 +492,7 @@ static int add_worktree(const char *path, const char *refname, strbuf_addf(&sb, "%s/gitdir", sb_repo.buf); strbuf_realpath(&realpath, sb_git.buf, 1); write_file(sb.buf, "%s", realpath.buf); - strbuf_realpath(&realpath, get_git_common_dir(), 1); + strbuf_realpath(&realpath, repo_get_common_dir(the_repository), 1); write_file(sb_git.buf, "gitdir: %s/worktrees/%s", realpath.buf, name); strbuf_reset(&sb); diff --git a/config.c b/config.c index 1733ba85dcd..0b87f0f9050 100644 --- a/config.c +++ b/config.c @@ -2213,7 +2213,7 @@ void read_early_config(config_fn_t cb, void *data) opts.respect_includes = 1; if (have_git_dir()) { - opts.commondir = get_git_common_dir(); + opts.commondir = repo_get_common_dir(the_repository); opts.git_dir = repo_get_git_dir(the_repository); /* * When setup_git_directory() was not yet asked to discover the diff --git a/environment.c b/environment.c index 040b1ff1ba8..7c4a142ca25 100644 --- a/environment.c +++ b/environment.c @@ -228,13 +228,6 @@ int have_git_dir(void) || the_repository->gitdir; } -const char *get_git_common_dir(void) -{ - if (!the_repository->commondir) - BUG("git environment hasn't been setup"); - return the_repository->commondir; -} - const char *get_git_namespace(void) { if (!git_namespace) diff --git a/environment.h b/environment.h index 06d37d5c82b..d778614158f 100644 --- a/environment.h +++ b/environment.h @@ -106,7 +106,6 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -const char *get_git_common_dir(void); const char *get_object_directory(void); char *get_index_file(void); char *get_graft_file(struct repository *r); diff --git a/repository.c b/repository.c index 31afc62551e..c8dcba1997a 100644 --- a/repository.c +++ b/repository.c @@ -98,6 +98,13 @@ const char *repo_get_git_dir(struct repository *repo) return repo->gitdir; } +const char *repo_get_common_dir(struct repository *repo) +{ + if (!repo->commondir) + BUG("repository hasn't been set up"); + return repo->commondir; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index cf2172c0aa5..404435ad029 100644 --- a/repository.h +++ b/repository.h @@ -207,6 +207,7 @@ extern struct repository *the_repository; #endif const char *repo_get_git_dir(struct repository *repo); +const char *repo_get_common_dir(struct repository *repo); /* * Define a custom repository layout. Any field can be NULL, which diff --git a/setup.c b/setup.c index 4a9c60922e7..fe4a5dfc43b 100644 --- a/setup.c +++ b/setup.c @@ -2068,7 +2068,7 @@ static void copy_templates(const char *option_template) goto close_free_return; } - strbuf_addstr(&path, get_git_common_dir()); + strbuf_addstr(&path, repo_get_common_dir(the_repository)); strbuf_complete(&path, '/'); copy_templates_1(&path, &template_path, dir); close_free_return: diff --git a/submodule.c b/submodule.c index 97516b0fec1..c7d164a31ab 100644 --- a/submodule.c +++ b/submodule.c @@ -2462,7 +2462,7 @@ void absorb_git_dir_into_superproject(const char *path, } else { /* Is it already absorbed into the superprojects git dir? */ char *real_sub_git_dir = real_pathdup(sub_git_dir, 1); - char *real_common_git_dir = real_pathdup(get_git_common_dir(), 1); + char *real_common_git_dir = real_pathdup(repo_get_common_dir(the_repository), 1); if (!starts_with(real_sub_git_dir, real_common_git_dir)) relocate_single_git_dir_into_superproject(path, super_prefix); diff --git a/trace.c b/trace.c index 32c5cda7afd..e6728c301f3 100644 --- a/trace.c +++ b/trace.c @@ -315,7 +315,7 @@ void trace_repo_setup(void) prefix = "(null)"; trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository))); - trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir())); + trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(repo_get_common_dir(the_repository))); trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree)); trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd)); trace_printf_key(&trace_setup_key, "setup: prefix: %s\n", quote_crnl(prefix)); diff --git a/worktree.c b/worktree.c index 11335c5d9a3..0f032ccedff 100644 --- a/worktree.c +++ b/worktree.c @@ -72,7 +72,7 @@ static struct worktree *get_main_worktree(int skip_reading_head) struct worktree *worktree = NULL; struct strbuf worktree_path = STRBUF_INIT; - strbuf_add_real_path(&worktree_path, get_git_common_dir()); + strbuf_add_real_path(&worktree_path, repo_get_common_dir(the_repository)); strbuf_strip_suffix(&worktree_path, "/.git"); CALLOC_ARRAY(worktree, 1); @@ -143,7 +143,7 @@ static struct worktree **get_worktrees_internal(int skip_reading_head) list[counter++] = get_main_worktree(skip_reading_head); - strbuf_addf(&path, "%s/worktrees", get_git_common_dir()); + strbuf_addf(&path, "%s/worktrees", repo_get_common_dir(the_repository)); dir = opendir(path.buf); strbuf_release(&path); if (dir) { @@ -173,7 +173,7 @@ const char *get_worktree_git_dir(const struct worktree *wt) if (!wt) return repo_get_git_dir(the_repository); else if (!wt->id) - return get_git_common_dir(); + return repo_get_common_dir(the_repository); else return git_common_path("worktrees/%s", wt->id); } @@ -626,7 +626,7 @@ static int is_main_worktree_path(const char *path) strbuf_add_real_path(&target, path); strbuf_strip_suffix(&target, "/.git"); - strbuf_add_real_path(&maindir, get_git_common_dir()); + strbuf_add_real_path(&maindir, repo_get_common_dir(the_repository)); strbuf_strip_suffix(&maindir, "/.git"); cmp = fspathcmp(maindir.buf, target.buf); From patchwork Thu Sep 12 11:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802028 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 460B51A3023 for ; Thu, 12 Sep 2024 11:29:32 +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=1726140574; cv=none; b=e2eudnPnlGpyKjddV3odWyGEqAOHRPlU6OXndF7nnBwld/h/P/Taa0xSZ2W0rBvrh3BpIljXFOCldgp//fIkAwM/Uws/ElOvVdiUVsW+dI3gbc7oDCddoZZQ4gywq0TdcKpxNSleC5vkCUXs4aCt/vuvl+DLVMc3PgA2taxxy5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140574; c=relaxed/simple; bh=fyTRTbH630nfg4G8ISK1X0RfnTAgfPID4YJvBHRm0ks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NjjNOXME/0jIMaGjiqL+voJYa2mnc5FqSWJy9Kb0GTRwHq/tThgvKw47AxOTE1z6Bc6yiXIAgn4Z2hK4npm4fq/YPNrAuy9ozfdJUEQnahM00bXq4a5g/AALox7E+x1voTJ7urprAyzkW2hupVg3/4aws6kOwmhSTFnnowE6FM4= 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=kUij7bi0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ccCsQvAh; 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="kUij7bi0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ccCsQvAh" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 6B5E4138061F; Thu, 12 Sep 2024 07:29:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Thu, 12 Sep 2024 07:29:31 -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=fm1; t=1726140571; x=1726226971; bh=eNVL3p8+PA cCEVhuDZAFQdxxsCLltRRUtrdMy2wHCxg=; b=kUij7bi0UEbCGCZejVoROb9xCd tJL4aREs1QVjXmmrZiOAX7Nlk5z6+13ZnTAhuofBtJ5MbNdwl1j0Okdb/pHvZHjw 8BW05qYWrSXL6hLKy9at5n5SEmbonh5g11Klzm8L4XcmI62vB9abNjXkzIPwidA8 2ux0E2nWBykKerLfxWiVIrf9A062DleYpfL9R5ZmmczJQW0e4CVohOjmmIDJOQ/Y 3OMYJnxO7DX3QCO/XSmUB5jIRCj+avUWcVYl46it5rJS37PurPenq+Y87x7ecJ52 vdFZMJ1T1MxSxvnxaxtfP1BXZmB1u+0rQffIjF+B8uHE8VQslS5DdoEXqWug== 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= fm1; t=1726140571; x=1726226971; bh=eNVL3p8+PAcCEVhuDZAFQdxxsCLl tRRUtrdMy2wHCxg=; b=ccCsQvAhRRtIoIymFeRD2xx0u3iCJgCkAmGJ1JmYRX4H Y8r0oXUAPoE7RaP7k4pkMsuzYmlHMS4Iv/0IIhVjG+6PbaZ6rhBKkRyoRE4VAI3r +J4MyP3wuNB4YUH3r/iqmM9QeeFRPQNyI4wRGZySjCq62T4YX0s032u7iqD5Gu1J HX3A6uK1upWChiYBkDcPlDo8PP6uNoSY3sulYxkLXPKid+TTPYXjpwjWCBCvSeKy fqYgvnP7daq+qKeGgx4KtF/GIab2KRIAcuJFpEiNNZ6KHjmbzsV5GdGla2PLNDcu TxuEsRjbntwH9r8tevVUYvqkSfZyLLnYqN921vyIow== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptggrlhhv ihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 776f5041 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:21 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:30 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 03/21] environment: make `get_object_directory()` accept a repository 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: The `get_object_directory()` function retrieves the path to the object directory for `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/commit-graph.c | 5 ++--- builtin/count-objects.c | 3 +-- builtin/multi-pack-index.c | 4 ++-- builtin/pack-objects.c | 2 +- builtin/prune.c | 8 ++++---- builtin/repack.c | 7 ++++--- bulk-checkin.c | 4 ++-- environment.c | 7 ------- environment.h | 1 - fetch-pack.c | 2 +- http-backend.c | 2 +- object-file.c | 4 ++-- pack-write.c | 3 ++- packfile.c | 2 +- prune-packed.c | 6 ++++-- repository.c | 7 +++++++ repository.h | 1 + server-info.c | 4 ++-- setup.c | 2 +- tmp-objdir.c | 8 +++++--- 20 files changed, 43 insertions(+), 39 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 7102ee90a00..7411e6244f2 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -1,7 +1,6 @@ #include "builtin.h" #include "commit.h" #include "config.h" -#include "environment.h" #include "gettext.h" #include "hex.h" #include "parse-options.h" @@ -95,7 +94,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix) usage_with_options(builtin_commit_graph_verify_usage, options); if (!opts.obj_dir) - opts.obj_dir = get_object_directory(); + opts.obj_dir = repo_get_object_directory(the_repository); if (opts.shallow) flags |= COMMIT_GRAPH_VERIFY_SHALLOW; if (opts.progress) @@ -275,7 +274,7 @@ static int graph_write(int argc, const char **argv, const char *prefix) if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1) die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs")); if (!opts.obj_dir) - opts.obj_dir = get_object_directory(); + opts.obj_dir = repo_get_object_directory(the_repository); if (opts.append) flags |= COMMIT_GRAPH_WRITE_APPEND; if (opts.split) diff --git a/builtin/count-objects.c b/builtin/count-objects.c index ec6098a149d..42275f62d59 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -7,7 +7,6 @@ #include "builtin.h" #include "config.h" #include "dir.h" -#include "environment.h" #include "gettext.h" #include "path.h" #include "repository.h" @@ -116,7 +115,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) report_linked_checkout_garbage(the_repository); } - for_each_loose_file_in_objdir(get_object_directory(), + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), count_loose, count_cruft, NULL, NULL); if (verbose) { diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 8805cbbeb3b..55289e989df 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -1,7 +1,6 @@ #include "builtin.h" #include "abspath.h" #include "config.h" -#include "environment.h" #include "gettext.h" #include "parse-options.h" #include "midx.h" @@ -9,6 +8,7 @@ #include "trace2.h" #include "object-store-ll.h" #include "replace-object.h" +#include "repository.h" #define BUILTIN_MIDX_WRITE_USAGE \ N_("git multi-pack-index [] write [--preferred-pack=]" \ @@ -63,7 +63,7 @@ static int parse_object_dir(const struct option *opt, const char *arg, char **value = opt->value; free(*value); if (unset) - *value = xstrdup(get_object_directory()); + *value = xstrdup(repo_get_object_directory(the_repository)); else *value = real_pathdup(arg, 1); return 0; diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 778be80f564..44341b206d4 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3940,7 +3940,7 @@ static int add_loose_object(const struct object_id *oid, const char *path, */ static void add_unreachable_loose_objects(void) { - for_each_loose_file_in_objdir(get_object_directory(), + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), add_loose_object, NULL, NULL, NULL); } diff --git a/builtin/prune.c b/builtin/prune.c index 57fe31467fe..47eeabbd13a 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -193,12 +193,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix) revs.exclude_promisor_objects = 1; } - for_each_loose_file_in_objdir(get_object_directory(), prune_object, - prune_cruft, prune_subdir, &revs); + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), + prune_object, prune_cruft, prune_subdir, &revs); prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0); - remove_temporary_files(get_object_directory()); - s = mkpathdup("%s/pack", get_object_directory()); + remove_temporary_files(repo_get_object_directory(the_repository)); + s = mkpathdup("%s/pack", repo_get_object_directory(the_repository)); remove_temporary_files(s); free(s); diff --git a/builtin/repack.c b/builtin/repack.c index 62cfa50c50f..40feacb73f8 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -1240,7 +1240,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (write_midx && write_bitmaps) { struct strbuf path = STRBUF_INIT; - strbuf_addf(&path, "%s/%s_XXXXXX", get_object_directory(), + strbuf_addf(&path, "%s/%s_XXXXXX", repo_get_object_directory(the_repository), "bitmap-ref-tips"); refs_snapshot = xmks_tempfile(path.buf); @@ -1249,7 +1249,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) strbuf_release(&path); } - packdir = mkpathdup("%s/pack", get_object_directory()); + packdir = mkpathdup("%s/pack", repo_get_object_directory(the_repository)); packtmp_name = xstrfmt(".tmp-%d-pack", (int)getpid()); packtmp = mkpathdup("%s/%s", packdir, packtmp_name); @@ -1519,7 +1519,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix) unsigned flags = 0; if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0)) flags |= MIDX_WRITE_INCREMENTAL; - write_midx_file(get_object_directory(), NULL, NULL, flags); + write_midx_file(repo_get_object_directory(the_repository), + NULL, NULL, flags); } cleanup: diff --git a/bulk-checkin.c b/bulk-checkin.c index 9089c214fa4..2753d5bbe4a 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -75,7 +75,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state) close(fd); } - strbuf_addf(&packname, "%s/pack/pack-%s.", get_object_directory(), + strbuf_addf(&packname, "%s/pack/pack-%s.", repo_get_object_directory(the_repository), hash_to_hex(hash)); finish_tmp_packfile(&packname, state->pack_tmp_name, state->written, state->nr_written, @@ -113,7 +113,7 @@ static void flush_batch_fsync(void) * to ensure that the data in each new object file is durable before * the final name is visible. */ - strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", get_object_directory()); + strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", repo_get_object_directory(the_repository)); temp = xmks_tempfile(temp_path.buf); fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp)); delete_tempfile(&temp); diff --git a/environment.c b/environment.c index 7c4a142ca25..0a2057399e0 100644 --- a/environment.c +++ b/environment.c @@ -273,13 +273,6 @@ const char *get_git_work_tree(void) return the_repository->worktree; } -const char *get_object_directory(void) -{ - if (!the_repository->objects->odb) - BUG("git environment hasn't been setup"); - return the_repository->objects->odb->path; -} - int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) { int fd; diff --git a/environment.h b/environment.h index d778614158f..91125d82991 100644 --- a/environment.h +++ b/environment.h @@ -106,7 +106,6 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -const char *get_object_directory(void); char *get_index_file(void); char *get_graft_file(struct repository *r); void set_git_dir(const char *path, int make_realpath); diff --git a/fetch-pack.c b/fetch-pack.c index 58b4581ad80..fddb90f2e78 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1839,7 +1839,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, string_list_append_nodup(pack_lockfiles, xstrfmt("%s/pack/pack-%s.keep", - get_object_directory(), + repo_get_object_directory(the_repository), packname)); } string_list_clear(&packfile_uris, 0); diff --git a/http-backend.c b/http-backend.c index 79ce097359b..73eec4ea3d8 100644 --- a/http-backend.c +++ b/http-backend.c @@ -601,7 +601,7 @@ static void get_head(struct strbuf *hdr, char *arg UNUSED) static void get_info_packs(struct strbuf *hdr, char *arg UNUSED) { - size_t objdirlen = strlen(get_object_directory()); + size_t objdirlen = strlen(repo_get_object_directory(the_repository)); struct strbuf buf = STRBUF_INIT; struct packed_git *p; size_t cnt = 0; diff --git a/object-file.c b/object-file.c index c5994202ba0..fa4121b98ad 100644 --- a/object-file.c +++ b/object-file.c @@ -2053,7 +2053,7 @@ static int start_loose_object_common(struct strbuf *tmp_file, else if (errno == EACCES) return error(_("insufficient permission for adding " "an object to repository database %s"), - get_object_directory()); + repo_get_object_directory(the_repository)); else return error_errno( _("unable to create temporary file")); @@ -2228,7 +2228,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len, prepare_loose_object_bulk_checkin(); /* Since oid is not determined, save tmp file to odb path. */ - strbuf_addf(&filename, "%s/", get_object_directory()); + strbuf_addf(&filename, "%s/", repo_get_object_directory(the_repository)); hdrlen = format_object_header(hdr, sizeof(hdr), OBJ_BLOB, len); /* diff --git a/pack-write.c b/pack-write.c index d07f03d0ab0..27965672f17 100644 --- a/pack-write.c +++ b/pack-write.c @@ -12,6 +12,7 @@ #include "pack-objects.h" #include "pack-revindex.h" #include "path.h" +#include "repository.h" #include "strbuf.h" void reset_pack_idx_option(struct pack_idx_option *opts) @@ -473,7 +474,7 @@ char *index_pack_lockfile(int ip_out, int *is_well_formed) packname[len-1] = 0; if (skip_prefix(packname, "keep\t", &name)) return xstrfmt("%s/pack/pack-%s.keep", - get_object_directory(), name); + repo_get_object_directory(the_repository), name); return NULL; } if (is_well_formed) diff --git a/packfile.c b/packfile.c index cf12a539eac..df4ba677197 100644 --- a/packfile.c +++ b/packfile.c @@ -30,7 +30,7 @@ char *odb_pack_name(struct strbuf *buf, const char *ext) { strbuf_reset(buf); - strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(), + strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(the_repository), hash_to_hex(hash), ext); return buf->buf; } diff --git a/prune-packed.c b/prune-packed.c index e54daf740a2..2bb99c29dfb 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -1,10 +1,12 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" -#include "environment.h" #include "gettext.h" #include "object-store-ll.h" #include "packfile.h" #include "progress.h" #include "prune-packed.h" +#include "repository.h" static struct progress *progress; @@ -37,7 +39,7 @@ void prune_packed_objects(int opts) if (opts & PRUNE_PACKED_VERBOSE) progress = start_delayed_progress(_("Removing duplicate objects"), 256); - for_each_loose_file_in_objdir(get_object_directory(), + for_each_loose_file_in_objdir(repo_get_object_directory(the_repository), prune_object, NULL, prune_subdir, &opts); /* Ensure we show 100% before finishing progress */ diff --git a/repository.c b/repository.c index c8dcba1997a..49c42c25daa 100644 --- a/repository.c +++ b/repository.c @@ -105,6 +105,13 @@ const char *repo_get_common_dir(struct repository *repo) return repo->commondir; } +const char *repo_get_object_directory(struct repository *repo) +{ + if (!repo->objects->odb) + BUG("repository hasn't been set up"); + return repo->objects->odb->path; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index 404435ad029..778f1511ab1 100644 --- a/repository.h +++ b/repository.h @@ -208,6 +208,7 @@ extern struct repository *the_repository; const char *repo_get_git_dir(struct repository *repo); const char *repo_get_common_dir(struct repository *repo); +const char *repo_get_object_directory(struct repository *repo); /* * Define a custom repository layout. Any field can be NULL, which diff --git a/server-info.c b/server-info.c index 1508fa6f825..c5af4cd98a6 100644 --- a/server-info.c +++ b/server-info.c @@ -2,7 +2,6 @@ #include "git-compat-util.h" #include "dir.h" -#include "environment.h" #include "hex.h" #include "repository.h" #include "refs.h" @@ -342,7 +341,8 @@ static int write_pack_info_file(struct update_info_ctx *uic) static int update_info_packs(int force) { - char *infofile = mkpathdup("%s/info/packs", get_object_directory()); + char *infofile = mkpathdup("%s/info/packs", + repo_get_object_directory(the_repository)); int ret; init_pack_info(infofile, force); diff --git a/setup.c b/setup.c index fe4a5dfc43b..1ebcab625fe 100644 --- a/setup.c +++ b/setup.c @@ -2282,7 +2282,7 @@ static void create_object_directory(void) struct strbuf path = STRBUF_INIT; size_t baselen; - strbuf_addstr(&path, get_object_directory()); + strbuf_addstr(&path, repo_get_object_directory(the_repository)); baselen = path.len; safe_create_dir(path.buf, 1); diff --git a/tmp-objdir.c b/tmp-objdir.c index a8e4553f274..c2fb9f91930 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -13,6 +13,7 @@ #include "strvec.h" #include "quote.h" #include "object-store-ll.h" +#include "repository.h" struct tmp_objdir { struct strbuf path; @@ -132,7 +133,8 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix) * can recognize any stale objdirs left behind by a crash and delete * them. */ - strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", get_object_directory(), prefix); + strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX", + repo_get_object_directory(the_repository), prefix); if (!mkdtemp(t->path.buf)) { /* free, not destroy, as we never touched the filesystem */ @@ -152,7 +154,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix) } env_append(&t->env, ALTERNATE_DB_ENVIRONMENT, - absolute_path(get_object_directory())); + absolute_path(repo_get_object_directory(the_repository))); env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf)); env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT, absolute_path(t->path.buf)); @@ -267,7 +269,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t) } strbuf_addbuf(&src, &t->path); - strbuf_addstr(&dst, get_object_directory()); + strbuf_addstr(&dst, repo_get_object_directory(the_repository)); ret = migrate_paths(&src, &dst); From patchwork Thu Sep 12 11:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802029 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 795A91A3037 for ; Thu, 12 Sep 2024 11:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140576; cv=none; b=fZc1tY8YEmk+vUyDLZM92s6+DDpidv8l6wHZy11e4QpNwGuljVEOHDMGapfx4/lrseoPAR03hMEDdH6fj9lAIAnztOLklwrLXNekCcAKYuw7vViuvEwbMlzji+a+KsRYCze4D9pxesbsxeBC/SlceIN6Z6Cyww0gy1VhbjVJOeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140576; c=relaxed/simple; bh=LnIXckUGzoxDq3PToU69Tp9lgD147tCqeUuj7GYplfo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ttyyVs7vxTFgtkgbrl0JdH4PzzFA6auD6sPUvGPpzLdlczFrJp5Cz485VGInqTpRC9Ea5FWzS0kvo+AodVUDzTOmf9X9GJRJUm1WfLaHmehom5ajnh7baqo4rQHgTcmS8xOgW+3lFISOyTO188SxBVWtB/iL7SR5DXM0unn2zXY= 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=R8ztkZtw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LkxutxNX; arc=none smtp.client-ip=103.168.172.157 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="R8ztkZtw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LkxutxNX" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id D847111405B2; Thu, 12 Sep 2024 07:29:33 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Thu, 12 Sep 2024 07:29:33 -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=fm1; t=1726140573; x=1726226973; bh=n9r/RHC3y6 68bCqn4KgmXwMRB3Xke8P0UlGtq+99XnA=; b=R8ztkZtwBKRczTaTLV+nQtllYM 4sxhWbIRnWtueRgGHA8wLrKOWRKN3ulZX5m+BPougeJrlRJAhezn5NqPcT89PwlI ZnjgMkfuBIJBxt/E+IIEVMlUwsuN1XRo6oy9hQ+DLy0Pbc5p4P9FQd2Gn+CXQwnD CoLWgRj49TpY66Jxq2YUlWePxShtkMTVvg+cs6BDZBj5Qcw9+MO+b8LwQWeC6FB1 OtqyQVN+2PHzxYEo3KgUJtrR+yjnRdn7/feZUqyIonu1a7qNfpCtjBi4pHqZ3nQH KeOsAmzTNCTlN9xEVeTN3Mt/MR9oFjBIiVbKPz82RT9lpPWwyCTq9RNTz71w== 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= fm1; t=1726140573; x=1726226973; bh=n9r/RHC3y668bCqn4KgmXwMRB3Xk e8P0UlGtq+99XnA=; b=LkxutxNX9zdyu68KzPRi09a9syUIwsDX959gQLZ80TO1 cJQ7pvHmBk56v85W+/hrXoD+jdS/Bn0PfSvkuuM0MCBuYmsMpkIbag7DbyEUGL4Q UL3bhOvPf+6XSm4zj+V58/4W01IVDwWDo0QkIQNFVEpux7OdG0qg1KsZ2RydfWNX Iy49Nyn3hth8kg4AkH73D4PwSBXmjY/sWGLLNllxNKulEVYqrnTIaSwSq2rjKRho r5Bm7PLhj75FDtkpcDuBMeEqGrSwituHQghZVq3/ofIkAW2Yvg/GaJTlbCm8nEIt qi27ZdCxrNeuAq/N7D/Jb01DKVpxHnldm4nmxsoD4A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehkrghr thhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrd hkvghrnhgvlhdrohhrghdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 87f3297a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:24 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 04/21] environment: make `get_index_file()` accept a repository 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: The `get_index_file()` function retrieves the path to the index file of `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/am.c | 8 ++++++-- builtin/commit.c | 6 +++--- builtin/merge.c | 14 ++++++++------ builtin/stash.c | 12 ++++++------ builtin/update-index.c | 2 +- builtin/write-tree.c | 4 ++-- environment.c | 7 ------- environment.h | 1 - repository.c | 7 +++++++ repository.h | 1 + wt-status.c | 3 ++- 11 files changed, 36 insertions(+), 29 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 405214e242a..5498ddeb6aa 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1668,7 +1668,9 @@ static void do_commit(const struct am_state *state) 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)) + if (write_index_as_tree(&tree, the_repository->index, + repo_get_index_file(the_repository), + 0, NULL)) die(_("git write-tree failed to write a tree")); if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) { @@ -2078,7 +2080,9 @@ static int clean_index(const struct object_id *head, const struct object_id *rem if (fast_forward_to(head_tree, head_tree, 1)) return -1; - if (write_index_as_tree(&index, the_repository->index, get_index_file(), 0, NULL)) + if (write_index_as_tree(&index, the_repository->index, + repo_get_index_file(the_repository), + 0, NULL)) return -1; index_tree = parse_tree_indirect(&index); diff --git a/builtin/commit.c b/builtin/commit.c index a1c1d16a099..b09320f9070 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -473,7 +473,7 @@ static const char *prepare_index(const char **argv, const char *prefix, COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("unable to write new index file")); commit_style = COMMIT_AS_IS; - ret = get_index_file(); + ret = repo_get_index_file(the_repository); goto out; } @@ -1874,8 +1874,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) repo_rerere(the_repository, 0); run_auto_maintenance(quiet); - run_commit_hook(use_editor, get_index_file(), NULL, "post-commit", - NULL); + run_commit_hook(use_editor, repo_get_index_file(the_repository), + NULL, "post-commit", NULL); if (amend && !no_post_rewrite) { commit_post_rewrite(the_repository, current_head, &oid); } diff --git a/builtin/merge.c b/builtin/merge.c index a2bae0700b4..7f5475f738c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -696,7 +696,9 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, static void write_tree_trivial(struct object_id *oid) { - if (write_index_as_tree(oid, the_repository->index, get_index_file(), 0, NULL)) + if (write_index_as_tree(oid, the_repository->index, + repo_get_index_file(the_repository), + 0, NULL)) die(_("git write-tree failed to write a tree")); } @@ -758,7 +760,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, } if (write_locked_index(the_repository->index, &lock, COMMIT_LOCK | SKIP_IF_UNCHANGED)) - die(_("unable to write %s"), get_index_file()); + die(_("unable to write %s"), repo_get_index_file(the_repository)); return clean ? 0 : 1; } else { return try_merge_command(the_repository, @@ -840,7 +842,7 @@ static void write_merge_heads(struct commit_list *); static void prepare_to_commit(struct commit_list *remoteheads) { struct strbuf msg = STRBUF_INIT; - const char *index_file = get_index_file(); + const char *index_file = repo_get_index_file(the_repository); if (!no_verify) { int invoked_hook; @@ -880,8 +882,8 @@ static void prepare_to_commit(struct commit_list *remoteheads) append_signoff(&msg, ignored_log_message_bytes(msg.buf, msg.len), 0); write_merge_heads(remoteheads); write_file_buf(git_path_merge_msg(the_repository), msg.buf, msg.len); - if (run_commit_hook(0 < option_edit, get_index_file(), NULL, - "prepare-commit-msg", + if (run_commit_hook(0 < option_edit, repo_get_index_file(the_repository), + NULL, "prepare-commit-msg", git_path_merge_msg(the_repository), "merge", NULL)) abort_commit(remoteheads, NULL); if (0 < option_edit) { @@ -889,7 +891,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) abort_commit(remoteheads, NULL); } - if (!no_verify && run_commit_hook(0 < option_edit, get_index_file(), + if (!no_verify && run_commit_hook(0 < option_edit, repo_get_index_file(the_repository), NULL, "commit-msg", git_path_merge_msg(the_repository), NULL)) abort_commit(remoteheads, NULL); diff --git a/builtin/stash.c b/builtin/stash.c index ad6bcefb770..f2ec9549a47 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -540,8 +540,8 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, NULL, NULL, NULL)) return error(_("could not write index")); - if (write_index_as_tree(&c_tree, the_repository->index, get_index_file(), 0, - NULL)) + if (write_index_as_tree(&c_tree, the_repository->index, + repo_get_index_file(the_repository), 0, NULL)) return error(_("cannot apply a stash in the middle of a merge")); if (index) { @@ -566,7 +566,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, discard_index(the_repository->index); repo_read_index(the_repository); if (write_index_as_tree(&index_tree, the_repository->index, - get_index_file(), 0, NULL)) + repo_get_index_file(the_repository), 0, NULL)) return error(_("could not save index tree")); reset_head(); @@ -1406,8 +1406,8 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b strbuf_addf(&commit_tree_label, "index on %s\n", msg.buf); commit_list_insert(head_commit, &parents); - if (write_index_as_tree(&info->i_tree, the_repository->index, get_index_file(), 0, - NULL) || + if (write_index_as_tree(&info->i_tree, the_repository->index, + repo_get_index_file(the_repository), 0, NULL) || commit_tree(commit_tree_label.buf, commit_tree_label.len, &info->i_tree, parents, &info->i_commit, NULL, NULL)) { if (!quiet) @@ -1905,7 +1905,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - index_file = get_index_file(); + index_file = repo_get_index_file(the_repository); strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file, (uintmax_t)pid); diff --git a/builtin/update-index.c b/builtin/update-index.c index 35a1f957adc..86c5d40e400 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1239,7 +1239,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) if (newfd < 0) { if (refresh_args.flags & REFRESH_QUIET) exit(128); - unable_to_lock_die(get_index_file(), lock_error); + unable_to_lock_die(repo_get_index_file(the_repository), lock_error); } if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK)) die("Unable to write new index file"); diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 8c75b4609b5..9bcc4470ce1 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -6,7 +6,6 @@ #include "builtin.h" #include "config.h" -#include "environment.h" #include "gettext.h" #include "hex.h" #include "tree.h" @@ -44,7 +43,8 @@ int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix) prepare_repo_settings(the_repository); the_repository->settings.command_requires_full_index = 0; - ret = write_index_as_tree(&oid, the_repository->index, get_index_file(), + ret = write_index_as_tree(&oid, the_repository->index, + repo_get_index_file(the_repository), flags, tree_prefix); switch (ret) { case 0: diff --git a/environment.c b/environment.c index 0a2057399e0..10ef77576c3 100644 --- a/environment.c +++ b/environment.c @@ -306,13 +306,6 @@ int odb_pack_keep(const char *name) return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } -char *get_index_file(void) -{ - if (!the_repository->index_file) - BUG("git environment hasn't been setup"); - return the_repository->index_file; -} - char *get_graft_file(struct repository *r) { if (!r->graft_file) diff --git a/environment.h b/environment.h index 91125d82991..ff590cfff73 100644 --- a/environment.h +++ b/environment.h @@ -106,7 +106,6 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -char *get_index_file(void); char *get_graft_file(struct repository *r); void set_git_dir(const char *path, int make_realpath); const char *get_git_namespace(void); diff --git a/repository.c b/repository.c index 49c42c25daa..849a912b031 100644 --- a/repository.c +++ b/repository.c @@ -112,6 +112,13 @@ const char *repo_get_object_directory(struct repository *repo) return repo->objects->odb->path; } +const char *repo_get_index_file(struct repository *repo) +{ + if (!repo->index_file) + BUG("repository hasn't been set up"); + return repo->index_file; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index 778f1511ab1..15660ac2f19 100644 --- a/repository.h +++ b/repository.h @@ -209,6 +209,7 @@ extern struct repository *the_repository; const char *repo_get_git_dir(struct repository *repo); const char *repo_get_common_dir(struct repository *repo); const char *repo_get_object_directory(struct repository *repo); +const char *repo_get_index_file(struct repository *repo); /* * Define a custom repository layout. Any field can be NULL, which diff --git a/wt-status.c b/wt-status.c index b477239039d..b813d3fe1c4 100644 --- a/wt-status.c +++ b/wt-status.c @@ -16,6 +16,7 @@ #include "revision.h" #include "diffcore.h" #include "quote.h" +#include "repository.h" #include "run-command.h" #include "strvec.h" #include "remote.h" @@ -152,7 +153,7 @@ void wt_status_prepare(struct repository *r, struct wt_status *s) "HEAD", 0, NULL, NULL); s->reference = "HEAD"; s->fp = stdout; - s->index_file = get_index_file(); + s->index_file = repo_get_index_file(the_repository); s->change.strdup_strings = 1; s->untracked.strdup_strings = 1; s->ignored.strdup_strings = 1; From patchwork Thu Sep 12 11:29:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802030 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 3EE5C1A38C1 for ; Thu, 12 Sep 2024 11:29:40 +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=1726140581; cv=none; b=CGax/hZAP03+qJ24i/uz+R/g2LvZsfd6LWtUtov9PRseocFDlT8RNXckMbggKk/4+yF3+cv3SXjax44lG6dYRWm5528g6FSztNuCqX/jvOMlkvpHO55IE1ygca75XYy1SE96e4zRgHG0zrcqf3Xlj70j1ryStVwHpNfOWCy4jk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140581; c=relaxed/simple; bh=f6BRkeTpZimyjiDuJXPzbGUGoUxtlnGK1GAAYC1whDo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ON2YA4ZcEV6E1MOWOVnUrix3EkEbGhMjfuGE7ot+228b1kZP/anU3QQNpkF93LAP/Jqdfu7DY8RqcjOvXQUPs20xzVpLTFSNkYNLJ4MgiNu2g28ho5eAzpczqQQ9l4DNpeNZjLBmzzzcl3CgpqdJnLcURv5XPqVPa6rNeJR5vMk= 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=L0PL2U3b; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=OmO2NWu+; 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="L0PL2U3b"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="OmO2NWu+" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 66C63138061F; Thu, 12 Sep 2024 07:29:39 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 12 Sep 2024 07:29:39 -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=fm1; t=1726140579; x=1726226979; bh=QVR71ChemU FytTnZNjFPkKU01RzVjIDtce8esukklHk=; b=L0PL2U3bQThos8jZsTN3AeLo+m +qF0tFKmtyB4aEkgej+hvpp0lli2VlMAw4YQ1jPRPmY04QZ69qvfK1Bnjl2mxKKz Cv288LaaqdThYqtgoZRoEI214vrk65PUI7jQvnZiBzgivmdvQ4PWwH4ge4WATlW1 /wcl7WOJZ/UjRnUMB3LulGpJUZTNAaSFRK2LLuNNbuBjNeRtfZM/l9TGfSjC5H/Q HBElL+3zD5yJouUfUvtSNlQPnYyIRJBFu98q76tTNFngqBcmPPPIVM8Qn9/f7HI8 4Ad+uhN3HPE+ZxPPirA67BeeaQwAUB2ynXKKTUGGDvvMcFH4CwInorm66C2g== 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= fm1; t=1726140579; x=1726226979; bh=QVR71ChemUFytTnZNjFPkKU01RzV jIDtce8esukklHk=; b=OmO2NWu+MY4ac7IVjZa4e7b7uW8lebQcbAs7kO7RMAmw yAltUUdl7qc/1kGYjJpwCNO+FNewXQjIOaSy/VnupnWTUayJcsfcuWVr6qMqM4S+ 4Qx3W8Em73vJ6K1sjOxaNN0Dv9BSuiylHqKQoCW7N2dSKZFfqIxcw6GPDYAtKGww dHOOrrxgfsgzSTTD8cvXxVyN+WH36PCoxwZRWphSx5KusSlIslftFv0JK8xTQTWa wbYFbFzUOrTxuhg+6QHXFzwTT+MQE8QcLDmf+tQxRKNmkRxe2nkMd/p70ETjM3dT +OdKgB99UhZX7MqzIDvZcSH0B/Gw0uzBTDgXHO8ldg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehg ihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:38 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c7583b0a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:29 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 05/21] environment: make `get_graft_file()` accept a repository 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: The `get_graft_file()` function retrieves the path to the graft file of `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/replace.c | 3 +-- commit.c | 4 ++-- environment.c | 7 ------- environment.h | 2 -- repository.c | 7 +++++++ repository.h | 1 + 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 34cc4672bc1..01161350b1f 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -11,7 +11,6 @@ #include "builtin.h" #include "config.h" #include "editor.h" -#include "environment.h" #include "gettext.h" #include "hex.h" #include "refs.h" @@ -514,7 +513,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle) static int convert_graft_file(int force) { - const char *graft_file = get_graft_file(the_repository); + const char *graft_file = repo_get_graft_file(the_repository); FILE *fp = fopen_or_warn(graft_file, "r"); struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT; struct strvec args = STRVEC_INIT; diff --git a/commit.c b/commit.c index 3238772f521..1f710a92a17 100644 --- a/commit.c +++ b/commit.c @@ -292,14 +292,14 @@ static int read_graft_file(struct repository *r, const char *graft_file) void prepare_commit_graft(struct repository *r) { - char *graft_file; + const char *graft_file; if (r->parsed_objects->commit_graft_prepared) return; if (!startup_info->have_repository) return; - graft_file = get_graft_file(r); + graft_file = repo_get_graft_file(r); read_graft_file(r, graft_file); /* make sure shallows are read */ is_repository_shallow(r); diff --git a/environment.c b/environment.c index 10ef77576c3..371f01a705d 100644 --- a/environment.c +++ b/environment.c @@ -306,13 +306,6 @@ int odb_pack_keep(const char *name) return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } -char *get_graft_file(struct repository *r) -{ - if (!r->graft_file) - BUG("git environment hasn't been setup"); - return r->graft_file; -} - static void set_git_dir_1(const char *path) { xsetenv(GIT_DIR_ENVIRONMENT, path, 1); diff --git a/environment.h b/environment.h index ff590cfff73..d12c48481b6 100644 --- a/environment.h +++ b/environment.h @@ -1,7 +1,6 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H -struct repository; struct strvec; /* @@ -106,7 +105,6 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -char *get_graft_file(struct repository *r); void set_git_dir(const char *path, int make_realpath); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); diff --git a/repository.c b/repository.c index 849a912b031..c2c231a7fd8 100644 --- a/repository.c +++ b/repository.c @@ -119,6 +119,13 @@ const char *repo_get_index_file(struct repository *repo) return repo->index_file; } +const char *repo_get_graft_file(struct repository *repo) +{ + if (!repo->graft_file) + BUG("repository hasn't been set up"); + return repo->graft_file; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index 15660ac2f19..ad0f984b444 100644 --- a/repository.h +++ b/repository.h @@ -210,6 +210,7 @@ const char *repo_get_git_dir(struct repository *repo); const char *repo_get_common_dir(struct repository *repo); const char *repo_get_object_directory(struct repository *repo); const char *repo_get_index_file(struct repository *repo); +const char *repo_get_graft_file(struct repository *repo); /* * Define a custom repository layout. Any field can be NULL, which From patchwork Thu Sep 12 11:29: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: 13802031 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 CA7F0190482 for ; Thu, 12 Sep 2024 11:29:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140584; cv=none; b=vAhGV5gQ5FPJGOcUxGsVnKOmIucduDb6UigXbfY/lb57+G25Ibn0IA4fpS8rb1yyzR+zD/sG88OEXFNpiKc5MWFdNBVg7x/0jWQbD6HIUuMCcsGpKD0lsgaNNtGmotibmyCWLia6QoxfCltZUGA7Qy9m5awq9oOrckF1t/mnrj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140584; c=relaxed/simple; bh=bwSIMb5lftWN/Wzk5Ad3bw+bTyALX7vXZRn3zl/7Vjg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l4dSlu0LOmlYq86xZtneVo4wruLZAYOpwxXrlMNT9MQaEhbDwZ78pnZWXyHrXG+ewM00yeweaF6Jd8Z48PVFDTxhz2gX4U32LQ5zMHBFOPl4kKsnWA48oXQLxkSuhhC4aZ3Fvs69bDMMZCrcPxQFWdMdc2x7yFnoGQuppiOR7po= 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=n+3g+ehb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=inPHSg02; arc=none smtp.client-ip=103.168.172.157 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="n+3g+ehb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="inPHSg02" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0262A11405E3; Thu, 12 Sep 2024 07:29:42 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 12 Sep 2024 07:29:42 -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=fm1; t=1726140581; x=1726226981; bh=H1YW8CFrIC Lm5U7/FgRkp14jNXCqdzNp+Jeom0oAQSY=; b=n+3g+ehb+aP7E9nGAZBVV7nHd7 1GxLFS1qwk0I4cxk6Wsf8fUZXzufgbTPpT7VDvh7hOi4qxSvKLpa6YpASvZorZjE VZWsOqwpBSqQIbwqHS/MmMjZ864CC9nlDKbVuaRaxpW9UmBtUFb+bQguc0AXp0Z9 D26/II266g1CHNKheryIRiln6SMx57bxXieayEXVioizLW0mOOf479GPsj5OFRv1 KAVdwb8TGUYqBKL35RkW6Oodb/R0FpwCl264Wn3pg+RCyBCG1/yvh+bv1Q45lS9k VWReyXdRuWawxHlITb8SjrIKAisM94ANKagYBVVeNRJB/n59qrD0UdE79qzQ== 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= fm1; t=1726140581; x=1726226981; bh=H1YW8CFrICLm5U7/FgRkp14jNXCq dzNp+Jeom0oAQSY=; b=inPHSg02DUZyksb6MG5I62wFR/UAhACqVvYsyr1rM2oY 4twu16o/3xDbbVN6Haoc0BRX158PeDB8Qt+vMrQwC3tJ+6sy4YvgUs+M4VRSygwq 7srCrn4d7COMcWoZ1EgGu58sW1JDGNJmiQ674PazooYgDqAQuT6msF/pKaxccA/j 3UkxWvMSZ1AKc+x2RPgjBm7+EuoZjkbex1lNxEUyWCwagcB6XdJbydq0kKSVW5J/ MUPsyDsDO2NaINeLN+j+fDhv4tzpaiX3Z8GV2Hn6kczcqnhQpkvandDflXR1Mehf yJCgmGEoJlzrBZINtYM/32zO8UxvbhRabV0LKexsOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohep tggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvg hrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a81222d5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:32 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 06/21] environment: make `get_git_work_tree()` accept a repository Message-ID: <00950932195ddb53dd1e54f93a6040bce4f6a434.1726139990.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 `get_git_work_tree()` function retrieves the path of the work tree of `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/blame.c | 2 +- builtin/difftool.c | 4 ++-- builtin/fsmonitor--daemon.c | 4 ++-- builtin/init-db.c | 4 ++-- builtin/reset.c | 5 +++-- builtin/rev-parse.c | 4 ++-- builtin/stash.c | 2 +- builtin/submodule--helper.c | 2 +- builtin/update-index.c | 2 +- dir.c | 3 ++- environment.c | 7 +------ environment.h | 1 - fsmonitor.c | 3 ++- pathspec.c | 2 +- repository.c | 5 +++++ repository.h | 1 + setup.c | 16 ++++++++-------- trace.c | 3 +-- 18 files changed, 36 insertions(+), 34 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 35e975fb132..1ffdda50904 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1081,7 +1081,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) path = add_prefix(prefix, argv[1]); argv[1] = argv[2]; } else { /* (2a) */ - if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree()) + if (argc == 2 && is_a_rev(argv[1]) && !repo_get_work_tree(the_repository)) die("missing to blame"); path = add_prefix(prefix, argv[argc - 1]); } diff --git a/builtin/difftool.c b/builtin/difftool.c index 8c59411e6e0..7f2cbd797ad 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -378,7 +378,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, struct hashmap wt_modified, tmp_modified; int indices_loaded = 0; - workdir = get_git_work_tree(); + workdir = repo_get_work_tree(the_repository); /* Setup temp directories */ tmp = getenv("TMPDIR"); @@ -739,7 +739,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix) if (!no_index){ setup_work_tree(); setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1); - setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1); + setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(repo_get_work_tree(the_repository)), 1); } else if (dir_diff) die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index"); diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index c54e736716a..25451d999e9 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -2,7 +2,6 @@ #include "abspath.h" #include "config.h" #include "dir.h" -#include "environment.h" #include "gettext.h" #include "parse-options.h" #include "fsmonitor-ll.h" @@ -1291,7 +1290,8 @@ static int fsmonitor_run_daemon(void) /* Prepare to (recursively) watch the directory. */ strbuf_init(&state.path_worktree_watch, 0); - strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree())); + strbuf_addstr(&state.path_worktree_watch, + absolute_path(repo_get_work_tree(the_repository))); state.nr_paths_watching = 1; strbuf_init(&state.alias.alias, 0); diff --git a/builtin/init-db.c b/builtin/init-db.c index 582dcf20f86..fb04962dcea 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -231,9 +231,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) set_git_work_tree(work_tree); else set_git_work_tree(git_work_tree_cfg); - if (access(get_git_work_tree(), X_OK)) + if (access(repo_get_work_tree(the_repository), X_OK)) die_errno (_("Cannot access work tree '%s'"), - get_git_work_tree()); + repo_get_work_tree(the_repository)); } else { if (real_git_dir) diff --git a/builtin/reset.c b/builtin/reset.c index 5f941fb3a29..86b2f07d660 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -26,6 +26,7 @@ #include "object-name.h" #include "parse-options.h" #include "path.h" +#include "repository.h" #include "unpack-trees.h" #include "cache-tree.h" #include "setup.h" @@ -441,7 +442,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) else trace2_cmd_mode(reset_type_names[reset_type]); - if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree())) + if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository))) setup_work_tree(); if (reset_type == MIXED && is_bare_repository()) @@ -474,7 +475,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) goto cleanup; } the_repository->index->updated_skipworktree = 1; - if (!no_refresh && get_git_work_tree()) { + if (!no_refresh && repo_get_work_tree(the_repository)) { uint64_t t_begin, t_delta_in_ms; t_begin = getnanotime(); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index cd85fe57bb0..a5108266daf 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -967,7 +967,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--show-toplevel")) { - const char *work_tree = get_git_work_tree(); + const char *work_tree = repo_get_work_tree(the_repository); if (work_tree) print_path(work_tree, prefix, format, DEFAULT_UNMODIFIED); else @@ -992,7 +992,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) const char *pfx = prefix; if (!is_inside_work_tree()) { const char *work_tree = - get_git_work_tree(); + repo_get_work_tree(the_repository); if (work_tree) printf("%s\n", work_tree); continue; diff --git a/builtin/stash.c b/builtin/stash.c index f2ec9549a47..354641b3f10 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -641,7 +641,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, cp.git_cmd = 1; cp.dir = prefix; strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s", - absolute_path(get_git_work_tree())); + absolute_path(repo_get_work_tree(the_repository))); strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s", absolute_path(repo_get_git_dir(the_repository))); strvec_push(&cp.args, "status"); diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 85fb23dee84..865b454d693 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1709,7 +1709,7 @@ static int clone_submodule(const struct module_clone_data *clone_data, exit(128); if (!is_absolute_path(clone_data->path)) - clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(), + clone_data_path = to_free = xstrfmt("%s/%s", repo_get_work_tree(the_repository), clone_data->path); if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) diff --git a/builtin/update-index.c b/builtin/update-index.c index 86c5d40e400..8baa2256194 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1194,7 +1194,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) "remove or change it, if you really want to " "enable the untracked cache")); add_untracked_cache(the_repository->index); - report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); + report(_("Untracked cache enabled for '%s'"), repo_get_work_tree(the_repository)); break; default: BUG("bad untracked_cache value: %d", untracked_cache); diff --git a/dir.c b/dir.c index 5a23376bdae..c43b5e30813 100644 --- a/dir.c +++ b/dir.c @@ -20,6 +20,7 @@ #include "object-store-ll.h" #include "path.h" #include "refs.h" +#include "repository.h" #include "wildmatch.h" #include "pathspec.h" #include "utf8.h" @@ -2838,7 +2839,7 @@ static const char *get_ident_string(void) return sb.buf; if (uname(&uts) < 0) die_errno(_("failed to get kernel name and information")); - strbuf_addf(&sb, "Location %s, system %s", get_git_work_tree(), + strbuf_addf(&sb, "Location %s, system %s", repo_get_work_tree(the_repository), uts.sysname); return sb.buf; } diff --git a/environment.c b/environment.c index 371f01a705d..4d0637b3822 100644 --- a/environment.c +++ b/environment.c @@ -219,7 +219,7 @@ void setup_git_env(const char *git_dir) int is_bare_repository(void) { /* if core.bare is not 'false', let's see if there is a work tree */ - return is_bare_repository_cfg && !get_git_work_tree(); + return is_bare_repository_cfg && !repo_get_work_tree(the_repository); } int have_git_dir(void) @@ -268,11 +268,6 @@ void set_git_work_tree(const char *new_work_tree) repo_set_worktree(the_repository, new_work_tree); } -const char *get_git_work_tree(void) -{ - return the_repository->worktree; -} - int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) { int fd; diff --git a/environment.h b/environment.h index d12c48481b6..52e1803aba6 100644 --- a/environment.h +++ b/environment.h @@ -108,7 +108,6 @@ extern char *git_work_tree_cfg; void set_git_dir(const char *path, int make_realpath); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); -const char *get_git_work_tree(void); void set_git_work_tree(const char *tree); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" diff --git a/fsmonitor.c b/fsmonitor.c index 28130f748f7..237ca59d004 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -8,6 +8,7 @@ #include "fsmonitor.h" #include "fsmonitor-ipc.h" #include "name-hash.h" +#include "repository.h" #include "run-command.h" #include "strbuf.h" #include "trace2.h" @@ -169,7 +170,7 @@ static int query_fsmonitor_hook(struct repository *r, strvec_pushf(&cp.args, "%d", version); strvec_pushf(&cp.args, "%s", last_update); cp.use_shell = 1; - cp.dir = get_git_work_tree(); + cp.dir = repo_get_work_tree(the_repository); trace2_region_enter("fsm_hook", "query", NULL); diff --git a/pathspec.c b/pathspec.c index 416fe1e3dcc..0fc6f84a6e6 100644 --- a/pathspec.c +++ b/pathspec.c @@ -495,7 +495,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, if (!have_git_dir()) die(_("'%s' is outside the directory tree"), copyfrom); - hint_path = get_git_work_tree(); + hint_path = repo_get_work_tree(the_repository); if (!hint_path) hint_path = repo_get_git_dir(the_repository); die(_("%s: '%s' is outside repository at '%s'"), elt, diff --git a/repository.c b/repository.c index c2c231a7fd8..afdd1946211 100644 --- a/repository.c +++ b/repository.c @@ -126,6 +126,11 @@ const char *repo_get_graft_file(struct repository *repo) return repo->graft_file; } +const char *repo_get_work_tree(struct repository *repo) +{ + return repo->worktree; +} + static void repo_set_commondir(struct repository *repo, const char *commondir) { diff --git a/repository.h b/repository.h index ad0f984b444..c603e969ae7 100644 --- a/repository.h +++ b/repository.h @@ -211,6 +211,7 @@ const char *repo_get_common_dir(struct repository *repo); const char *repo_get_object_directory(struct repository *repo); const char *repo_get_index_file(struct repository *repo); const char *repo_get_graft_file(struct repository *repo); +const char *repo_get_work_tree(struct repository *repo); /* * Define a custom repository layout. Any field can be NULL, which diff --git a/setup.c b/setup.c index 1ebcab625fe..1bfec288ab6 100644 --- a/setup.c +++ b/setup.c @@ -51,7 +51,7 @@ static int abspath_part_inside_repo(char *path) size_t wtlen; char *path0; int off; - const char *work_tree = precompose_string_if_needed(get_git_work_tree()); + const char *work_tree = precompose_string_if_needed(repo_get_work_tree(the_repository)); struct strbuf realpath = STRBUF_INIT; if (!work_tree) @@ -147,7 +147,7 @@ char *prefix_path(const char *prefix, int len, const char *path) { char *r = prefix_path_gently(prefix, len, NULL, path); if (!r) { - const char *hint_path = get_git_work_tree(); + const char *hint_path = repo_get_work_tree(the_repository); if (!hint_path) hint_path = repo_get_git_dir(the_repository); die(_("'%s' is outside repository at '%s'"), path, @@ -475,7 +475,7 @@ int is_inside_git_dir(void) int is_inside_work_tree(void) { if (inside_work_tree < 0) - inside_work_tree = is_inside_dir(get_git_work_tree()); + inside_work_tree = is_inside_dir(repo_get_work_tree(the_repository)); return inside_work_tree; } @@ -490,7 +490,7 @@ void setup_work_tree(void) if (work_tree_config_is_bogus) die(_("unable to set up work tree using invalid config")); - work_tree = get_git_work_tree(); + work_tree = repo_get_work_tree(the_repository); if (!work_tree || chdir_notify(work_tree)) die(_("this operation must be run in a work tree")); @@ -547,7 +547,7 @@ static void setup_original_cwd(void) * Get our worktree; we only protect the current working directory * if it's in the worktree. */ - worktree = get_git_work_tree(); + worktree = repo_get_work_tree(the_repository); if (!worktree) goto no_prevention_needed; @@ -1062,9 +1062,9 @@ static const char *setup_explicit_git_dir(const char *gitdirenv, set_git_work_tree("."); /* set_git_work_tree() must have been called by now */ - worktree = get_git_work_tree(); + worktree = repo_get_work_tree(the_repository); - /* both get_git_work_tree() and cwd are already normalized */ + /* both repo_get_work_tree() and cwd are already normalized */ if (!strcmp(cwd->buf, worktree)) { /* cwd == worktree */ set_git_dir(gitdirenv, 0); free(gitfile); @@ -2192,7 +2192,7 @@ static int create_default_files(const char *template_path, char *path; int reinit; int filemode; - const char *work_tree = get_git_work_tree(); + const char *work_tree = repo_get_work_tree(the_repository); /* * First copy the templates -- we might have the default diff --git a/trace.c b/trace.c index e6728c301f3..d8c43773ae8 100644 --- a/trace.c +++ b/trace.c @@ -25,7 +25,6 @@ #include "git-compat-util.h" #include "abspath.h" -#include "environment.h" #include "repository.h" #include "quote.h" #include "setup.h" @@ -308,7 +307,7 @@ void trace_repo_setup(void) cwd = xgetcwd(); - if (!(git_work_tree = get_git_work_tree())) + if (!(git_work_tree = repo_get_work_tree(the_repository))) git_work_tree = "(null)"; if (!startup_info->prefix) From patchwork Thu Sep 12 11:29: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: 13802032 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 81DBC1A3AA5 for ; Thu, 12 Sep 2024 11:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140587; cv=none; b=QB2oEH7cf2566Qu40dIteOfXuesC5kFCiYGMKoYf3Rv+lYrFnONcv3jAZ7ZB+s8Bp/Knq29VbAJKo2hPhm4+N7AR08AWljhQnMcKDPkdiCTrCLAAt1hp2i8XLVs30G9/hxwekC6hq937HTeqSV4IenZB3bWcM5kKvKFVcOvyA50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140587; c=relaxed/simple; bh=CzQ2aAxrfKSjRqcRE1Xy/vWeWcIhl2V2WYhEwkT9crs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VPwAVQXUW4TWVDNY4PxTmvAVCoLyxA8S4aVBpvDT2gRhcZ2NpbSukVKLoZvU0/oBdtgR5HVqFe/eoxKOKFD2q4RqcYmVX9ndPE9NEwALMfDnNVEuCWLR8rjyEXeFAWUl/L9A0vJpzsjn1S31AFsI9XPZ23L8gczmkUdxW7EoBU8= 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=QBXFHfQm; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Au5aiYGc; arc=none smtp.client-ip=103.168.172.157 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="QBXFHfQm"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Au5aiYGc" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id A02D011405E6; Thu, 12 Sep 2024 07:29:44 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 12 Sep 2024 07:29:44 -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=fm1; t=1726140584; x=1726226984; bh=aax87Yuv6K YGoHaOjvEGXCaJHy/nYHDTQF1POz3vPcI=; b=QBXFHfQmrqPsRb9Tfc5b2CySev v0l5KzmqWbB8lp7dfZ+oGAdlaZbZ5OKjE7/PEUC/Bwym7DQC0jtKnNV5AOYK2KpI FwO/HXcf0qfOECDPkMxRsdNdtTW0NzmllTipJuMaUeQaEBM6S+wqCO8UztAISrvY MT2iEF1zffV07JdL0AvmZXP9aW262Cfv+t7yc/cXnu34vwCG9JaWFLB/+T2twEUY hIJ9+HGyVlzLQetb9F2cdmAJOI6yQFqfYZuaN/L7B5TgRPnQF2nTNyJHBvyvbRQ9 o77+P+LDDT5bfz1ebGnGhZ1hJ4vI8X+j/qE6vzzSZKZNHsAOj7jT4pUkM/zg== 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= fm1; t=1726140584; x=1726226984; bh=aax87Yuv6KYGoHaOjvEGXCaJHy/n YHDTQF1POz3vPcI=; b=Au5aiYGcs2bURkBh3vT4+GHiPY7t581aw0f8c7GJ1S4o ckqBEXMWpJDzMSvIWicPDr/ptvtBPa0eNNwc04Q7bKLClGVoVJo/31uHU6volwnl tMRwG3u32mKil4ZH1BLP1hPKlnS/h0RWkQTTdwqirk+SYuS9lPQoWLr6a4YVGXj5 XcUivLLQvvbKIQ+VSQ8vcofp3Yc8xLKSXqSZ0GlM2z6ZHZQevBsvF/NO6iQbJw/8 qW1WMNbQAQT1rqItEXrYK4yxx5CsKbb/v3T4YToOMm7KKtcFaBq69rQTKZiDbDDU TnN0P0S2NrYx71VTSlMs/Di/SLpxrrNp6AoU0frQZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehjlhht ohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhgpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0a927e33 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:34 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:43 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 07/21] config: document `read_early_config()` and `read_very_early_config()` Message-ID: <8c0010b439725585ffc3a9bb4f1f7eb4944a2d6f.1726139990.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: It's not clear what `read_early_config()` and `read_very_early_config()` do differently compared to `repo_read_config()` from just looking at their names. Document both of these in the header file to clarify their intent. Signed-off-by: Patrick Steinhardt --- config.c | 4 ---- config.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 0b87f0f9050..a8357ea9544 100644 --- a/config.c +++ b/config.c @@ -2234,10 +2234,6 @@ void read_early_config(config_fn_t cb, void *data) strbuf_release(&gitdir); } -/* - * Read config but only enumerate system and global settings. - * Omit any repo-local, worktree-local, or command-line settings. - */ void read_very_early_config(config_fn_t cb, void *data) { struct config_options opts = { 0 }; diff --git a/config.h b/config.h index d0497157c52..f5fa833cb98 100644 --- a/config.h +++ b/config.h @@ -192,7 +192,18 @@ int git_config_from_blob_oid(config_fn_t fn, const char *name, void git_config_push_parameter(const char *text); void git_config_push_env(const char *spec); int git_config_from_parameters(config_fn_t fn, void *data); + +/* + * Read config when the Git directory has not yet been set up. In case + * `the_repository` has not yet been set up, try to discover the Git + * directory to read the configuration from. + */ void read_early_config(config_fn_t cb, void *data); + +/* + * Read config but only enumerate system and global settings. + * Omit any repo-local, worktree-local, or command-line settings. + */ void read_very_early_config(config_fn_t cb, void *data); /** From patchwork Thu Sep 12 11:29:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802033 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 D2C151A0BCE for ; Thu, 12 Sep 2024 11:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140589; cv=none; b=hFQxoEyx9xkFRDIt3NvjuuaAFC5Df5/ailNJSgm56TTrQLpO+Rn2moZuxrpxHjAdxwzlc/4NtMgxfcoqXUAlPSiyri/XTG7qHYbith3/haWQuSaNmcYahv/2jnYb/4VeYRTwmnZKvMclsGzPC2XCph8OhQxvbAgwoqNkr4wvi50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140589; c=relaxed/simple; bh=bAJswoDzfxaX16rF+qk1R1DcHxDVE4DJyxZ62mhIj1I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gWEoos4NkPkHvkEhM0hLCx5ja8phfE6k1HTzFj2C2AwdU9hrvH3Z9WoRwtfMeAxTutI6HNUL0M+LnNAsJQY7K0/r4ibiW0n+Qcr3WgN9Fbudb0MwaNDY+3zordaZZQkppuI9JD3XS9SUurSQtSoghVFPj66bGEtyDG17RuulJB8= 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=MnNXkJr5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qkwWgqlO; arc=none smtp.client-ip=103.168.172.157 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="MnNXkJr5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qkwWgqlO" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 3C81311405E3; Thu, 12 Sep 2024 07:29:47 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 12 Sep 2024 07:29:47 -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=fm1; t=1726140587; x=1726226987; bh=dHQOZZFI/M cq+23BlvBJVNXsJfpmkGp4NZk9M6rc/wE=; b=MnNXkJr5FwNg5gsnAHqjA6rdlq mc8kQPqu29YRyCFqmQQ5UXO6TYBe3BSyE6PrbVpUlzF9EUsDLGAXVfVtdwj3DwqI 5LKnz3fLEGBNDq/zlnTKel1JvRcx++EUDANNLtzTBw03i6iISTkS9tHKvd5ptmzC iyWDwaHDg9ot8AVu7Y17YAAsiJ6ilKb2Da+gu6kP0E3Zv0is/cpZ9xte15z6+swv /imcB9j+aNav1fVhrxS+bftKNe7bGGITZZmV7Jpr2g3lqn6Qx/w1rX83KuXwEUiU QCeN5MQT0ptlnXoH6YrYZvCnubzC9KPW3G2vbsmZWyElC3vLYAoTQZiQz8Ow== 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= fm1; t=1726140587; x=1726226987; bh=dHQOZZFI/Mcq+23BlvBJVNXsJfpm kGp4NZk9M6rc/wE=; b=qkwWgqlOj8yzLhmqKRPp6uQM56DOAeIj8KyTDTFv3m0B hjfkSgCZR3x2ArhqKpKNoqJCH6lk8mucjVF3O8g+odBOWyNJctQzi+iRhdCMYF/w iYIdehhOfQRgCqY9RSkq+ZdWhdRhGC9YoxgKvB7h3pufJo1YGicRk5Fg3y3FaA0+ hrCXJODgrGcKZWKDyIXJvB/luzP389cOxFFmXaUgnW/vpyNQSyc2K4xvgiqhM5lT 3Vm1iUdFn1+9cUXPC6QUvbDB77ND71GKrRrHE7MomPqs2G3ZItRNT34a45dr0CR3 7PSw0uLFVKrYrhGfjxJheCsP2ZoHCmnawek6sxa2sw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegt rghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihhtsehvghgvrh drkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:45 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 61a990fa (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:37 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:45 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 08/21] config: make dependency on repo in `read_early_config()` explicit Message-ID: <1ed3d3f1d7142129212750602585550c69aa599e.1726139990.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 `read_early_config()` function can be used to read configuration where a repository has not yet been set up. As such, it is optional whether or not `the_repository` has already been initialized. If it was initialized we use its commondir and gitdir. If not, the function will try to detect the Git directories by itself and, if found, also parse their config files. This means that we implicitly rely on `the_repository`. Make this dependency explicit by passing a `struct repository`. This allows us to again drop the `USE_THE_REPOSITORY_VARIABLE` define in "config.c". Signed-off-by: Patrick Steinhardt --- alias.c | 6 ++++-- config.c | 10 ++++------ config.h | 2 +- help.c | 2 +- pager.c | 7 +++++-- t/helper/test-config.c | 3 ++- trace2/tr2_cfg.c | 4 +++- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/alias.c b/alias.c index 4daafd9bdae..1a1a141a0ae 100644 --- a/alias.c +++ b/alias.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "alias.h" #include "config.h" @@ -37,7 +39,7 @@ char *alias_lookup(const char *alias) { struct config_alias_data data = { alias, NULL }; - read_early_config(config_alias_cb, &data); + read_early_config(the_repository, config_alias_cb, &data); return data.v; } @@ -46,7 +48,7 @@ void list_aliases(struct string_list *list) { struct config_alias_data data = { NULL, NULL, list }; - read_early_config(config_alias_cb, &data); + read_early_config(the_repository, config_alias_cb, &data); } void quote_cmdline(struct strbuf *buf, const char **argv) diff --git a/config.c b/config.c index a8357ea9544..043e1c8a078 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" @@ -2204,7 +2202,7 @@ static void configset_iter(struct config_set *set, config_fn_t fn, void *data) } } -void read_early_config(config_fn_t cb, void *data) +void read_early_config(struct repository *repo, config_fn_t cb, void *data) { struct config_options opts = {0}; struct strbuf commondir = STRBUF_INIT; @@ -2212,9 +2210,9 @@ void read_early_config(config_fn_t cb, void *data) opts.respect_includes = 1; - if (have_git_dir()) { - opts.commondir = repo_get_common_dir(the_repository); - opts.git_dir = repo_get_git_dir(the_repository); + if (repo && repo->gitdir) { + opts.commondir = repo_get_common_dir(repo); + opts.git_dir = repo_get_git_dir(repo); /* * When setup_git_directory() was not yet asked to discover the * GIT_DIR, we ask discover_git_directory() to figure out whether there diff --git a/config.h b/config.h index f5fa833cb98..5c730c4f899 100644 --- a/config.h +++ b/config.h @@ -198,7 +198,7 @@ int git_config_from_parameters(config_fn_t fn, void *data); * `the_repository` has not yet been set up, try to discover the Git * directory to read the configuration from. */ -void read_early_config(config_fn_t cb, void *data); +void read_early_config(struct repository *repo, config_fn_t cb, void *data); /* * Read config but only enumerate system and global settings. diff --git a/help.c b/help.c index c03863f2265..413c93edaea 100644 --- a/help.c +++ b/help.c @@ -618,7 +618,7 @@ const char *help_unknown_cmd(const char *cmd) memset(&other_cmds, 0, sizeof(other_cmds)); memset(&aliases, 0, sizeof(aliases)); - read_early_config(git_unknown_cmd_config, NULL); + read_early_config(the_repository, git_unknown_cmd_config, NULL); /* * Disable autocorrection prompt in a non-interactive session diff --git a/pager.c b/pager.c index 9c24ce62633..40b664f893c 100644 --- a/pager.c +++ b/pager.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "editor.h" @@ -92,7 +94,8 @@ const char *git_pager(int stdout_is_tty) pager = getenv("GIT_PAGER"); if (!pager) { if (!pager_program) - read_early_config(core_pager_config, NULL); + read_early_config(the_repository, + core_pager_config, NULL); pager = pager_program; } if (!pager) @@ -298,7 +301,7 @@ int check_pager_config(const char *cmd) data.want = -1; data.value = NULL; - read_early_config(pager_command_config, &data); + read_early_config(the_repository, pager_command_config, &data); if (data.value) pager_program = data.value; diff --git a/t/helper/test-config.c b/t/helper/test-config.c index e193079ed54..33247f0e92e 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -96,7 +96,8 @@ int cmd__config(int argc, const char **argv) struct config_set cs; if (argc == 3 && !strcmp(argv[1], "read_early_config")) { - read_early_config(early_config_cb, (void *)argv[2]); + read_early_config(the_repository, early_config_cb, + (void *)argv[2]); return 0; } diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c index d96d908bb9d..22a99a0682a 100644 --- a/trace2/tr2_cfg.c +++ b/trace2/tr2_cfg.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "strbuf.h" @@ -124,7 +126,7 @@ void tr2_cfg_list_config_fl(const char *file, int line) struct tr2_cfg_data data = { file, line }; if (tr2_cfg_load_patterns() > 0) - read_early_config(tr2_cfg_cb, &data); + read_early_config(the_repository, tr2_cfg_cb, &data); } void tr2_list_env_vars_fl(const char *file, int line) From patchwork Thu Sep 12 11:29:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802034 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 9928D1A3BD4 for ; Thu, 12 Sep 2024 11:29:50 +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=1726140592; cv=none; b=TGF/65EMEMAJSUHyd3Y3eN0lb3Q9GgK8lXOI/QkvSXslBMq79NPkz4EXKVe5LUNQ/++31MDA4jPmlvtqeq/rRDINXO65GhUMIqy5DMCP4T+eEmDLKd1jscav6b0NjpH0/AvWhNT5zVcyrQpYzcsQBC6oNvONRnEerNkcejO24b0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140592; c=relaxed/simple; bh=PT4lPzQ9G2Ri0F+lmqvBNswi8qSX7ttf7tpfNNIqEWc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ST2AVuznXW/8DHncedz4VbTjWRphrh4FpqsaA/Xpn/nlqAvcgSKWd9S3bjNUl7etqnMHkN6J5WYmYjaeLT7eRXUpOGOgYOKbP7OutS0OJjXWidtDzvUCLHT0JNOuSI+T5udBZLVT5wKqcklENbNGRc6vub4eHQkvnQMP5yBb8gU= 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=tR95sQqT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HQuaXmr1; 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="tR95sQqT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HQuaXmr1" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id B1A721380625; Thu, 12 Sep 2024 07:29:49 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Thu, 12 Sep 2024 07:29: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=fm1; t=1726140589; x=1726226989; bh=DYoYt1paYM ZnFG78HHjz4bZEAyCKrpbLNx9qIi48DEY=; b=tR95sQqTyk9HKwTaduoyhiO2lc l+3W639i8X7AHTM+1HgrmDvvb2ot7FTvxm04yTyHbWVFyWq0E8SmkD3+Yb3kSSrU INaT2XPFK0Crwcl/uB64QYl8ErdhojX+5U54vRqkln8dMX4el7O3IsHdi+JpvcjJ 1mrUJusctUOZ2HJHgyQ7ZsastBMFosPRBD37XFPxgsO6J4mSFtWqgQB0CKG6BDjA 3eUSfhoJhxgWwRuw2HTTa23DQWioS3siUX4tLKQbkosAuut6jQjeQZVyUo20R658 zTD/pkRvriSXSq2LtEewcxUl/5/CCUJ+2fRFJe7vLa10Slhku7lP2E0+EtaQ== 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= fm1; t=1726140589; x=1726226989; bh=DYoYt1paYMZnFG78HHjz4bZEAyCK rpbLNx9qIi48DEY=; b=HQuaXmr1Lu+VhTryiA38L7Vlkhq+jwV7k6q4eer40sjN GpT3SFHXWSMJ8dsiZRlg2va2jvc3UjnSzAhjb8GOJeE3bz5AjgdxbALY3szAPcpD xVhXXG/kdTepQVEgiQI4XYg11C/jZN/ngDaTkQHTFv/ioY3RBZTQA7chqmr2utcg PEoNKics058XFZxN+VUEBHuxN002Jsq6VzJ2+ZU4KWC0OuQ6MDIZqfBtvduT1wXS HA31WwoZrJRnjUyFp9Qk9oNB4FOygUfiKXNT0NeB21d/At+FMzEa/bALCBbvPsnh VqBIZFFF9+uuLfRHgMCZQztpIz5/iRTdjauj2wXGHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehkrghrthhh ihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesgh hoohhglhgvrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhr gh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:48 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5a25f607 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:40 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 09/21] environment: move object database functions into object layer 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: The `odb_mkstemp()` and `odb_pack_keep()` functions are quite clearly tied to the object store, but regardless of that they are located in "environment.c". Move them over, which also helps to get rid of dependencies on `the_repository` in the environment subsystem. Signed-off-by: Patrick Steinhardt --- bundle-uri.c | 2 +- environment.c | 34 ---------------------------------- environment.h | 15 --------------- object-file.c | 33 +++++++++++++++++++++++++++++++++ object-store-ll.h | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 50 deletions(-) diff --git a/bundle-uri.c b/bundle-uri.c index 1e0ee156ba3..eb8eca078bb 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -4,7 +4,6 @@ #include "bundle-uri.h" #include "bundle.h" #include "copy.h" -#include "environment.h" #include "gettext.h" #include "refs.h" #include "run-command.h" @@ -13,6 +12,7 @@ #include "config.h" #include "fetch-pack.h" #include "remote.h" +#include "object-store-ll.h" static struct { enum bundle_list_heuristic heuristic; diff --git a/environment.c b/environment.c index 4d0637b3822..f337efd1dd5 100644 --- a/environment.c +++ b/environment.c @@ -23,7 +23,6 @@ #include "commit.h" #include "strvec.h" #include "object-file.h" -#include "object-store-ll.h" #include "path.h" #include "replace-object.h" #include "tmp-objdir.h" @@ -268,39 +267,6 @@ void set_git_work_tree(const char *new_work_tree) repo_set_worktree(the_repository, new_work_tree); } -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) -{ - int fd; - /* - * we let the umask do its job, don't try to be more - * restrictive except to remove write permission. - */ - int mode = 0444; - git_path_buf(temp_filename, "objects/%s", pattern); - fd = git_mkstemp_mode(temp_filename->buf, mode); - if (0 <= fd) - return fd; - - /* slow path */ - /* some mkstemp implementations erase temp_filename on failure */ - git_path_buf(temp_filename, "objects/%s", pattern); - safe_create_leading_directories(temp_filename->buf); - return xmkstemp_mode(temp_filename->buf, mode); -} - -int odb_pack_keep(const char *name) -{ - int fd; - - fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); - if (0 <= fd) - return fd; - - /* slow path */ - safe_create_leading_directories_const(name); - return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); -} - static void set_git_dir_1(const char *path) { xsetenv(GIT_DIR_ENVIRONMENT, path, 1); diff --git a/environment.h b/environment.h index 52e1803aba6..682d4f2e3b5 100644 --- a/environment.h +++ b/environment.h @@ -200,21 +200,6 @@ extern int grafts_keep_true_parents; extern int repository_format_precious_objects; -/* - * Create a temporary file rooted in the object database directory, or - * die on failure. The filename is taken from "pattern", which should have the - * usual "XXXXXX" trailer, and the resulting filename is written into the - * "template" buffer. Returns the open descriptor. - */ -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); - -/* - * Create a pack .keep file named "name" (which should generally be the output - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on - * error. - */ -int odb_pack_keep(const char *name); - const char *get_log_output_encoding(void); const char *get_commit_output_encoding(void); diff --git a/object-file.c b/object-file.c index fa4121b98ad..968da27cd41 100644 --- a/object-file.c +++ b/object-file.c @@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path) return result; } +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) +{ + int fd; + /* + * we let the umask do its job, don't try to be more + * restrictive except to remove write permission. + */ + int mode = 0444; + git_path_buf(temp_filename, "objects/%s", pattern); + fd = git_mkstemp_mode(temp_filename->buf, mode); + if (0 <= fd) + return fd; + + /* slow path */ + /* some mkstemp implementations erase temp_filename on failure */ + git_path_buf(temp_filename, "objects/%s", pattern); + safe_create_leading_directories(temp_filename->buf); + return xmkstemp_mode(temp_filename->buf, mode); +} + +int odb_pack_keep(const char *name) +{ + int fd; + + fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); + if (0 <= fd) + return fd; + + /* slow path */ + safe_create_leading_directories_const(name); + return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); +} + static void fill_loose_path(struct strbuf *buf, const struct object_id *oid) { int i; diff --git a/object-store-ll.h b/object-store-ll.h index c5f2bb2fc2f..53b8e693b1b 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -231,6 +231,21 @@ struct raw_object_store { struct raw_object_store *raw_object_store_new(void); void raw_object_store_clear(struct raw_object_store *o); +/* + * Create a temporary file rooted in the object database directory, or + * die on failure. The filename is taken from "pattern", which should have the + * usual "XXXXXX" trailer, and the resulting filename is written into the + * "template" buffer. Returns the open descriptor. + */ +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); + +/* + * Create a pack .keep file named "name" (which should generally be the output + * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on + * error. + */ +int odb_pack_keep(const char *name); + /* * Put in `buf` the name of the file in the local object database that * would be used to store a loose object with the specified oid. From patchwork Thu Sep 12 11:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802035 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 B56C61A42AA for ; Thu, 12 Sep 2024 11:29:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140595; cv=none; b=n2nq3h5DQoHmW8ZYMfstvtJt0Jk6WPJoF8MFU/6yqgHZ70elwLecySsAIalCXKNGd4hH+JjwjK1fiHTIawjwv0jKGNlacmbddvbDQLTfkL7fwrn8+xHkK3YIInQvsZcJEFiNyWfWzFAMfM186guK16rr67h78jsajLHXkqfVbBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140595; c=relaxed/simple; bh=fSCdOtp7TcKC5KRao/zbUmBXCPnn/1xpgY7r6C0HL7A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qDka7Xojfmor//PijLIjoXFfHFYIdAauhQhWkMFofh7KPalV6KQ0FOLVHShKiy8lZbrq9STnHb+iARQoD2UlJtwLVRQiw/xH2RJDcdRyJRov2eUuWAMdSMy0OI8+ZaIqraKPGMd9CYU7r2eMcpyt2rJXvwmCN9PoO4bghgYW4NI= 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=US8ngGV3; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Dm96CQyU; arc=none smtp.client-ip=103.168.172.157 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="US8ngGV3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Dm96CQyU" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 1FBC411405E3; Thu, 12 Sep 2024 07:29:53 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 12 Sep 2024 07:29: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=fm1; t=1726140593; x=1726226993; bh=b6zuSIOKwK 1g+ZH/hm+RxB1LuZgj1gvTKZZq+3nQarw=; b=US8ngGV3d4RLy87ozecFvbsjR7 gi2kxyQ2Q+Ulx74pclDKMT1C5HKElTeMPLky/0sBRTdIIRNRwhyI+xvbzyf07T2T pcvNSDY9mCkTJ3XEz5fGFZ/gNzY7Hz7DBzhIYCcgT9RHe85JNQmfdBR2h6DBtfYP kvFiEDPX5TGQwTYQmNQ4av5VMNA5jGVLqbipEYRFhd91RjiNDmY/n9Qeuc/cmx5A KCzdWZsL6xWVmqz43YcLzo/R9F/vQ3PfIc+lpuXec3JfWVRjnXzexaGIw2b9wwnR wppNWRCEy6WDmjWiiAauD9muuAJkCoKobUwXOdCmRWOy19H3tgVwn+r0XUQQ== 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= fm1; t=1726140593; x=1726226993; bh=b6zuSIOKwK1g+ZH/hm+RxB1LuZgj 1gvTKZZq+3nQarw=; b=Dm96CQyUkHtS3TDiVlkKG7D8JAKHelngEvXWGlAgeFJX sO7di46cONBpFqokfRfF1y2Xkh6ZL1Iw7KnlMzwq0nf6iPH05J2TLyiY7hx1Hn/A bnf1+/8R84lglNdvV/AMyqieyub0cCJSye22bvwPTB9fBL6sYWxd8ey9WWUmlvJy 9lbAFTXpD07RVs8PxyyciAj7Wfa7hc9LbKj9IpzvWVXVu2D0M0KNqTPSl2cvVohj CoOvGmLAwa6I9Tp0Z7SUb5Tfzo9cDsUnaCUGGHVGF55lTN8wpAgPSAad5sWhFHti DyReBM9L56M//xeDSsJh0Vc851mu3irSyvy7AcH1xA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvg hrnhgvlhdrohhrghdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:51 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1bae4791 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:42 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:51 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 10/21] environment: make `get_git_namespace()` self-contained Message-ID: <85c10fad522ba6d7369129d115e5cc240ef6d352.1726139990.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 logic to set up and retrieve `git_namespace` is distributed across different functions which communicate with each other via a global environment variable. This is rather pointless though, as the value is always derived from an environment variable, and this environment variable does not change after we have parsed global options. Convert the function to be fully self-contained such that it lazily populates once called. Signed-off-by: Patrick Steinhardt --- environment.c | 57 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/environment.c b/environment.c index f337efd1dd5..49844418419 100644 --- a/environment.c +++ b/environment.c @@ -122,8 +122,6 @@ int core_preload_index = 1; /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; -static char *git_namespace; - /* * Repository-local GIT_* environment variables; see environment.h for details. */ @@ -146,27 +144,6 @@ const char * const local_repo_env[] = { NULL }; -static char *expand_namespace(const char *raw_namespace) -{ - struct strbuf buf = STRBUF_INIT; - struct strbuf **components, **c; - - if (!raw_namespace || !*raw_namespace) - return xstrdup(""); - - strbuf_addstr(&buf, raw_namespace); - components = strbuf_split(&buf, '/'); - strbuf_reset(&buf); - for (c = components; *c; c++) - if (strcmp((*c)->buf, "/") != 0) - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); - strbuf_list_free(components); - if (check_refname_format(buf.buf, 0)) - die(_("bad git namespace path \"%s\""), raw_namespace); - strbuf_addch(&buf, '/'); - return strbuf_detach(&buf, NULL); -} - const char *getenv_safe(struct strvec *argv, const char *name) { const char *value = getenv(name); @@ -205,8 +182,6 @@ void setup_git_env(const char *git_dir) : "refs/replace/"); update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); - free(git_namespace); - git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); if (shallow_file) set_alternate_shallow_file(the_repository, shallow_file, 0); @@ -229,9 +204,35 @@ int have_git_dir(void) const char *get_git_namespace(void) { - if (!git_namespace) - BUG("git environment hasn't been setup"); - return git_namespace; + static const char *namespace; + + struct strbuf buf = STRBUF_INIT; + struct strbuf **components, **c; + const char *raw_namespace; + + if (namespace) + return namespace; + + raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT); + if (!raw_namespace || !*raw_namespace) { + namespace = ""; + return namespace; + } + + strbuf_addstr(&buf, raw_namespace); + components = strbuf_split(&buf, '/'); + strbuf_reset(&buf); + for (c = components; *c; c++) + if (strcmp((*c)->buf, "/") != 0) + strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); + strbuf_list_free(components); + if (check_refname_format(buf.buf, 0)) + die(_("bad git namespace path \"%s\""), raw_namespace); + strbuf_addch(&buf, '/'); + + namespace = strbuf_detach(&buf, NULL); + + return namespace; } const char *strip_namespace(const char *namespaced_ref) From patchwork Thu Sep 12 11:29: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: 13802036 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 3F42018E043 for ; Thu, 12 Sep 2024 11:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140600; cv=none; b=K12H4vj5zxfrkMA8quxaBbInNVCi7fG50EZSw1RSeqnj+8yDpRaHUeMPimJXmi36vOm9u7bAoKsa6RMNzC/0Xgosee23xWS97WnGiU2Srq/ndlOUbvWoO8cTOskRX7C7jGYRHA9vdcg4XMLCnqE/UdTEPSz4EMVO57Sccfunlys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140600; c=relaxed/simple; bh=rXrxOUiglOTReDdqdjkEfEM/zPSH64LxKP8xDk2JA8o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=I+H3EUOivZhVjLx9Ttq8w8jNhEQ7ye9SYr7NYiMaZAVvgadoin8uIsETzVC6hZjCcQ7bIadiPMicicTVL0Gpnx3oAIqq+b6/25Ne792DtoQId2a9CGJhsdPcaH78tuKE1LZ7T7iLVMe1J4UHVMgXQeQGMEdgN5TlPAb0uNixmYE= 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=WCODk+rv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IqncLUsd; arc=none smtp.client-ip=103.168.172.157 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="WCODk+rv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IqncLUsd" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 77A1E11405DF; Thu, 12 Sep 2024 07:29:58 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 12 Sep 2024 07:29:58 -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=fm1; t=1726140598; x=1726226998; bh=BrtEbDbCMD Q2twxdtHYway/CZE9075hCnWTgjb1fuEQ=; b=WCODk+rvh51EQxm7/yqJHWemUL QJM5VJL7tfBArT//KT74AWW4r+9isJTWMFBTJPWmiCRoPJaMIAqxDHjj8qHArJmT B5+HnYmF8cTaUN5pXVAxD9gGKNFH7DDGdDcMrAZ1JfAC4j8o5jp5a9iR5JKiB0pT Le9r3E/D6f2Q4PFVentyII6B1TdnxuXy4d/yCa5K0oXOmu8qCG7CJzyR3Cr8vGXM qqB1AnoJk+FVQoiNjP68e2RA+22sR6m8OYWll0fO4pP/ZwjN3O/Z+QZMVSuDDd4u rmhnW/QJXuvWoWKJOMTb7mCCLuQ/5mmYPzpHeUXfu7ZXomFUt9HxorgSGggA== 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= fm1; t=1726140598; x=1726226998; bh=BrtEbDbCMDQ2twxdtHYway/CZE90 75hCnWTgjb1fuEQ=; b=IqncLUsdQGOkAs7vbtr7WqkiflmKHXMmyyJfe/lCkw+D m1ERpWArEi2dmpxnWSsKFtR5NVm/R6VTEXHzP9dVgxADjVbrqaR9jb2wF3wTACZ6 m44aluecOoRq3lTGAeubK5RsPV/AVdpeXcTByDPFH/QqKi++jAMi7MwsvoXwDir3 FuOk26bvnVAmcWXknmPVGMtJyLBGcp0vYTZpi87i3S5HMTsbrvDUkQp9BoKxAbrW KFcdCWh3uarQc/jLiHr19/ZwSw1hzE9kNfQRtDmm1e36ZBUTe9o91fS3mQPdT0Ut gFu02ID3DpOHP1IZau4MyUqPdrNcIemzHoQxtiplAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehj lhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehkrghrthhhihhkrdduke eksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 45fc3538 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:48 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 11/21] environment: move `set_git_dir()` and related into setup layer Message-ID: <437b6f1f30d1e582e2e8a35f43d60a1fccb86740.1726139990.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 functions `set_git_dir()` and friends are used to set up repositories. As such, they are quite clearly part of the setup subsystem, but still live in "environment.c". Move them over, which also helps to get rid of dependencies on `the_repository` in the environment subsystem. Signed-off-by: Patrick Steinhardt --- environment.c | 105 ------------------------------------------------- environment.h | 2 - setup.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.h | 3 ++ 4 files changed, 109 insertions(+), 107 deletions(-) diff --git a/environment.c b/environment.c index 49844418419..64ae13ef240 100644 --- a/environment.c +++ b/environment.c @@ -22,14 +22,9 @@ #include "fmt-merge-msg.h" #include "commit.h" #include "strvec.h" -#include "object-file.h" #include "path.h" -#include "replace-object.h" -#include "tmp-objdir.h" #include "chdir-notify.h" #include "setup.h" -#include "shallow.h" -#include "trace.h" #include "write-or-die.h" int trust_executable_bit = 1; @@ -155,41 +150,6 @@ const char *getenv_safe(struct strvec *argv, const char *name) return argv->v[argv->nr - 1]; } -void setup_git_env(const char *git_dir) -{ - char *git_replace_ref_base; - const char *shallow_file; - const char *replace_ref_base; - struct set_gitdir_args args = { NULL }; - struct strvec to_free = STRVEC_INIT; - - args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); - args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); - args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT); - args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); - args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); - if (getenv(GIT_QUARANTINE_ENVIRONMENT)) { - args.disable_ref_updates = 1; - } - - repo_set_gitdir(the_repository, git_dir, &args); - strvec_clear(&to_free); - - if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) - disable_replace_refs(); - replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); - git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base - : "refs/replace/"); - update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); - - shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); - if (shallow_file) - set_alternate_shallow_file(the_repository, shallow_file, 0); - - if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) - fetch_if_missing = 0; -} - int is_bare_repository(void) { /* if core.bare is not 'false', let's see if there is a work tree */ @@ -243,71 +203,6 @@ const char *strip_namespace(const char *namespaced_ref) return NULL; } -static int git_work_tree_initialized; - -/* - * Note. This works only before you used a work tree. This was added - * primarily to support git-clone to work in a new repository it just - * created, and is not meant to flip between different work trees. - */ -void set_git_work_tree(const char *new_work_tree) -{ - if (git_work_tree_initialized) { - struct strbuf realpath = STRBUF_INIT; - - strbuf_realpath(&realpath, new_work_tree, 1); - new_work_tree = realpath.buf; - if (strcmp(new_work_tree, the_repository->worktree)) - die("internal error: work tree has already been set\n" - "Current worktree: %s\nNew worktree: %s", - the_repository->worktree, new_work_tree); - strbuf_release(&realpath); - return; - } - git_work_tree_initialized = 1; - repo_set_worktree(the_repository, new_work_tree); -} - -static void set_git_dir_1(const char *path) -{ - xsetenv(GIT_DIR_ENVIRONMENT, path, 1); - setup_git_env(path); -} - -static void update_relative_gitdir(const char *name UNUSED, - const char *old_cwd, - const char *new_cwd, - void *data UNUSED) -{ - char *path = reparent_relative_path(old_cwd, new_cwd, - repo_get_git_dir(the_repository)); - struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); - - trace_printf_key(&trace_setup_key, - "setup: move $GIT_DIR to '%s'", - path); - set_git_dir_1(path); - if (tmp_objdir) - tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); - free(path); -} - -void set_git_dir(const char *path, int make_realpath) -{ - struct strbuf realpath = STRBUF_INIT; - - if (make_realpath) { - strbuf_realpath(&realpath, path, 1); - path = realpath.buf; - } - - set_git_dir_1(path); - if (!is_absolute_path(path)) - chdir_notify_register(NULL, update_relative_gitdir, NULL); - - strbuf_release(&realpath); -} - const char *get_log_output_encoding(void) { return git_log_output_encoding ? git_log_output_encoding diff --git a/environment.h b/environment.h index 682d4f2e3b5..b8460396790 100644 --- a/environment.h +++ b/environment.h @@ -105,10 +105,8 @@ int have_git_dir(void); extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -void set_git_dir(const char *path, int make_realpath); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); -void set_git_work_tree(const char *tree); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" diff --git a/setup.c b/setup.c index 1bfec288ab6..19cce5afa72 100644 --- a/setup.c +++ b/setup.c @@ -7,16 +7,22 @@ #include "exec-cmd.h" #include "gettext.h" #include "hex.h" +#include "object-file.h" #include "object-name.h" #include "refs.h" +#include "replace-object.h" #include "repository.h" #include "config.h" #include "dir.h" #include "setup.h" +#include "shallow.h" #include "string-list.h" +#include "strvec.h" #include "chdir-notify.h" #include "path.h" #include "quote.h" +#include "tmp-objdir.h" +#include "trace.h" #include "trace2.h" #include "worktree.h" #include "exec-cmd.h" @@ -1613,6 +1619,106 @@ enum discovery_result discover_git_directory_reason(struct strbuf *commondir, return result; } +void setup_git_env(const char *git_dir) +{ + char *git_replace_ref_base; + const char *shallow_file; + const char *replace_ref_base; + struct set_gitdir_args args = { NULL }; + struct strvec to_free = STRVEC_INIT; + + args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); + args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); + args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT); + args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); + args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); + if (getenv(GIT_QUARANTINE_ENVIRONMENT)) { + args.disable_ref_updates = 1; + } + + repo_set_gitdir(the_repository, git_dir, &args); + strvec_clear(&to_free); + + if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) + disable_replace_refs(); + replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); + git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base + : "refs/replace/"); + update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); + + shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); + if (shallow_file) + set_alternate_shallow_file(the_repository, shallow_file, 0); + + if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) + fetch_if_missing = 0; +} + +static void set_git_dir_1(const char *path) +{ + xsetenv(GIT_DIR_ENVIRONMENT, path, 1); + setup_git_env(path); +} + +static void update_relative_gitdir(const char *name UNUSED, + const char *old_cwd, + const char *new_cwd, + void *data UNUSED) +{ + char *path = reparent_relative_path(old_cwd, new_cwd, + repo_get_git_dir(the_repository)); + struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); + + trace_printf_key(&trace_setup_key, + "setup: move $GIT_DIR to '%s'", + path); + set_git_dir_1(path); + if (tmp_objdir) + tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); + free(path); +} + +void set_git_dir(const char *path, int make_realpath) +{ + struct strbuf realpath = STRBUF_INIT; + + if (make_realpath) { + strbuf_realpath(&realpath, path, 1); + path = realpath.buf; + } + + set_git_dir_1(path); + if (!is_absolute_path(path)) + chdir_notify_register(NULL, update_relative_gitdir, NULL); + + strbuf_release(&realpath); +} + +static int git_work_tree_initialized; + +/* + * Note. This works only before you used a work tree. This was added + * primarily to support git-clone to work in a new repository it just + * created, and is not meant to flip between different work trees. + */ +void set_git_work_tree(const char *new_work_tree) +{ + if (git_work_tree_initialized) { + struct strbuf realpath = STRBUF_INIT; + + strbuf_realpath(&realpath, new_work_tree, 1); + new_work_tree = realpath.buf; + if (strcmp(new_work_tree, the_repository->worktree)) + die("internal error: work tree has already been set\n" + "Current worktree: %s\nNew worktree: %s", + the_repository->worktree, new_work_tree); + strbuf_release(&realpath); + return; + } + git_work_tree_initialized = 1; + repo_set_worktree(the_repository, new_work_tree); +} + const char *setup_git_directory_gently(int *nongit_ok) { static struct strbuf cwd = STRBUF_INIT; diff --git a/setup.h b/setup.h index fd2df7cd525..e496ab3e4de 100644 --- a/setup.h +++ b/setup.h @@ -94,6 +94,9 @@ static inline int discover_git_directory(struct strbuf *commondir, return 0; } +void set_git_dir(const char *path, int make_realpath); +void set_git_work_tree(const char *tree); + const char *setup_git_directory_gently(int *); const char *setup_git_directory(void); char *prefix_path(const char *prefix, int len, const char *path); From patchwork Thu Sep 12 11:29: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: 13802037 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 9A5491A2567 for ; Thu, 12 Sep 2024 11:30:01 +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=1726140603; cv=none; b=JNa5Id3/bDvb9u76YC6D/+k8gpWjm1LOjb5qcsceU1R4lW3JK3QXDiUStfhmClX24wt4u9pEJFRqzEFvTpUREX0FfZGsZdalWbXZ1kzi67Q2gKGZmItQHtotuu4QktHoXZ/k14TEQD512pb2pvuZgADYgkCIagiKgUH1oqvguJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140603; c=relaxed/simple; bh=x0gHHgsySr3jILwR3M6yuzvr1Gqle8iVBTnrbOETR2g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QzzbyWCr5yQEg2XHR7q78o05KYChZ1tw2ptXqce+t/nfB+DskXBQonWdFgRTaVo1w7/xkqW9oVm9TPaDT6cArhfFtTv2Ymx2PT9O3j+kjADb3i02/UvaRRPMu1lYOfdQG5/9IgsxYJ5+r66Ujn5p8DckaIC8BTTwtXQOfODTkdU= 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=R07+ed1s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=p/ShZvrh; 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="R07+ed1s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="p/ShZvrh" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id D7492138061F; Thu, 12 Sep 2024 07:30:00 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 12 Sep 2024 07:30: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=fm1; t=1726140600; x=1726227000; bh=nulMwl1dF7 OpHLp3ERJdcKDaMzu4b1PhPa0JGt7XDvY=; b=R07+ed1sUMGVeg7rdi58bw1T9n DbM/uieZR6xKWTEm4oCpS4hDFyi31LLsckHJhM17PzwEzrGgVvVh/OKNWRSI6sNe 11FMYNK6xgH/iTDlhViOacVMv/1AmA3/ikUbvHHrAuNwda9DQ2G+p+DsZ/PKMMW4 o5EKuLPPeXLKMpt9sLUdufkmGsWm83zEu4lPsbAkEByoHnjYXU5kRbWfIxhtRxGG unrbzc4BRHQysPx1xJASJh/CsfP9pdSzaSI0HaUvrTUlerB1hqXBXt74zcl+UyGS 8T07jRu0fuDeFJzLQh1YtO5jGTR5YPTkFabSk5DIr+cDb6/BQ897cR/pktMg== 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= fm1; t=1726140600; x=1726227000; bh=nulMwl1dF7OpHLp3ERJdcKDaMzu4 b1PhPa0JGt7XDvY=; b=p/ShZvrh19Da6U2MtGVHCSwjglk3E06AEwp/XRYpaKtj aaujHvqC7stYlRk+LLu+RYeznTvDhXTNjNsFjNbY1cSXwf7l1z6RJ8aiZevJNV/s DJbVBqDgoxc4qRPILidakI+V3ZUQQPyfX/F5CdO+DDnsSDjRhsQ2/sBs3TWBXpXY O+ItS4kk9O/zudBrKTwQdRtjeXqqZPxC9IINEItp5SDJtT3Dhf4GTJu1Xh6pkZSU Zfo5hO9nSC6lniHOGUQtFraRk0bOA4MNS9gpE+Hcr6VQy/D4crcZTaKGx18ygM84 jw59hzhonpzZk658q28gtSxbRx1C19nzQYNIVCsXIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:29:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7398c30f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:50 +0000 (UTC) Date: Thu, 12 Sep 2024 13:29:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 12/21] environment: reorder header to split out `the_repository`-free section Message-ID: <8de5b246dadd7de97ffebb22f6f018aeb7a74917.1726139990.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: Reorder the "environment.h" header such that declarations which are free from `the_repository` come before those which aren't. The new structure is now: - Defines for environment variable names. - Things which do not rely on a repository. - Things which do, including those that implicitly rely on a parsed repository. This includes for example variables which get populated when reading repository config. This will allow us to guard the last category of declarations with `USE_THE_REPOSITORY_VARIABLE`. Signed-off-by: Patrick Steinhardt --- environment.h | 81 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/environment.h b/environment.h index b8460396790..f1a7c645db5 100644 --- a/environment.h +++ b/environment.h @@ -1,22 +1,6 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H -struct strvec; - -/* - * The character that begins a commented line in user-editable file - * that is subject to stripspace. - */ -extern const char *comment_line_str; -extern char *comment_line_str_to_free; -extern int auto_comment_line_char; - -/* - * Wrapper of getenv() that returns a strdup value. This value is kept - * in argv to be freed later. - */ -const char *getenv_safe(struct strvec *argv, const char *name); - /* Double-check local_repo_env below if you add to this list. */ #define GIT_DIR_ENVIRONMENT "GIT_DIR" #define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" @@ -86,6 +70,8 @@ const char *getenv_safe(struct strvec *argv, const char *name); */ #define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" +#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" + /* * Repository-local GIT_* environment variables; these will be cleared * when git spawns a sub-process that runs inside another repository. @@ -94,6 +80,28 @@ const char *getenv_safe(struct strvec *argv, const char *name); */ extern const char * const local_repo_env[]; +struct strvec; + +/* + * Wrapper of getenv() that returns a strdup value. This value is kept + * in argv to be freed later. + */ +const char *getenv_safe(struct strvec *argv, const char *name); + +/* + * Should we print an ellipsis after an abbreviated SHA-1 value + * when doing diff-raw output or indicating a detached HEAD? + */ +int print_sha1_ellipsis(void); + +/* + * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). + */ +int use_optional_locks(void); + +const char *get_git_namespace(void); +const char *strip_namespace(const char *namespaced_ref); + void setup_git_env(const char *git_dir); /* @@ -102,13 +110,19 @@ void setup_git_env(const char *git_dir); */ int have_git_dir(void); +/* + * Accessors for the core.sharedrepository config which lazy-load the value + * from the config (if not already set). The "reset" function can be + * used to unset "set" or cached value, meaning that the value will be loaded + * fresh from the config file on the next call to get_shared_repository(). + */ +void set_shared_repository(int value); +int get_shared_repository(void); +void reset_shared_repository(void); + extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -const char *get_git_namespace(void); -const char *strip_namespace(const char *namespaced_ref); - -#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" /* Environment bits from configuration mechanism */ extern int trust_executable_bit; @@ -134,16 +148,6 @@ extern unsigned long big_file_threshold; extern unsigned long pack_size_limit_cfg; extern int max_allowed_tree_depth; -/* - * Accessors for the core.sharedrepository config which lazy-load the value - * from the config (if not already set). The "reset" function can be - * used to unset "set" or cached value, meaning that the value will be loaded - * fresh from the config file on the next call to get_shared_repository(). - */ -void set_shared_repository(int value); -int get_shared_repository(void); -void reset_shared_repository(void); - extern int core_preload_index; extern int precomposed_unicode; extern int protect_hfs; @@ -153,11 +157,6 @@ extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; -/* - * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). - */ -int use_optional_locks(void); - enum log_refs_config { LOG_REFS_UNSET = -1, LOG_REFS_NONE = 0, @@ -172,6 +171,7 @@ enum rebase_setup_type { AUTOREBASE_REMOTE, AUTOREBASE_ALWAYS }; +extern enum rebase_setup_type autorebase; enum push_default_type { PUSH_DEFAULT_NOTHING = 0, @@ -181,15 +181,12 @@ enum push_default_type { PUSH_DEFAULT_CURRENT, PUSH_DEFAULT_UNSPECIFIED }; - -extern enum rebase_setup_type autorebase; extern enum push_default_type push_default; enum object_creation_mode { OBJECT_CREATION_USES_HARDLINKS = 0, OBJECT_CREATION_USES_RENAMES = 1 }; - extern enum object_creation_mode object_creation_mode; extern char *notes_ref_name; @@ -209,9 +206,11 @@ extern char *askpass_program; extern char *excludes_file; /* - * Should we print an ellipsis after an abbreviated SHA-1 value - * when doing diff-raw output or indicating a detached HEAD? + * The character that begins a commented line in user-editable file + * that is subject to stripspace. */ -int print_sha1_ellipsis(void); +extern const char *comment_line_str; +extern char *comment_line_str_to_free; +extern int auto_comment_line_char; #endif From patchwork Thu Sep 12 11:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802038 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 7A8E71A262F for ; Thu, 12 Sep 2024 11:30:04 +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=1726140606; cv=none; b=jvNbxDP2I3P/69GvsX8ahS3grFV5PZnaVMCkWInoWtXv5lyst9g9E3feXvHUUcPm1BiEhH8tRC8pV29mdQ7K1040q9rdk4lxEIbPRYSZr774IAtD8WcRXK+uLR9VflJ4JYMl+3GkcwNP3lbJQB/ob89NhJzq157feUkATvzRot8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140606; c=relaxed/simple; bh=GDaMR5cTuNaIXY/n5x6zZmE9MBi/Q7lElB8OrliGKtw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Mn2y9aBVTZS2xSccUj90Y8+9y33cz1tYodXxanJO1copw+tvZJD5qyhokaFZZ8tOEq27LojAgCcOO7XKWasLDonZD8JrIKAqDrCsAprnvCmeGZZexULPI3PD/TcrqOn1q2VSU221MCf0fYxYRdZktMgNTrnw7XgMm3Vv8YAq1L0= 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=Ihq4Jwjd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k7Tg3bVW; 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="Ihq4Jwjd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k7Tg3bVW" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 92410138064B; Thu, 12 Sep 2024 07:30:03 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 12 Sep 2024 07:30:03 -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=fm1; t=1726140603; x=1726227003; bh=Ky79fJEFQL 90ugsU8+ZrXxI9Vec86hL6EpLNzds3rTM=; b=Ihq4JwjdyTJLWGQbzKgGjzDAJ6 PTUqIeMLpUG6fDrgI9+7xtBNpRi1tDO5fS9FypTpf91FsZY98cx53PtclwYCgm41 3zQl5Ydvo5Cy14aeIlYHJqOyXu8W6H7K1NKQ0s7HnNa3HotE09Dxqzu/gpsDRSCu CRJu6hPTzq8mvN298BB8OVqAC92DxDPFBWzcNHjR39QDHU+cCRAcoGAf2gEpXzGq M+8iH/9Ik8ItGTso36JLUIr2Kg6CX79MtpkIk/gi6RMOUJm6KXf5I+Ik2LJbCTim xJUcO0sa9o0PTni/hAPzT2oi39FEDwz6wmTXSZqZ+RpOzcnvIYG2xgy6mUDA== 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= fm1; t=1726140603; x=1726227003; bh=Ky79fJEFQL90ugsU8+ZrXxI9Vec8 6hL6EpLNzds3rTM=; b=k7Tg3bVWv+N27s0ktV9pGF9JkdlvrKh5Z61AbMtI+5Dz ZoALmLyXjJXjZSx/YjWwizO4YxV68iKbaW+H1rS9gOZ5Q8tZAVVyszMmIZLw+RFM vsMBsONQuBg8OaMb+sr/dH6yz0LpjHIxRyOswXW1oBrEWKvmz4fvZPWduOmmh3lf PyoveR0xlEm5v/QD+KZPQgmUgmImktQ6IjYt88G4GCRfRdpT0MT0BA6cmXFRxfFA vrYOQ37629d4uu+6aoPk7kovDYZfrMeTrYg52Lp1iuWjzKut4+4xsQ1NVABzy6Hz 18DA0MWORNTLsp6fXsQuFb8V1uWEuFdRQhYEgw2eEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesgh hoohhglhgvrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhr gh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:02 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d66ce3e3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:53 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:01 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 13/21] environment: guard state depending on a repository Message-ID: <417cca950bff25c5947663532d5ed468079e6c72.1726139990.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: In "environment.h" we have quite a lot of functions and variables that either explicitly or implicitly depend on `the_repository`. The implicit set of stateful declarations includes for example variables which get populated when parsing a repository's Git configuration. This set of variables is broken by design, as their state often depends on the last repository config that has been parsed. So they may or may not represent the state of `the_repository`. Fixing that is quite a big undertaking, and later patches in this series will demonstrate a solution for a first small set of those variables. So for now, let's guard these with `USE_THE_REPOSITORY_VARIABLE` so that callers are aware of the implicit dependency. Signed-off-by: Patrick Steinhardt --- compat/mingw.c | 2 ++ compat/win32/path-utils.c | 2 ++ config.c | 2 ++ environment.h | 25 ++++++++++++++++++++++++- name-hash.c | 3 +++ path.c | 2 ++ preload-index.c | 3 +++ prompt.c | 2 ++ refs/files-backend.c | 2 ++ sparse-index.c | 2 ++ statinfo.c | 2 ++ t/helper/test-path-utils.c | 2 ++ tree-diff.c | 3 +++ userdiff.c | 2 ++ 14 files changed, 53 insertions(+), 1 deletion(-) diff --git a/compat/mingw.c b/compat/mingw.c index 29d3f09768c..5c2080c04c1 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../git-compat-util.h" #include "win32.h" #include diff --git a/compat/win32/path-utils.c b/compat/win32/path-utils.c index b658ca3f811..966ef779b9c 100644 --- a/compat/win32/path-utils.c +++ b/compat/win32/path-utils.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../../git-compat-util.h" #include "../../environment.h" diff --git a/config.c b/config.c index 043e1c8a078..f3066c37477 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,8 @@ * */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "advice.h" diff --git a/environment.h b/environment.h index f1a7c645db5..934859e1c59 100644 --- a/environment.h +++ b/environment.h @@ -102,6 +102,28 @@ int use_optional_locks(void); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); +/* + * TODO: All the below state either explicitly or implicitly relies on + * `the_repository`. We should eventually get rid of these and make the + * dependency on a repository explicit: + * + * - `setup_git_env()` ideally shouldn't exist as it modifies global state, + * namely the environment. The current process shouldn't ever access that + * state via envvars though, but should instead consult a `struct + * repository`. When spawning new processes, we would ideally also pass a + * `struct repository` and then set up the environment variables for the + * child process, only. + * + * - `have_git_dir()` should not have to exist at all. Instead, we should + * decide on whether or not we have a `struct repository`. + * + * - All the global config variables should become tied to a repository. Like + * this, we'd correctly honor repository-local configuration and be able to + * distinguish configuration values from different repositories. + * + * Please do not add new global config variables here. + */ +# ifdef USE_THE_REPOSITORY_VARIABLE void setup_git_env(const char *git_dir); /* @@ -213,4 +235,5 @@ extern const char *comment_line_str; extern char *comment_line_str_to_free; extern int auto_comment_line_char; -#endif +# endif /* USE_THE_REPOSITORY_VARIABLE */ +#endif /* ENVIRONMENT_H */ diff --git a/name-hash.c b/name-hash.c index 3a58ce03d9c..95528e3bcd2 100644 --- a/name-hash.c +++ b/name-hash.c @@ -5,6 +5,9 @@ * * Copyright (C) 2008 Linus Torvalds */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" diff --git a/path.c b/path.c index a3bf25b7def..93491bab141 100644 --- a/path.c +++ b/path.c @@ -2,6 +2,8 @@ * Utilities for paths and pathnames */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "environment.h" diff --git a/preload-index.c b/preload-index.c index 63fd35d64b1..7926eb09a69 100644 --- a/preload-index.c +++ b/preload-index.c @@ -1,6 +1,9 @@ /* * Copyright (C) 2008 Linus Torvalds */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "pathspec.h" #include "dir.h" diff --git a/prompt.c b/prompt.c index 8935fe4dfb9..f21c5bf1c7e 100644 --- a/prompt.c +++ b/prompt.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "parse.h" #include "environment.h" diff --git a/refs/files-backend.c b/refs/files-backend.c index 1cff65f6ae5..1bbb550f3af 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../git-compat-util.h" #include "../copy.h" #include "../environment.h" diff --git a/sparse-index.c b/sparse-index.c index 9958656ded1..542ca5f411c 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" diff --git a/statinfo.c b/statinfo.c index 3c6bc049c15..30a164b0e68 100644 --- a/statinfo.c +++ b/statinfo.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "statinfo.h" diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index bf0e23ed505..f57c8d706aa 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "test-tool.h" #include "abspath.h" #include "environment.h" diff --git a/tree-diff.c b/tree-diff.c index 9252481df36..5eab8af631b 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -1,6 +1,9 @@ /* * Helper functions for tree diff generation */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "diff.h" #include "diffcore.h" diff --git a/userdiff.c b/userdiff.c index 989629149f6..d43d8360d17 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "userdiff.h" From patchwork Thu Sep 12 11:30:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802039 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 C01E81A42D3 for ; Thu, 12 Sep 2024 11:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140609; cv=none; b=uOBSI4u/SyatDfdFCXGNdhU18aqO2Z36fmtgzZXMjOrr9O36K+qGZ2GnscspGQKgT2fSsnCxeojySgJYXSzL4OB1UsGkNF37oiHVvEByXKbn0IS7CiNhi4JJi8ikgFDCcF8YGbOPG2SKpmTz23rhSfF7KnjC5EqE+i+kCnne9cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140609; c=relaxed/simple; bh=LO+zotbZUd05gVv8/HiZ4GvIhpRNdm/bs7lYGXz3bl4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PQMPz3gm1ULZXkQbvbS5DyqQkJ2fKm7ed2lbrdrv0wqhOijF+/KaNdN37baLecgQLwZ7SZFtm8IuWWc6qLv5XOdqnCiH5E+etC7QbxSTZyiNaCipva56oRayUuNOndifLyJJQl9uD8+8eMo5lqPjSpXEVhVhKfGmO+ZlhWMM0TY= 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=kvS6FOPR; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=psticSmU; arc=none smtp.client-ip=103.168.172.157 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="kvS6FOPR"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="psticSmU" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0F45E11405B2; Thu, 12 Sep 2024 07:30:06 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 12 Sep 2024 07:30: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=fm1; t=1726140606; x=1726227006; bh=WNhDvg3Xn2 L5Gxaf0O2TfCsRu8l24hNy7LNPtqbnRpU=; b=kvS6FOPRTnjKj6dmMGpT8pUQ+E gz9eLszRZokJO8qU0YBpixDvxjSNsFVtE3PLLXNEjUWRG5HvQdRsASZQemtsLh8I 6zpRfqstkEtR9IBGT2VyHGYtxAERTV4wb14hnQIcaqEiMsv9QpkbQo8DCmBlv9AN xzKRupgWXwR68XBI4O01C7bqAvR6YSkYUoogQXj1PWaa1v8uo6UgAoNSOH+KkKK8 ZvNEnBmSoLVE/Natl8yeESxIMdhWh3/uWyf8bYLJ4nXWKHKzlQ2Ok7rUJDb3VTWK iKJWRyH1Wl5L1Rl78BNFL7UqzMQAU0jCFSbk8TFC4O1F715gaXQCD6XrKe/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= fm1; t=1726140606; x=1726227006; bh=WNhDvg3Xn2L5Gxaf0O2TfCsRu8l2 4hNy7LNPtqbnRpU=; b=psticSmUUWo2bi+GzYIfgnYoaFqIBC9DKQ+gwfWLIK+N Rju2p/8Ovqip/6LU2Ap2FjknF4oeMeSWrOfde13HCLt+ohokfhBHe2sUQWI133o0 wbPVqGgAK1Q0n+dPHnMbGWhC5+YpQpc1Y+ocvR5IZFQ7kh18T8ccWj0yQ1TjozbF bsUGyDHCeL+Rsk6lxqWRCf760QTIqmRoPisWrQf7HjRcNdB5SaLKcVqbo/wGLhsb eJZOhKfNjEebsmoqty3S1cd1thveqrG6Y01/qLi0uHk8mXn32HQE2lcp8o05zMEM C/bWXI4nONsTnSQsBNVBovEoeFX5hv+pp4LQ7TwMaA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehkrghr thhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b328ee6f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:56 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 14/21] repo-settings: split out declarations into a standalone header 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 have "repo-settings.c", we do not have a corresponding "repo-settings.h" file. Instead, this functionality is part of the "repository.h" header, making it hard to discover. Split the declarations out of "repository.h" and create a standalone header file with them. Signed-off-by: Patrick Steinhardt --- repo-settings.c | 1 + repo-settings.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ repository.h | 51 +------------------------------------------- 3 files changed, 58 insertions(+), 50 deletions(-) create mode 100644 repo-settings.h diff --git a/repo-settings.c b/repo-settings.c index 2b4e68731be..6165546e80a 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "config.h" +#include "repo-settings.h" #include "repository.h" #include "midx.h" diff --git a/repo-settings.h b/repo-settings.h new file mode 100644 index 00000000000..ff20a965373 --- /dev/null +++ b/repo-settings.h @@ -0,0 +1,56 @@ +#ifndef REPO_SETTINGS_H +#define REPO_SETTINGS_H + +struct fsmonitor_settings; +struct repository; + +enum untracked_cache_setting { + UNTRACKED_CACHE_KEEP, + UNTRACKED_CACHE_REMOVE, + UNTRACKED_CACHE_WRITE, +}; + +enum fetch_negotiation_setting { + FETCH_NEGOTIATION_CONSECUTIVE, + FETCH_NEGOTIATION_SKIPPING, + FETCH_NEGOTIATION_NOOP, +}; + +struct repo_settings { + int initialized; + + int core_commit_graph; + int commit_graph_generation_version; + int commit_graph_changed_paths_version; + int gc_write_commit_graph; + int fetch_write_commit_graph; + int command_requires_full_index; + int sparse_index; + int pack_read_reverse_index; + int pack_use_bitmap_boundary_traversal; + int pack_use_multi_pack_reuse; + + /* + * Does this repository have core.useReplaceRefs=true (on by + * default)? This provides a repository-scoped version of this + * config, though it could be disabled process-wide via some Git + * builtins or the --no-replace-objects option. See + * replace_refs_enabled() for more details. + */ + int read_replace_refs; + + struct fsmonitor_settings *fsmonitor; /* lazily loaded */ + + int index_version; + int index_skip_hash; + enum untracked_cache_setting core_untracked_cache; + + int pack_use_sparse; + enum fetch_negotiation_setting fetch_negotiation_algorithm; + + int core_multi_pack_index; +}; + +void prepare_repo_settings(struct repository *r); + +#endif /* REPO_SETTINGS_H */ diff --git a/repository.h b/repository.h index c603e969ae7..24a66a496a6 100644 --- a/repository.h +++ b/repository.h @@ -2,9 +2,9 @@ #define REPOSITORY_H #include "strmap.h" +#include "repo-settings.h" struct config_set; -struct fsmonitor_settings; struct git_hash_algo; struct index_state; struct lock_file; @@ -14,59 +14,12 @@ struct submodule_cache; struct promisor_remote_config; struct remote_state; -enum untracked_cache_setting { - UNTRACKED_CACHE_KEEP, - UNTRACKED_CACHE_REMOVE, - UNTRACKED_CACHE_WRITE, -}; - -enum fetch_negotiation_setting { - FETCH_NEGOTIATION_CONSECUTIVE, - FETCH_NEGOTIATION_SKIPPING, - FETCH_NEGOTIATION_NOOP, -}; - enum ref_storage_format { REF_STORAGE_FORMAT_UNKNOWN, REF_STORAGE_FORMAT_FILES, REF_STORAGE_FORMAT_REFTABLE, }; -struct repo_settings { - int initialized; - - int core_commit_graph; - int commit_graph_generation_version; - int commit_graph_changed_paths_version; - int gc_write_commit_graph; - int fetch_write_commit_graph; - int command_requires_full_index; - int sparse_index; - int pack_read_reverse_index; - int pack_use_bitmap_boundary_traversal; - int pack_use_multi_pack_reuse; - - /* - * Does this repository have core.useReplaceRefs=true (on by - * default)? This provides a repository-scoped version of this - * config, though it could be disabled process-wide via some Git - * builtins or the --no-replace-objects option. See - * replace_refs_enabled() for more details. - */ - int read_replace_refs; - - struct fsmonitor_settings *fsmonitor; /* lazily loaded */ - - int index_version; - int index_skip_hash; - enum untracked_cache_setting core_untracked_cache; - - int pack_use_sparse; - enum fetch_negotiation_setting fetch_negotiation_algorithm; - - int core_multi_pack_index; -}; - struct repo_path_cache { char *squash_msg; char *merge_msg; @@ -273,8 +226,6 @@ int repo_read_index_unmerged(struct repository *); */ void repo_update_index_if_able(struct repository *, struct lock_file *); -void prepare_repo_settings(struct repository *r); - /* * Return 1 if upgrade repository format to target_version succeeded, * 0 if no upgrade is necessary, and -1 when upgrade is not possible. From patchwork Thu Sep 12 11:30: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: 13802040 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 1FF911A4B83 for ; Thu, 12 Sep 2024 11:30:10 +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=1726140611; cv=none; b=C7eWb7xX+hgriDnHkBXsgBTijKHhk/tGsN45gxpUDMLtnelOjMSpLb2I3xwuQyZMPsiZl2eD4FU+9qBMHneIvjBeOmuItLO1a/ugnxkCsnOFdeBK94JFHWtwlbS3bJCtLvCnf2UhGTprUynDBuzYtMZhhd9hfB0V7Cuo146gFqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140611; c=relaxed/simple; bh=xTJp0r2uyp7kQmtAtR+uPlL9gzrRdRCdM7TW5oVBjkY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=npY+ABy9TrZTzdk8uH/TvpAJcrmCObOP8jRd3RIHqrhUaBikvfgHwxZ64e0zsNVzRXc2vWkrf42KQJGHEC1z5u2Ivy7bbez2nXu98UCBjcEX5eIW/4GccBEf5a3TeouO0H9Xq8M49d7A74EhoqwHWljuy1J7H+PLX+SZ76yl+MY= 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=IAnJUK/s; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=H1jqtInL; 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="IAnJUK/s"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="H1jqtInL" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 7CEE61380651; Thu, 12 Sep 2024 07:30:09 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Thu, 12 Sep 2024 07:30:09 -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=fm1; t=1726140609; x=1726227009; bh=ZSnv6vhaZX 8OQCDnGZ5JhPacEt+WfvRjvxW3Mx61PXs=; b=IAnJUK/sXf3nRN/q9SJbZSaD9w oOd9gXY20gX0KuW+KWgDNcZUU3xQ+/bV1cQw7KH2rcM0GOVEcyYGNyDS2isappMl OnsJyxbBx9wjrfOJHCwznGQXqFxu9syEgtJLeIxFSOEXo3dyNKPRvFhXePOc2FN4 XHdOAP78AHcEjbGlqqnK/hsSXjqR/QiAs7W5kltlyzXy9hK7AZ7vqDh8cMrxXc9P KuPcjW0ZP+XPIBEkvIWXJoQArGCf39ewZLFj1F1kDN9h3HKOV2Kc9dwdc+Url6Or UhdfEQE1D+6N1KSA9dHO4K62XSCu1HJ3naNt03mOWcwJwh0lImezp8orC3sQ== 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= fm1; t=1726140609; x=1726227009; bh=ZSnv6vhaZX8OQCDnGZ5JhPacEt+W fvRjvxW3Mx61PXs=; b=H1jqtInLPjLlkFT1uVVxZmdRV3nay0fLP8IETCosK9gV 9njCp2qXR1UqmGoxKF6MYSj6QZayGxFa45n119REIHccLp+6BUqEUcuYnYrL4lOj EEAgESrHVZ9vtDCgzX4tftbslCOF0pce5oQ0QBhVj5mywPFl9eU3XOtZfbJGmCo1 rGYpDccTZNF6BS3ClTqKvewwoMoYaGgHxixJHIxqbrO3PDI/lemVTyIdg0pMkTYT wJ8kcBb0wz8oDxBRz3V9DeuvSIlyUKPcYHfxXkGODiQo2Khzf9bb0LV3PFPoFnAI QU4FY1SEW1FSzTOrCJGRHOC+cbeZDdGjGwo4I1A02Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhv ihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3caa263e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:29:59 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 15/21] repo-settings: track defaults close to `struct repo_settings` Message-ID: <7a74c8d8a8d640c2f0784984da93813c34fe3982.1726139990.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 default values for `struct repo_settings` are set up in `prepare_repo_settings()`. This is somewhat different from how we typically do this, namely by providing an `INIT` macro that sets up the default values for us. Refactor the code to do the same. Signed-off-by: Patrick Steinhardt --- repo-settings.c | 9 ++++----- repo-settings.h | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/repo-settings.c b/repo-settings.c index 6165546e80a..3a76ba276c9 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -20,6 +20,7 @@ static void repo_cfg_int(struct repository *r, const char *key, int *dest, void prepare_repo_settings(struct repository *r) { + const struct repo_settings defaults = REPO_SETTINGS_INIT; int experimental; int value; const char *strval; @@ -29,13 +30,11 @@ void prepare_repo_settings(struct repository *r) if (!r->gitdir) BUG("Cannot add settings for uninitialized repository"); - if (r->settings.initialized++) + if (r->settings.initialized) return; - /* Defaults */ - r->settings.index_version = -1; - r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; - r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE; + memcpy(&r->settings, &defaults, sizeof(defaults)); + r->settings.initialized++; /* Booleans config or default, cascades to other settings */ repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); diff --git a/repo-settings.h b/repo-settings.h index ff20a965373..28f95695b3a 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -50,6 +50,11 @@ struct repo_settings { int core_multi_pack_index; }; +#define REPO_SETTINGS_INIT { \ + .index_version = -1, \ + .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ + .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ +} void prepare_repo_settings(struct repository *r); From patchwork Thu Sep 12 11:30:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802041 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 956121A263D for ; Thu, 12 Sep 2024 11:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140614; cv=none; b=gC1sRo7xy3sgesaPxdtGq9mDPSduXolb74ioZVZW2CUerjCNKx4vJSIcsGoKlGfKUHWNFIvt3WKiczWKARctN1A6T5l9n1F6pca22wQ2Svji7eVziFTqYo0Q2XfYZE34Da4DG2BwfJ20ICmcPxTK0UJl0Hy8WuHRXq4JVXRv7NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140614; c=relaxed/simple; bh=88SbeCqApX45rQ3RZAh/I5IrE3IvTJaLrEYIUacKOqc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qq7uhU++OsVhYRZhnqwz5qOgEhqd/GSyO9xU4FR9ciCQTJrwc7xMIad/zIj93UF8g2DlDjrKHR4IjixQneKQICX4lj+HUY1faFP8AG0to2rsaZv5Gfswv6OMd5UswHUSmeig1cs2iPaw1NW3CxbfaMhzYhtSY+jaOwRyvNIwGKY= 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=jc1a86vF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=oH2IMKCo; arc=none smtp.client-ip=103.168.172.157 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="jc1a86vF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="oH2IMKCo" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id F1DFE11405E4; Thu, 12 Sep 2024 07:30:11 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 12 Sep 2024 07:30:11 -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=fm1; t=1726140611; x=1726227011; bh=MTGTmJQn5Q X6DO1eRUTtpUG/N4CjXwh+4KeeFekBdhE=; b=jc1a86vF/6p27HF78citG5g9uq Vkt5YpjCEsAyN2MobOOZplqmwUq+1Lex7LLS/ucrVRM/2Snt+wZZgg6/9UNqUJbA +UVLh6BqEvGD39rEZZyNyd9aIJE08dZ1Bya6VQqA+FGSTd0zZORlLw/rN9tDStUD zMKmYgQINU2NG3hMIqIz4x9svpIoRLYV2rR3+yMb7CzQa6VP7aBhzG1oM5a1FpIp mo3vVFeM/IunDqPBaSNa1KO3o+b+45LT+soP4dxYdTGWRa3F7w+AfHTlUVBYxxSs krJoZAaEkMC+ekCa3xhzeaxAUOnWZHy+AfNWrDtHglAALtdRat7ZS2Pzcmkw== 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= fm1; t=1726140611; x=1726227011; bh=MTGTmJQn5QX6DO1eRUTtpUG/N4Cj Xwh+4KeeFekBdhE=; b=oH2IMKCojlEANfobqyYwcvMP/ojdacJCyZcnalzUQk2w mXZbplK0q7qVFdM2a65WYtj2OqB9/YdASuXA0XBkzR2hqsvpvF4X8Md1XMUOYhua egtS5nsYJa68eRn7C7d6XgmVkCrp/9viOjQejJJg6Ejt84X/dRcyqdZTEUQR/Say RUD69DL7ueGl+7R01b1dDmtuULR9ZD0N3seDOcGLpp9NF0QAtqy0ac/nkM7FxuVa s3PVaR1uofO7nTSNO2RzeVt7Ds35DFhv2bdfIFzvTe4z+3ayrL46/UyFl+XgcqHu 6nEpeLLq390g6Mn9YVZG0aXvOpupMoNp4eizJZbkQA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthho pehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrd hkvghrnhgvlhdrohhrghdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:10 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c764d33c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:01 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 16/21] branch: stop modifying `log_all_ref_updates` variable 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: In "branch.c" we modify the global `log_all_ref_updates` variable to force creation of a reflog entry. Modifying global state like this is discouraged, as it may have all kinds of consequences in other places of our codebase. Stop modifying the variable and pass the `REF_FORCE_CREATE_REFLOG` flag instead. Setting this flag has a stronger meaning than setting the config to `LOG_REFS_NORMAL`: - `LOG_REFS_NORMAL` will ask us to only create reflog entries for preexisting reflogs or branches, remote refs, note refs and HEAD. - `REF_FORCE_CREATE_REFLOG` will unconditionally create a reflog and is thus equivalent to `LOG_REFS_ALWAYS`. But as we are in `create_branch()` and thus do not have to worry about arbitrary references, but only about branches, `LOG_REFS_NORMAL` and `LOG_REFS_ALWAYS` are indeed equivalent. Signed-off-by: Patrick Steinhardt --- branch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/branch.c b/branch.c index c887ea21514..08fa4094d2b 100644 --- a/branch.c +++ b/branch.c @@ -601,6 +601,7 @@ void create_branch(struct repository *r, int forcing = 0; struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; + int flags = 0; char *msg; if (track == BRANCH_TRACK_OVERRIDE) @@ -619,7 +620,7 @@ void create_branch(struct repository *r, goto cleanup; if (reflog) - log_all_ref_updates = LOG_REFS_NORMAL; + flags |= REF_FORCE_CREATE_REFLOG; if (forcing) msg = xstrfmt("branch: Reset to %s", start_name); @@ -630,7 +631,7 @@ void create_branch(struct repository *r, if (!transaction || ref_transaction_update(transaction, ref.buf, &oid, forcing ? NULL : null_oid(), - NULL, NULL, 0, msg, &err) || + NULL, NULL, flags, msg, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); ref_transaction_free(transaction); From patchwork Thu Sep 12 11:30:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802042 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 0F903185B5D for ; Thu, 12 Sep 2024 11:30:18 +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=1726140619; cv=none; b=Qsi/M0iXj+qdB9MMOV5wZkH6sE0+7NfPCnfKjCuDBFXpuY9o/p4z1X/fXKzTJlOyi3U4sLbb23UxF/xO5x2RgA/WojCLCaoSDve4M6TYPyebf+2ii8+f8wtXcElhc5z7j0BePA5i31Wczy1V+BCVZ+eWn8Ri+0bx4RK8BHLrH30= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140619; c=relaxed/simple; bh=NWi7Url5UdCx44xk2Ev9nujaX9i3QOFDs87Nl0Jdqmo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Sa10/FRHxhfHCxDV2KHZBAxf/Pah8sdEg3iDxyAwm39pS3Kn5Azj3z1zN3ZBNJAEDhUiwjNF5aFhh9yr3YId0ArfzHi/uq0E3e7+pr1TAbdpP6Yl4ElPstD2EOTn9n8DHXq9X6sPnKoVfu3YgUGWhhX+FbaE1/oToW4BKb0DmYs= 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=GP1zpF72; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ogxXbWO+; 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="GP1zpF72"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ogxXbWO+" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 6F65D1380626; Thu, 12 Sep 2024 07:30:17 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 12 Sep 2024 07:30: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=fm1; t=1726140617; x=1726227017; bh=s9YK7NvqFd OufgpzTSQfb8F8vwynH41O728d4FJIGzQ=; b=GP1zpF72gldZVetf6OXlw2iX8k I+a10Q9Fzx1ge5OMRB82AzgCaZ+wVjNpE5Fzok6ul8oHaoVld/qkB8C/OURZ37Ls tvD0muHPesE+7NEJ0mNwjiN+kwy3TaO4DtxzpWFmdkpEendTCcv2XwmUGQ3pb6Qv 5AYwBZZ4pEdpk2Br+WiiyVrGw9qe79sSrgzlX5+qa8LV+3Ryh06+QWUPf67G9gvY dbyP4i88z91NnSmB2tsSjdGNhfRrez2zH5i3jNvYP/Pytq/fB4BzBP/ff29266sw IGGPQg885K2KJaYpdVvMACeGyDraj/H8SZ/q4V5AsSWa1zEi4bwnNki5SQYg== 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= fm1; t=1726140617; x=1726227017; bh=s9YK7NvqFdOufgpzTSQfb8F8vwyn H41O728d4FJIGzQ=; b=ogxXbWO+twwSn9sfDHtvtjQvjok5c3uIPuWKlXznUep3 B2Zm7J0lTMbK34do4ZE+UKexzSsZ+d/yN7u26TssWyVablD5h5ALkhSaZ9dUe2gs BK16zj+eQLf3ENxjjOYVHGhY9NXJalEf0aYmJjFizNyN/J2B7qxOZ/bkFgWfy3+H ki1BlBBClj46ybtm8b7Ty/i0LpBIRse78nLXaBW7Db9+C8l6xiOPhkWjfWXkoVAK gcMPXEIA7yl7RkZyJjfYTiMIQQd/Xmjr/jtkJEygQLeC91QuUdYKTrgLgIhC9tHy hjI4J/pVvNro4Zjzdy5cuYZYJk+8Ja6XiAiIM5IIMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtoheptggr lhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrse hgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhr gh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:16 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2736f7b8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:07 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:13 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 17/21] refs: stop modifying global `log_all_ref_updates` variable Message-ID: <128fefd33a86e9b3d80203e891dc383643d6dec0.1726139990.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: In refs-related code we modify the global `log_all_ref_updates` variable, which is done because `should_autocreate_reflog()` does not accept passing an `enum log_refs_config` but instead accesses the global variable. Adapt its interface such that the value is provided by the caller, which allows us to compute the proper value locally without having to modify global state. This change requires us to move the enum to "repo-settings.h", or otherwise we get compilation errors due to include cycles. We're about to fully move this setting into the repo-settings subsystem anyway, so this is fine. Signed-off-by: Patrick Steinhardt --- builtin/checkout.c | 3 ++- environment.h | 8 ++------ refs.c | 5 +++-- refs.h | 4 +++- refs/files-backend.c | 23 ++++++++++++----------- refs/reftable-backend.c | 12 +++++++----- repo-settings.h | 7 +++++++ 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 4cfe6fab505..6db7f39492e 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -23,6 +23,7 @@ #include "read-cache.h" #include "refs.h" #include "remote.h" +#include "repo-settings.h" #include "resolve-undo.h" #include "revision.h" #include "setup.h" @@ -954,7 +955,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch); if (opts->new_branch_log && - !should_autocreate_reflog(refname)) { + !should_autocreate_reflog(log_all_ref_updates, refname)) { int ret; struct strbuf err = STRBUF_INIT; diff --git a/environment.h b/environment.h index 934859e1c59..0b4e5afc36d 100644 --- a/environment.h +++ b/environment.h @@ -1,6 +1,8 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H +#include "repo-settings.h" + /* Double-check local_repo_env below if you add to this list. */ #define GIT_DIR_ENVIRONMENT "GIT_DIR" #define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" @@ -179,12 +181,6 @@ extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; -enum log_refs_config { - LOG_REFS_UNSET = -1, - LOG_REFS_NONE = 0, - LOG_REFS_NORMAL, - LOG_REFS_ALWAYS -}; extern enum log_refs_config log_all_ref_updates; enum rebase_setup_type { diff --git a/refs.c b/refs.c index ceb72d4bd74..d7402bcd196 100644 --- a/refs.c +++ b/refs.c @@ -24,7 +24,7 @@ #include "submodule.h" #include "worktree.h" #include "strvec.h" -#include "repository.h" +#include "repo-settings.h" #include "setup.h" #include "sigchain.h" #include "date.h" @@ -958,7 +958,8 @@ static char *normalize_reflog_message(const char *msg) return strbuf_detach(&sb, NULL); } -int should_autocreate_reflog(const char *refname) +int should_autocreate_reflog(enum log_refs_config log_all_ref_updates, + const char *refname) { switch (log_all_ref_updates) { case LOG_REFS_ALWAYS: diff --git a/refs.h b/refs.h index f8b919a1388..f2c4ccde611 100644 --- a/refs.h +++ b/refs.h @@ -3,6 +3,7 @@ #include "commit.h" #include "repository.h" +#include "repo-settings.h" struct fsck_options; struct object_id; @@ -111,7 +112,8 @@ int refs_verify_refname_available(struct ref_store *refs, int refs_ref_exists(struct ref_store *refs, const char *refname); -int should_autocreate_reflog(const char *refname); +int should_autocreate_reflog(enum log_refs_config log_all_ref_updates, + const char *refname); int is_branch(const char *refname); diff --git a/refs/files-backend.c b/refs/files-backend.c index 1bbb550f3af..f5871abcf75 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -8,6 +8,7 @@ #include "../hex.h" #include "../fsck.h" #include "../refs.h" +#include "../repo-settings.h" #include "refs-internal.h" #include "ref-cache.h" #include "packed-backend.h" @@ -1443,6 +1444,7 @@ static int write_ref_to_lockfile(struct files_ref_store *refs, static int commit_ref_update(struct files_ref_store *refs, struct ref_lock *lock, const struct object_id *oid, const char *logmsg, + int flags, struct strbuf *err); /* @@ -1586,7 +1588,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, oidcpy(&lock->old_oid, &orig_oid); if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || - commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) { + commit_ref_update(refs, lock, &orig_oid, logmsg, 0, &err)) { error("unable to write current sha1 into %s: %s", newrefname, err.buf); strbuf_release(&err); goto rollback; @@ -1603,14 +1605,11 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, goto rollbacklog; } - flag = log_all_ref_updates; - log_all_ref_updates = LOG_REFS_NONE; if (write_ref_to_lockfile(refs, lock, &orig_oid, 0, &err) || - commit_ref_update(refs, lock, &orig_oid, NULL, &err)) { + commit_ref_update(refs, lock, &orig_oid, NULL, REF_SKIP_CREATE_REFLOG, &err)) { error("unable to write current sha1 into %s: %s", oldrefname, err.buf); strbuf_release(&err); } - log_all_ref_updates = flag; rollbacklog: if (logmoved && rename(sb_newref.buf, sb_oldref.buf)) @@ -1705,13 +1704,17 @@ static int log_ref_setup(struct files_ref_store *refs, const char *refname, int force_create, int *logfd, struct strbuf *err) { + enum log_refs_config log_refs_cfg = log_all_ref_updates; struct strbuf logfile_sb = STRBUF_INIT; char *logfile; + if (log_refs_cfg == LOG_REFS_UNSET) + log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; + files_reflog_path(refs, &logfile_sb, refname); logfile = strbuf_detach(&logfile_sb, NULL); - if (force_create || should_autocreate_reflog(refname)) { + if (force_create || should_autocreate_reflog(log_refs_cfg, refname)) { if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) { if (errno == ENOENT) strbuf_addf(err, "unable to create directory for '%s': " @@ -1800,9 +1803,6 @@ static int files_log_ref_write(struct files_ref_store *refs, if (flags & REF_SKIP_CREATE_REFLOG) return 0; - if (log_all_ref_updates == LOG_REFS_UNSET) - log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; - result = log_ref_setup(refs, refname, flags & REF_FORCE_CREATE_REFLOG, &logfd, err); @@ -1891,6 +1891,7 @@ static int write_ref_to_lockfile(struct files_ref_store *refs, static int commit_ref_update(struct files_ref_store *refs, struct ref_lock *lock, const struct object_id *oid, const char *logmsg, + int flags, struct strbuf *err) { files_assert_main_repository(refs, "commit_ref_update"); @@ -1898,7 +1899,7 @@ static int commit_ref_update(struct files_ref_store *refs, clear_loose_ref_cache(refs); if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid, oid, - logmsg, 0, err)) { + logmsg, flags, err)) { char *old_msg = strbuf_detach(err, NULL); strbuf_addf(err, "cannot update the ref '%s': %s", lock->ref_name, old_msg); @@ -1931,7 +1932,7 @@ static int commit_ref_update(struct files_ref_store *refs, struct strbuf log_err = STRBUF_INIT; if (files_log_ref_write(refs, "HEAD", &lock->old_oid, oid, - logmsg, 0, &log_err)) { + logmsg, flags, &log_err)) { error("%s", log_err.buf); strbuf_release(&log_err); } diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 1c4b19e737f..c78186423a1 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -19,6 +19,7 @@ #include "../reftable/reftable-record.h" #include "../reftable/reftable-error.h" #include "../reftable/reftable-iterator.h" +#include "../repo-settings.h" #include "../setup.h" #include "../strmap.h" #include "parse.h" @@ -158,20 +159,21 @@ static struct reftable_stack *stack_for(struct reftable_ref_store *store, static int should_write_log(struct ref_store *refs, const char *refname) { - if (log_all_ref_updates == LOG_REFS_UNSET) - log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; + enum log_refs_config log_refs_cfg = log_all_ref_updates; + if (log_refs_cfg == LOG_REFS_UNSET) + log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; - switch (log_all_ref_updates) { + switch (log_refs_cfg) { case LOG_REFS_NONE: return refs_reflog_exists(refs, refname); case LOG_REFS_ALWAYS: return 1; case LOG_REFS_NORMAL: - if (should_autocreate_reflog(refname)) + if (should_autocreate_reflog(log_refs_cfg, refname)) return 1; return refs_reflog_exists(refs, refname); default: - BUG("unhandled core.logAllRefUpdates value %d", log_all_ref_updates); + BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg); } } diff --git a/repo-settings.h b/repo-settings.h index 28f95695b3a..d03b6e57f0c 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -16,6 +16,13 @@ enum fetch_negotiation_setting { FETCH_NEGOTIATION_NOOP, }; +enum log_refs_config { + LOG_REFS_UNSET = -1, + LOG_REFS_NONE = 0, + LOG_REFS_NORMAL, + LOG_REFS_ALWAYS +}; + struct repo_settings { int initialized; From patchwork Thu Sep 12 11:30: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: 13802043 Received: from fhigh6-smtp.messagingengine.com (fhigh6-smtp.messagingengine.com [103.168.172.157]) (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 D83091A2657 for ; Thu, 12 Sep 2024 11:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140622; cv=none; b=U6dhIfptxfV7IgCQtRhuZzMb6gnsXsFRbNPnI5sgqUA0U/Ne7raq/816CIgyX1iVTUoioIbTkm8wiw+7I4R3R+BeSkjb87JsSeMbSXexAEw4Dr40i26Q6mYzX5ZhwzYe5a7xGCfmDq/eECQ4ciC+VBtpcOevsyd3tpZVN290WhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140622; c=relaxed/simple; bh=xNYGg92FMwx/yVUNLjLE+ablyFKW7ClbmFy3/3YWkiA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hSqb9e1aCqSd8aBL/0rXHIGxw+fzHxgpPCGD1Wiwd/x0r+hJXInKNavOnFug4xjtR8Ommqb/HoYJbYmYtFJQ3gs2pF/s6V8TgCl+kqDEok5BlUIK9ws9Wg7p8wbb7ZprL2qiXk19gY3Re1MMf2L/B7nFRK2GWyNPpxEttBkIf7U= 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=e0Ow+fK6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PkcGaoFi; arc=none smtp.client-ip=103.168.172.157 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="e0Ow+fK6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PkcGaoFi" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 0607D11405E1; Thu, 12 Sep 2024 07:30:20 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 12 Sep 2024 07:30:20 -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=fm1; t=1726140620; x=1726227020; bh=Jt36ZhZmng XCRn9wf1TYf3mufG7RHS6D5nlxbCreZ5I=; b=e0Ow+fK6yY1/ZUxhPT9hxGCJM6 F2r26Hg7k1hQww1kt9ETUZYbmdzcsaWjaflLa4SGF1/V104Vm4/wW0r9G1h5neaj TIANYuAVsDQezJQYn1gqgljcUTpn/Tb0pOAHpSpAZHtd7NUkGwi/hCOmoduGj+At QaPeJn4cD77+HyV9xKqBSJjMiHpON0AReW8UB6+VdD/9kBwkWx/2EInEpj23BT4I u+aU/3TOPKhnxxbPyIHgSXKTTsSuCnMcLySPqCu6ye7b1LcXm+h39zMUeZcg8qwO jPeUdS5xkHY3RDbJXxqp7msWwZ1v2dnK1PblueooYpqWU4mXRtQkBKECB7lg== 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= fm1; t=1726140620; x=1726227020; bh=Jt36ZhZmngXCRn9wf1TYf3mufG7R HS6D5nlxbCreZ5I=; b=PkcGaoFiv/w1NbgQvsdfvYfuhhnZa3jYz8kWc2A/OWGR qxB1/0mkaAMOhLs0WZQkD9TVIP5Hl3V5XYQqF2o+BVks52HmP/PYW59mI+PQLN9r 0EsoGtCNG6x39KujrclWeqG19IaXaYr8JPljbCHMCtu5+rgNjC96nczuZ4FSVC6s LYBjUO/vYaSpq+83ZM5klZX7c3s2wBg5ZqX1g/xwxLSaKcmpqwZyLkwQmQ0lLYG9 EXxDj7x/PWpmILiZgd42aI0XoMj1cnxzywRg3nUiZ3OLeTwHExfhiFZHJL0nILL5 9lSVcAVAkXsGyxrI5U/og5ALK0v/9LHKVyKOsuLrPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomh dprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhi thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjlhhtohgslhgvrhesgh hmrghilhdrtghomhdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:18 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0b8bba95 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:09 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 18/21] environment: stop storing "core.logAllRefUpdates" globally 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: The value of "core.logAllRefUpdates" is being stored in the global variable `log_all_ref_updates`. This design is somewhat aged nowadays, where it is entirely possible to access multiple repositories in the same process which all have different values for this setting. So using a single global variable to track it is plain wrong. Remove the global variable. Instead, we now provide a new function part of the repo-settings subsystem that parses the value for a specific repository. While that may require us to read the value multiple times, we work around this by reading it once when the ref backends are set up and caching the value there. Signed-off-by: Patrick Steinhardt --- builtin/checkout.c | 2 ++ config.c | 10 ---------- environment.c | 1 - environment.h | 2 -- refs/files-backend.c | 4 +++- refs/reftable-backend.c | 12 +++++++----- repo-settings.c | 16 ++++++++++++++++ repo-settings.h | 3 +++ setup.c | 2 +- 9 files changed, 32 insertions(+), 20 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 6db7f39492e..7e18b87c7a4 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -951,6 +951,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts, const char *old_desc, *reflog_msg; if (opts->new_branch) { if (opts->new_orphan_branch) { + enum log_refs_config log_all_ref_updates = + repo_settings_get_log_all_ref_updates(the_repository); char *refname; refname = mkpathdup("refs/heads/%s", opts->new_orphan_branch); diff --git a/config.c b/config.c index f3066c37477..47101c3e977 100644 --- a/config.c +++ b/config.c @@ -1452,16 +1452,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.logallrefupdates")) { - if (value && !strcasecmp(value, "always")) - log_all_ref_updates = LOG_REFS_ALWAYS; - else if (git_config_bool(var, value)) - log_all_ref_updates = LOG_REFS_NORMAL; - else - log_all_ref_updates = LOG_REFS_NONE; - return 0; - } - if (!strcmp(var, "core.warnambiguousrefs")) { warn_ambiguous_refs = git_config_bool(var, value); return 0; diff --git a/environment.c b/environment.c index 64ae13ef240..992d87e0d60 100644 --- a/environment.c +++ b/environment.c @@ -77,7 +77,6 @@ int sparse_expect_files_outside_of_patterns; int merge_log_config = -1; int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ unsigned long pack_size_limit_cfg; -enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET; int max_allowed_tree_depth = #ifdef _MSC_VER /* diff --git a/environment.h b/environment.h index 0b4e5afc36d..315fd319951 100644 --- a/environment.h +++ b/environment.h @@ -181,8 +181,6 @@ extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; -extern enum log_refs_config log_all_ref_updates; - enum rebase_setup_type { AUTOREBASE_NEVER = 0, AUTOREBASE_LOCAL, diff --git a/refs/files-backend.c b/refs/files-backend.c index f5871abcf75..a536d7d1b57 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -75,6 +75,7 @@ struct files_ref_store { unsigned int store_flags; char *gitcommondir; + enum log_refs_config log_all_ref_updates; struct ref_cache *loose; @@ -107,6 +108,7 @@ static struct ref_store *files_ref_store_init(struct repository *repo, refs->gitcommondir = strbuf_detach(&sb, NULL); refs->packed_ref_store = packed_ref_store_init(repo, refs->gitcommondir, flags); + refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo); chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); chdir_notify_reparent("files-backend $GIT_COMMONDIR", @@ -1704,7 +1706,7 @@ static int log_ref_setup(struct files_ref_store *refs, const char *refname, int force_create, int *logfd, struct strbuf *err) { - enum log_refs_config log_refs_cfg = log_all_ref_updates; + enum log_refs_config log_refs_cfg = refs->log_all_ref_updates; struct strbuf logfile_sb = STRBUF_INIT; char *logfile; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index c78186423a1..043e19439f6 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -52,6 +52,7 @@ struct reftable_ref_store { struct reftable_write_options write_options; unsigned int store_flags; + enum log_refs_config log_all_ref_updates; int err; }; @@ -157,21 +158,21 @@ static struct reftable_stack *stack_for(struct reftable_ref_store *store, } } -static int should_write_log(struct ref_store *refs, const char *refname) +static int should_write_log(struct reftable_ref_store *refs, const char *refname) { - enum log_refs_config log_refs_cfg = log_all_ref_updates; + enum log_refs_config log_refs_cfg = refs->log_all_ref_updates; if (log_refs_cfg == LOG_REFS_UNSET) log_refs_cfg = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL; switch (log_refs_cfg) { case LOG_REFS_NONE: - return refs_reflog_exists(refs, refname); + return refs_reflog_exists(&refs->base, refname); case LOG_REFS_ALWAYS: return 1; case LOG_REFS_NORMAL: if (should_autocreate_reflog(log_refs_cfg, refname)) return 1; - return refs_reflog_exists(refs, refname); + return refs_reflog_exists(&refs->base, refname); default: BUG("unhandled core.logAllRefUpdates value %d", log_refs_cfg); } @@ -278,6 +279,7 @@ static struct ref_store *reftable_be_init(struct repository *repo, base_ref_store_init(&refs->base, repo, gitdir, &refs_be_reftable); strmap_init(&refs->worktree_stacks); refs->store_flags = store_flags; + refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo); refs->write_options.hash_id = repo->hash_algo->format_id; refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask); @@ -1220,7 +1222,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data } else if (!(u->flags & REF_SKIP_CREATE_REFLOG) && (u->flags & REF_HAVE_NEW) && (u->flags & REF_FORCE_CREATE_REFLOG || - should_write_log(&arg->refs->base, u->refname))) { + should_write_log(arg->refs, u->refname))) { struct reftable_log_record *log; int create_reflog = 1; diff --git a/repo-settings.c b/repo-settings.c index 3a76ba276c9..1322fd2f972 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -124,3 +124,19 @@ void prepare_repo_settings(struct repository *r) */ r->settings.command_requires_full_index = 1; } + +enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo) +{ + const char *value; + + if (!repo_config_get_string_tmp(repo, "core.logallrefupdates", &value)) { + if (value && !strcasecmp(value, "always")) + return LOG_REFS_ALWAYS; + else if (git_config_bool("core.logallrefupdates", value)) + return LOG_REFS_NORMAL; + else + return LOG_REFS_NONE; + } + + return LOG_REFS_UNSET; +} diff --git a/repo-settings.h b/repo-settings.h index d03b6e57f0c..76adb96a669 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -65,4 +65,7 @@ struct repo_settings { void prepare_repo_settings(struct repository *r); +/* Read the value for "core.logAllRefUpdates". */ +enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo); + #endif /* REPO_SETTINGS_H */ diff --git a/setup.c b/setup.c index 19cce5afa72..74991914726 100644 --- a/setup.c +++ b/setup.c @@ -2354,7 +2354,7 @@ static int create_default_files(const char *template_path, else { git_config_set("core.bare", "false"); /* allow template config file to override the default */ - if (log_all_ref_updates == LOG_REFS_UNSET) + if (repo_settings_get_log_all_ref_updates(the_repository) == LOG_REFS_UNSET) git_config_set("core.logallrefupdates", "true"); if (needs_work_tree_config(original_git_dir, work_tree)) git_config_set("core.worktree", work_tree); From patchwork Thu Sep 12 11:30: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: 13802044 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 1EF381A2649 for ; Thu, 12 Sep 2024 11:30: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=1726140624; cv=none; b=M76eKfJMNS0FG2PrtZPd+PBFgaf2QQb2SlBfe/4rLhq6ajDYoEVcSA5pJ/jmlbaQr+bgNYObdCZI5x8JE1CkEA03c0qG/m4xN6QuA1yR14NUiZjOuLFK5ESIQMhDvioXQZxT/snloCp7ygSDOYdXV+bwMYBdP0kvXchoCottRRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140624; c=relaxed/simple; bh=dRqd6E2r3WAI7vwX+mkTqGOw55v10Va64DgdJ/BbtuQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V2zehM2YHqv2BWBs/tFv9Ou5UV5eeM2ii2cwl8UXSUkjA6iu/NeuSG5bu2yv25hP5o8xNVgvTa5bkzvGOuMmhkh1C1QpmPVbrjY14jLkVEaEydbtWDGNlKgvpsfK9xJPjlAAB/jwbnw/FMmatQxTzF3/STaBeMnnOfJxJMgHq6Y= 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=L8qZ7gLa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CJxRF/zr; 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="L8qZ7gLa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CJxRF/zr" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 7CAF11380644; Thu, 12 Sep 2024 07:30:22 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 12 Sep 2024 07:30:22 -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=fm1; t=1726140622; x=1726227022; bh=ekEaVdiMI7 Zl9sLM0K5Gtb4/6LU1pex3wqXHi45eXaI=; b=L8qZ7gLauKVqXdDe3PTJ8NOcfE 2xMkxgc2D8xp0tEebcKIYeEJmWd69ydM9fZdbeixHy8aebWmSj+9b9aNMWExKfu9 OfgmYNpRjkgdh5Z6y1Fj8lm9yu0750fDoNleOEQa/uTrVlQRVBnPz5ebpR5n/4Kq whkeQTMDMxSh3pdvkg1YiKayc0RxfNfLmdTh4nDQORF1AlyIA5i3BcEI/r/3twNS jGhLUkGjjjjVrDLHC5COJGgRh5WxW+Q9f3QgK1RpCsogG5k+emyFr+0Ips5IOeip TrJGCo5dk6OAW4N3NWdzS0S66UDXABB/kgwWWOk/Awl5qECT72A9NktPx+Mw== 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= fm1; t=1726140622; x=1726227022; bh=ekEaVdiMI7Zl9sLM0K5Gtb4/6LU1 pex3wqXHi45eXaI=; b=CJxRF/zru8QFlEVKrwupB3wlt/0CFLG73Jp69adsxmr5 ujE5ULkh+7Y6ZhsU9xjz+gGHYz+Ro55e+1Z/KEbCvj4E3L4dT1fmsubOVv6ZTo4w logwMuc0fb8XYFOXxuhgZkZjqwrz9VsrPZLkKwQQc2sXVaLehD0xbat9N5pb3Hzg 39vqJleiRvh+8LAdZE5tErmSGjnwfDLM2a4jnwfAtcFkmw5zeHRRAAXKlOt9lzVN JhcHttXd/1FAS84r4XSagjNtXu4hg/MM5MxvDs2jQUfaZj9+TVsasMx9mkuHSD8Q NjFRKXmmzaiNijsVqufgPBeJtUfDcCbi25+wyDd4WA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehk rghrthhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrh esphhosghogidrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e66893ce (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:12 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 19/21] environment: stop storing "core.preferSymlinkRefs" globally 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: Same as the preceding commit, storing the "core.preferSymlinkRefs" value globally is misdesigned as this setting may be set per repository. There is only a single user of this value anyway, namely the "files" backend. So let's just remove the global variable and read the value of this setting when initializing the backend. Signed-off-by: Patrick Steinhardt --- config.c | 5 ----- environment.c | 1 - environment.h | 1 - refs/files-backend.c | 5 ++++- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 47101c3e977..a59890180a3 100644 --- a/config.c +++ b/config.c @@ -1447,11 +1447,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.prefersymlinkrefs")) { - prefer_symlink_refs = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "core.warnambiguousrefs")) { warn_ambiguous_refs = git_config_bool(var, value); return 0; diff --git a/environment.c b/environment.c index 992d87e0d60..6805c7b01df 100644 --- a/environment.c +++ b/environment.c @@ -34,7 +34,6 @@ int has_symlinks = 1; int minimum_abbrev = 4, default_abbrev = -1; int ignore_case; int assume_unchanged; -int prefer_symlink_refs; int is_bare_repository_cfg = -1; /* unspecified */ int warn_ambiguous_refs = 1; int warn_on_object_refname_ambiguity = 1; diff --git a/environment.h b/environment.h index 315fd319951..0cab644e2d3 100644 --- a/environment.h +++ b/environment.h @@ -156,7 +156,6 @@ extern int has_symlinks; extern int minimum_abbrev, default_abbrev; extern int ignore_case; extern int assume_unchanged; -extern int prefer_symlink_refs; extern int warn_ambiguous_refs; extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; diff --git a/refs/files-backend.c b/refs/files-backend.c index a536d7d1b57..e5b0aff00dc 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,6 +1,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "../git-compat-util.h" +#include "../config.h" #include "../copy.h" #include "../environment.h" #include "../gettext.h" @@ -76,6 +77,7 @@ struct files_ref_store { char *gitcommondir; enum log_refs_config log_all_ref_updates; + int prefer_symlink_refs; struct ref_cache *loose; @@ -109,6 +111,7 @@ static struct ref_store *files_ref_store_init(struct repository *repo, refs->packed_ref_store = packed_ref_store_init(repo, refs->gitcommondir, flags); refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo); + repo_config_get_bool(repo, "core.prefersymlinkrefs", &refs->prefer_symlink_refs); chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); chdir_notify_reparent("files-backend $GIT_COMMONDIR", @@ -2942,7 +2945,7 @@ static int files_transaction_finish(struct ref_store *ref_store, * We try creating a symlink, if that succeeds we continue to the * next update. If not, we try and create a regular symref. */ - if (update->new_target && prefer_symlink_refs) + if (update->new_target && refs->prefer_symlink_refs) if (!create_ref_symlink(lock, update->new_target)) continue; From patchwork Thu Sep 12 11:30:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802045 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 B2E0D1A2649 for ; Thu, 12 Sep 2024 11:30:26 +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=1726140628; cv=none; b=Q5j+WJY0rcDvjHcae4vtLCS15USh5xZebx6xPcIsw4ui5yzGAo9gn3hk5WkSlE2/RgQ6GSfjSHPLnpWsah1qFibfksLyGxQmUwT/tq1wr0wgdp2snVeTBz+FxzfXkrnSJOnzCc7dRSWvS1pN4tX2XW1P8CmqYeEp3i/l6XEvAtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140628; c=relaxed/simple; bh=YbAXqBup/LUIpJt0GsaH9j+7L+nl9PZxVecXDgQjQEU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=f5/Cjp0lc5C5YZ1n548bEp6sAqEtyQlpOlKzaHBfrxFOr2w9in1KcZDRe0EVqwFmDQbb/scsDgzFFXApLUfM8z9VSQuNM6LW06m+tQjjsR/X38+2ZUdhHSgcvJcy2vnx7oBWqzSlPdN1ndolXvXHKEQnAqq18IWSwDKUb6QShRo= 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=dzSWi9Gi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LFDX4dzA; 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="dzSWi9Gi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LFDX4dzA" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 05E0F1380639; Thu, 12 Sep 2024 07:30:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 12 Sep 2024 07:30: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=fm1; t=1726140626; x=1726227026; bh=cU8F9Z1DOi OvSpwPsRrgbam6abXF2jjtGFLey3zV9cU=; b=dzSWi9GihFrz5F0UdWBofIzBNL /ERjbmhnZe3L9gThrUWWWQhpXpd4S74mIuJxdZn0mhdw5E3fFaT9OgCSWtAETzrv 9uqDroxCekVaa/GvKGMc7M16MwBEF4PWpmAzfmn+pd1bQqbNTh0eWBREQz/PbXlo cw18PsOybftAYnjpf7HZ8DNFvaV6KOaCVY7IQ3urCF2FXSsQsRfQ0yszMm/Q7X4g +lLYDkoakshb57NYqrGnD5tis+iV/aHKW9LYbD/aBsurfIK2CxF7e3a9HrNR59i9 1bwhyNpt112MYBM6HUCmefYq/8Xd7yRsdlQsf3AAr7aM7Bc+uoj4av9YDIlg== 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= fm1; t=1726140626; x=1726227026; bh=cU8F9Z1DOiOvSpwPsRrgbam6abXF 2jjtGFLey3zV9cU=; b=LFDX4dzAHrsXSpa4jkx5RtgNiIvacUAueoc23e0GKblz HTmYA/YEm1NG2qaOv3qNfPCI2gUdZV7X4EPMEggNMmTD58bdLGSg8RPv13u5h6bo iI0+ylsL6Ue4o7s8QFiiYylDTvRluHoztB5gQ/ltrhdu5NMy7ly0MA0fM2ektqZV dfhZL/pTQe1UHxBjWuvZg0tFNi+m80AcliOpkmqJesGspU10PWrWdTbFIiGTB8mT Huzvk+NCr7l62dxZXMHcQqrUFfcSwC/H+YzWc65e5157FKYINo8y9jHIRLIcHQud EJieHHKTIfBdmESNeSM9GcyytaNUVO1JqgzqFlfTHQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepudeffeetteekudekffevudefgfelhefgteffhfdvveff keevleevjeejfefgfeeinecuffhomhgrihhnpeifrghrnhgrmhgsihhguhhouhhsrhgvfh hsrdhinhhtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphht thhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepghhithesvhhgvg hrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegtrghlvhhinhifrghnsehgohhoghhl vgdrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 49bc5da2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:15 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 20/21] environment: stop storing "core.warnAmbiguousRefs" globally Message-ID: <3c4a9259fbbe7d0aa7edbffaffb26b13feb5f52b.1726139990.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: Same as the preceding commits, storing the "core.warnAmbiguousRefs" value globally is misdesigned as this setting may be set per repository. Move the logic into the repo-settings subsystem. The usual pattern here is that users are expected to call `prepare_repo_settings()` before they access the settings themselves. This seems somewhat fragile though, as it is easy to miss and leads to somewhat ugly code patterns at the call sites. Instead, introduce a new function that encapsulates this logic for us. This also allows us to change how exactly the lazy initialization works in the future, e.g. by only partially initializing values as requested by the caller. Signed-off-by: Patrick Steinhardt --- builtin/rev-parse.c | 4 +++- config.c | 5 ----- environment.c | 1 - environment.h | 1 - object-name.c | 5 +++-- ref-filter.c | 3 ++- refs.c | 4 ++-- repo-settings.c | 9 +++++++++ repo-settings.h | 4 ++++ 9 files changed, 23 insertions(+), 13 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index a5108266daf..34b46754426 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -19,6 +19,7 @@ #include "path.h" #include "diff.h" #include "read-cache-ll.h" +#include "repo-settings.h" #include "repository.h" #include "revision.h" #include "setup.h" @@ -899,7 +900,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) } if (opt_with_value(arg, "--abbrev-ref", &arg)) { abbrev_ref = 1; - abbrev_ref_strict = warn_ambiguous_refs; + abbrev_ref_strict = + repo_settings_get_warn_ambiguous_refs(the_repository); if (arg) { if (!strcmp(arg, "strict")) abbrev_ref_strict = 1; diff --git a/config.c b/config.c index a59890180a3..53c68f3da61 100644 --- a/config.c +++ b/config.c @@ -1447,11 +1447,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.warnambiguousrefs")) { - warn_ambiguous_refs = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "core.abbrev")) { if (!value) return config_error_nonbool(var); diff --git a/environment.c b/environment.c index 6805c7b01df..9dd000cda36 100644 --- a/environment.c +++ b/environment.c @@ -35,7 +35,6 @@ int minimum_abbrev = 4, default_abbrev = -1; int ignore_case; int assume_unchanged; int is_bare_repository_cfg = -1; /* unspecified */ -int warn_ambiguous_refs = 1; int warn_on_object_refname_ambiguity = 1; int repository_format_precious_objects; char *git_commit_encoding; diff --git a/environment.h b/environment.h index 0cab644e2d3..aa38133da9c 100644 --- a/environment.h +++ b/environment.h @@ -156,7 +156,6 @@ extern int has_symlinks; extern int minimum_abbrev, default_abbrev; extern int ignore_case; extern int assume_unchanged; -extern int warn_ambiguous_refs; extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; extern char *apply_default_ignorewhitespace; diff --git a/object-name.c b/object-name.c index 09c1bd93a31..c892fbe80aa 100644 --- a/object-name.c +++ b/object-name.c @@ -20,6 +20,7 @@ #include "pretty.h" #include "object-store-ll.h" #include "read-cache-ll.h" +#include "repo-settings.h" #include "repository.h" #include "setup.h" #include "midx.h" @@ -959,7 +960,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len, int fatal = !(flags & GET_OID_QUIETLY); if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) { - if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) { + if (repo_settings_get_warn_ambiguous_refs(r) && warn_on_object_refname_ambiguity) { refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0); if (refs_found > 0) { warning(warn_msg, len, str); @@ -1020,7 +1021,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len, if (!refs_found) return -1; - if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) && + if (repo_settings_get_warn_ambiguous_refs(r) && !(flags & GET_OID_QUIETLY) && (refs_found > 1 || !get_short_oid(r, str, len, &tmp_oid, GET_OID_QUIETLY))) warning(warn_msg, len, str); diff --git a/ref-filter.c b/ref-filter.c index b6c6c101276..7f5cf5a1269 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -13,6 +13,7 @@ #include "object-name.h" #include "object-store-ll.h" #include "oid-array.h" +#include "repo-settings.h" #include "repository.h" #include "commit.h" #include "mailmap.h" @@ -2160,7 +2161,7 @@ static const char *show_ref(struct refname_atom *atom, const char *refname) if (atom->option == R_SHORT) return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository), refname, - warn_ambiguous_refs); + repo_settings_get_warn_ambiguous_refs(the_repository)); else if (atom->option == R_LSTRIP) return lstrip_ref_components(refname, atom->lstrip); else if (atom->option == R_RSTRIP) diff --git a/refs.c b/refs.c index d7402bcd196..3bee3e78299 100644 --- a/refs.c +++ b/refs.c @@ -730,7 +730,7 @@ int expand_ref(struct repository *repo, const char *str, int len, if (r) { if (!refs_found++) *ref = xstrdup(r); - if (!warn_ambiguous_refs) + if (!repo_settings_get_warn_ambiguous_refs(repo)) break; } else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) { warning(_("ignoring dangling symref %s"), fullref.buf); @@ -775,7 +775,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len, if (oid) oidcpy(oid, &hash); } - if (!warn_ambiguous_refs) + if (!repo_settings_get_warn_ambiguous_refs(r)) break; } strbuf_release(&path); diff --git a/repo-settings.c b/repo-settings.c index 1322fd2f972..4699b4b3650 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -140,3 +140,12 @@ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *re return LOG_REFS_UNSET; } + +int repo_settings_get_warn_ambiguous_refs(struct repository *repo) +{ + prepare_repo_settings(repo); + if (repo->settings.warn_ambiguous_refs < 0) + repo_cfg_bool(repo, "core.warnambiguousrefs", + &repo->settings.warn_ambiguous_refs, 1); + return repo->settings.warn_ambiguous_refs; +} diff --git a/repo-settings.h b/repo-settings.h index 76adb96a669..51d6156a117 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -56,16 +56,20 @@ struct repo_settings { enum fetch_negotiation_setting fetch_negotiation_algorithm; int core_multi_pack_index; + int warn_ambiguous_refs; /* lazily loaded via accessor */ }; #define REPO_SETTINGS_INIT { \ .index_version = -1, \ .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ + .warn_ambiguous_refs = -1, \ } void prepare_repo_settings(struct repository *r); /* Read the value for "core.logAllRefUpdates". */ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo); +/* Read the value for "core.warnAmbiguousRefs". */ +int repo_settings_get_warn_ambiguous_refs(struct repository *repo); #endif /* REPO_SETTINGS_H */ From patchwork Thu Sep 12 11:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13802046 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 372101A2C22 for ; Thu, 12 Sep 2024 11:30: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=1726140630; cv=none; b=TI5NFGuL0JcGseAjzeg9cZX61A/1sU54xeAIn383NtFqz20BVIqkfXHVqkNX8anD39QoDimnj8UoDCYum/tnE8EzztaEzQUYD+Kcv2HAAJ09ohNkG6ctKmYfm52JBUM3JC/7cWOtewpIm9Wq9M+AgTBMijO6MnVa84Eu3LIeFxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726140630; c=relaxed/simple; bh=HEDrAb2lGvdLFNNj2HZuqoBMqtIUhtxwNJgQTe9HZks=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hMNTuDE5DpzoZbrFjeUlRV7Wskui046Yk+p8fRHKhKQzXBsaML1YIlimzUF7CEfBFSMLQHBDacriCJWyWHmKPEkV92U+B9s4lPMqBhGQwBfX+fqRRLmdjbnHB/QclZUwv07x/dpYBN74RyGjSiaC/3ZvEXUxcptIi72Cwh3EMTY= 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=JNKveLEJ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NAAw8jgp; 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="JNKveLEJ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NAAw8jgp" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id 95D611380626; Thu, 12 Sep 2024 07:30:28 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 12 Sep 2024 07:30: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=fm1; t=1726140628; x=1726227028; bh=W/44EwCG4M CAPfGEyNVP332EbYw8PsXBw/zHc3nuC6Y=; b=JNKveLEJtfKPM6AAAve9GkRNmJ dLQ3C6lkuGLjH3mPGI6WMVF2YYl+znMTOb+jCrWFiG4/OAcKc/gQfs5y1VGzipYj kTgVakKYa9D6L1Ep8R/NnzaSFqp73PtRcI47zJ/js6ZEf+ExiG5k1mznHKjU9LCz USOuQVqiVuDfIxwJXCzG6Kuj2TmS6NgVgApMfpMnRtyzjCkkFdCfyVt5P+udK4lQ Kmm2TsnTFBGldCbLgQRRj3BaukIKxvrn4xTvyBJbhZzG61/2ja98xfjP3W854YGS 83hELT0FBHiWJo1kMROfBehE6W8jltlyaXUKQZTha6CJuN7jVIFwTs5O2acQ== 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= fm1; t=1726140628; x=1726227028; bh=W/44EwCG4MCAPfGEyNVP332EbYw8 PsXBw/zHc3nuC6Y=; b=NAAw8jgpVim0d6eVQ9LvBO2WHoPmSKX1hCpXSLgeug1G pAZ9BMLy3p2eQ16lG8tBdn/JCbLzUVLoVBbZmEvgRwpB9JXlVt9PRT2Xv03Qx6qZ rj0f4X84eR34ezRoiI2rJDa8C0AUwWVQfrPBy4eX33Uj9MQowaOH4rJid/Styzhm oUOEnE8+K+YDHJgazRy2v4MC4QApYwXZeQJKR+DymrRAB0lEV9yiY2yFTBKFteFK GZwX41Tb2f1fhzRR9hwUdsgdtamiEx7RRRDBeeR5odfSrYBL/6zGZ2OJhhVWTC38 sesP07lleuVTdVzdhgibxax5xuifL4uqbASseXfEsw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudejfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhi thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhmpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtgho mh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Sep 2024 07:30:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6914f330 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 12 Sep 2024 11:30:18 +0000 (UTC) Date: Thu, 12 Sep 2024 13:30:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano , karthik nayak Subject: [PATCH v3 21/21] environment: stop storing "core.notesRef" globally Message-ID: <08672e8a073109e16e3522bb8b6c05e905643610.1726139990.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: Stop storing the "core.notesRef" config value globally. Instead, retrieve the value in `default_notes_ref()`. The code is never called in a hot loop anyway, so doing this on every invocation should be perfectly fine. Signed-off-by: Patrick Steinhardt --- builtin/notes.c | 22 ++++++++++++++-------- config.c | 8 -------- environment.c | 1 - environment.h | 2 -- notes.c | 21 +++++++++++++-------- notes.h | 3 ++- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 04f9dfb7fbd..5d594a07240 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -897,6 +897,7 @@ static int merge(int argc, const char **argv, const char *prefix) 1, PARSE_OPT_NONEG), OPT_END() }; + char *notes_ref; argc = parse_options(argc, argv, prefix, options, git_notes_merge_usage, 0); @@ -924,7 +925,8 @@ static int merge(int argc, const char **argv, const char *prefix) if (do_commit) return merge_commit(&o); - o.local_ref = default_notes_ref(); + notes_ref = default_notes_ref(the_repository); + o.local_ref = notes_ref; strbuf_addstr(&remote_ref, argv[0]); expand_loose_notes_ref(&remote_ref); o.remote_ref = remote_ref.buf; @@ -953,7 +955,7 @@ static int merge(int argc, const char **argv, const char *prefix) } strbuf_addf(&msg, "notes: Merged notes from %s into %s", - remote_ref.buf, default_notes_ref()); + remote_ref.buf, notes_ref); strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ result = notes_merge(&o, t, &result_oid); @@ -961,7 +963,7 @@ static int merge(int argc, const char **argv, const char *prefix) if (result >= 0) /* Merge resulted (trivially) in result_oid */ /* Update default notes ref with new commit */ refs_update_ref(get_main_ref_store(the_repository), msg.buf, - default_notes_ref(), &result_oid, NULL, 0, + notes_ref, &result_oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR); else { /* Merge has unresolved conflicts */ struct worktree **worktrees; @@ -973,14 +975,14 @@ static int merge(int argc, const char **argv, const char *prefix) /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ worktrees = get_worktrees(); wt = find_shared_symref(worktrees, "NOTES_MERGE_REF", - default_notes_ref()); + notes_ref); if (wt) die(_("a notes merge into %s is already in-progress at %s"), - default_notes_ref(), wt->path); + notes_ref, wt->path); free_worktrees(worktrees); - if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL)) + if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", notes_ref, NULL)) die(_("failed to store link to current notes ref (%s)"), - default_notes_ref()); + notes_ref); fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s " "and commit the result with 'git notes merge --commit', " "or abort the merge with 'git notes merge --abort'.\n"), @@ -988,6 +990,7 @@ static int merge(int argc, const char **argv, const char *prefix) } free_notes(t); + free(notes_ref); strbuf_release(&remote_ref); strbuf_release(&msg); return result < 0; /* return non-zero on conflicts */ @@ -1084,6 +1087,7 @@ static int prune(int argc, const char **argv, const char *prefix) static int get_ref(int argc, const char **argv, const char *prefix) { struct option options[] = { OPT_END() }; + char *notes_ref; argc = parse_options(argc, argv, prefix, options, git_notes_get_ref_usage, 0); @@ -1092,7 +1096,9 @@ static int get_ref(int argc, const char **argv, const char *prefix) usage_with_options(git_notes_get_ref_usage, options); } - puts(default_notes_ref()); + notes_ref = default_notes_ref(the_repository); + puts(notes_ref); + free(notes_ref); return 0; } diff --git a/config.c b/config.c index 53c68f3da61..1266eab0860 100644 --- a/config.c +++ b/config.c @@ -1555,14 +1555,6 @@ static int git_default_core_config(const char *var, const char *value, return git_config_string(&check_roundtrip_encoding, var, value); } - if (!strcmp(var, "core.notesref")) { - if (!value) - return config_error_nonbool(var); - free(notes_ref_name); - notes_ref_name = xstrdup(value); - return 0; - } - if (!strcmp(var, "core.editor")) { FREE_AND_NULL(editor_program); return git_config_string(&editor_program, var, value); diff --git a/environment.c b/environment.c index 9dd000cda36..a2ce9980818 100644 --- a/environment.c +++ b/environment.c @@ -67,7 +67,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS #endif enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; -char *notes_ref_name; int grafts_keep_true_parents; int core_apply_sparse_checkout; int core_sparse_checkout_cone; diff --git a/environment.h b/environment.h index aa38133da9c..923e12661e1 100644 --- a/environment.h +++ b/environment.h @@ -203,8 +203,6 @@ enum object_creation_mode { }; extern enum object_creation_mode object_creation_mode; -extern char *notes_ref_name; - extern int grafts_keep_true_parents; extern int repository_format_precious_objects; diff --git a/notes.c b/notes.c index da42df282d5..f4f18daf07e 100644 --- a/notes.c +++ b/notes.c @@ -992,15 +992,16 @@ static int notes_display_config(const char *k, const char *v, return 0; } -const char *default_notes_ref(void) +char *default_notes_ref(struct repository *repo) { - const char *notes_ref = NULL; + char *notes_ref = NULL; + if (!notes_ref) - notes_ref = getenv(GIT_NOTES_REF_ENVIRONMENT); + notes_ref = xstrdup_or_null(getenv(GIT_NOTES_REF_ENVIRONMENT)); if (!notes_ref) - notes_ref = notes_ref_name; /* value of core.notesRef config */ + repo_config_get_string(repo, "core.notesref", ¬es_ref); if (!notes_ref) - notes_ref = GIT_NOTES_DEFAULT_REF; + notes_ref = xstrdup(GIT_NOTES_DEFAULT_REF); return notes_ref; } @@ -1010,13 +1011,14 @@ void init_notes(struct notes_tree *t, const char *notes_ref, struct object_id oid, object_oid; unsigned short mode; struct leaf_node root_tree; + char *to_free = NULL; if (!t) t = &default_notes_tree; assert(!t->initialized); if (!notes_ref) - notes_ref = default_notes_ref(); + notes_ref = to_free = default_notes_ref(the_repository); update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref)); if (!combine_notes) @@ -1033,7 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, if (flags & NOTES_INIT_EMPTY || repo_get_oid_treeish(the_repository, notes_ref, &object_oid)) - return; + goto out; if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid)) die("Cannot use notes ref %s", notes_ref); if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode)) @@ -1043,6 +1045,9 @@ void init_notes(struct notes_tree *t, const char *notes_ref, oidclr(&root_tree.key_oid, the_repository->hash_algo); oidcpy(&root_tree.val_oid, &oid); load_subtree(t, &root_tree, t->root, 0); + +out: + free(to_free); } struct notes_tree **load_notes_trees(struct string_list *refs, int flags) @@ -1105,7 +1110,7 @@ void load_display_notes(struct display_notes_opt *opt) if (!opt || opt->use_default_notes > 0 || (opt->use_default_notes == -1 && !opt->extra_notes_refs.nr)) { - string_list_append(&display_notes_refs, default_notes_ref()); + string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository)); display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT); if (display_ref_env) { string_list_add_refs_from_colon_sep(&display_notes_refs, diff --git a/notes.h b/notes.h index 235216944bc..6dc6d7b2654 100644 --- a/notes.h +++ b/notes.h @@ -4,6 +4,7 @@ #include "string-list.h" struct object_id; +struct repository; struct strbuf; /* @@ -70,7 +71,7 @@ extern struct notes_tree { * 3. The value of the core.notesRef config variable, if set * 4. GIT_NOTES_DEFAULT_REF (i.e. "refs/notes/commits") */ -const char *default_notes_ref(void); +char *default_notes_ref(struct repository *repo); /* * Flags controlling behaviour of notes tree initialization