From patchwork Fri Aug 30 09:08:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784755 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 00C4116D9AA for ; Fri, 30 Aug 2024 09:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008944; cv=none; b=QYUYbTppX/Im2KWpDmwjZTnEYNrJGuRN2x8G5PrcSU88CR8/eLyjEC02mTPSgvSelfSNxyADvymvbwsOtp+Rh5lwaPVDstvdWsS0P1akUzg1mVLpo1c5BXegeMcf8QrJqVWsh1VKwu5CudMjv3rYvSxortWDqLDZPP6yM6R9Cz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008944; c=relaxed/simple; bh=TwvXF2cDRsyM5GiGOoNz6ZLeiYKFNCYh/0tk2qnIBCk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MAza3OuK1onbBMnHkhfKg9LplgGCDJufioyEbuzQAYwplz97vkKNMMumqvajnv9mFvVkkthVEfGI9l+ZU+eh7uJoS5Z+T4dK8nnHvDHg4cU+mV821Dnk59BQHeZ/WhGYEwoGAmaJk306ZqN41IL7VHD+NjM0XAfeDr4IItkkr+I= 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=MdJr80De; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lzFAKG08; arc=none smtp.client-ip=103.168.172.154 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="MdJr80De"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lzFAKG08" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 010611140242; Fri, 30 Aug 2024 05:09:01 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 30 Aug 2024 05:09:01 -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=1725008940; x=1725095340; bh=XWQvZhOtpn YWxxV13AtNtausUdh3iPFgqOStyoujtVo=; b=MdJr80De4J7fqUL3AB7MqdMJJA jDfFuXRrdL/ZK1o/sFhRJqM9hguLHjw31sQ9FrHmd//msQMBc8SRIHpudqHaOMDv iV4nE4Y7l82cD0/xv6082vcev/lwcRHLgngt4O4SDrr6J6FBLhM1FbJiVPooc10a f33OJ/FYn4z67JgGYO+oeKoMsb3dddj82dbcdL1PyRgKXFrJLFmkqeuJLuHSi1AT NZ3xDB1/d7VD1iY0U1UfUFc5SjegUBwBbO4zBHZkI/4nPy5Z30aylFCpOgiqAEpa hZqnG5+7mmQfIx8D0nDohGEPRdestC8CVosQX/+obyKz0IBSf+ya1axQfCnA== 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=1725008940; x=1725095340; bh=XWQvZhOtpnYWxxV13AtNtausUdh3 iPFgqOStyoujtVo=; b=lzFAKG08feUb/ZFFnXLCR5SKn+D520h/t4z6i5ID7V+T J/yjPsN37+232vDpRNoTNCl/sks8PB3b5zOQmj+Wo1TpanflL3PayGUWwvywir6g VUNe4+Uz9SF+2hK1Wtgzbzw7QdLUWqMdxFjDCFLXjRWKjOo37Uygo03oExPObJQ8 rrb/mcGmR4OpEspV1nkjr3xcufJiXR4UTixdd6g36+iVvGk6LpD0sY+OzxbPFFl5 nRJQzP0ZBqSTjynYhJiNxapdF97gQhdac7AIwQEJ4sT605acz5r8KNHQdKx2yu6h GylaAfiX6q3lleu6edVMrjky5yUBz+n0/r+1FkR1Og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepieduieeitdehieeutdejudehkedvgfejudefgfeiuefg jeekudegfefgffeftdehnecuffhomhgrihhnpehgnhhurdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgs pghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepghhithesvh hgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegtrghlvhhinhifrghnsehgohho ghhlvgdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtg hpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:08:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id a1526b42 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:08:48 +0000 (UTC) Date: Fri, 30 Aug 2024 11:08:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 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..6f43f2e8344 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("git environment hasn't been setup"); + 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 Fri Aug 30 09:09:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784756 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 21F5C16F0EF for ; Fri, 30 Aug 2024 09:09:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008946; cv=none; b=npJUKLsywhpf9ucTzxlO0Lw3vQDfIfx5HQkTKcNjRWKzmra/+qOs6DhWFknCj79mUEt7/gmsZYPtB4N1BN7k7FxVB6SG+TujFoRumvScCPTf/LR5wLfsG0ftknzi9RxYCjZXSl1J0u5dvxX82P3e3JayXM7NnXsq43SfWbjo5gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008946; c=relaxed/simple; bh=YnHPVq7ddyZqeCgyvHJu6jPWncVndN3uagEbj3xFHx8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V5kk78AQkh8teG88M8YDwRvIGeJYiguI0oFruufvR6utujCz6kJBtH9B/eO4ZHk08G1x7+5OwjvoiKrW9wDYfldIr1qiQYp3tw50x8KzmvuQoOIfynxCPd2x62CJ7fihq1Ku6WL6FkMhTKRF7aB2IUE+RyBqGU1c0IZqofqB/MI= 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=DTq3awXr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=D1mH2mpd; arc=none smtp.client-ip=103.168.172.150 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="DTq3awXr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="D1mH2mpd" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 499F1138024B; Fri, 30 Aug 2024 05:09:03 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008943; x=1725095343; bh=8UN7Y+jgjt nCbR4cn5pZ+0pZiBr7USicCmksrTIWIqI=; b=DTq3awXrAv56ubs1W+4+1092z+ mcICBB5jAqetx82FY67W7Zb+Nu53STAbOgqav7YoiHtPvt27ACRYRaAVe6laIkad WDVnpBBVsGiH4e0Xq0T44zOgSCu1INctug7PxcrXydtApfnnAxwMrxodYmw1xN4m HbKsDjgryN99QjiRsMbQQ0uYYvlkzuvc+bpgcWXVkqJRw1453+Z9+hDKIx/UEEd+ LlJdlVZoQSILAxzU7o75i6D1WqhILWoy8xWURFZUYYgOTTgANiCfSecgH7CiTiub p5M+gU8i3INk9+7ZfER8ytwDQQzDUs4Nc/FjjvE15x+OekMhfug5opoJNb5Q== 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=1725008943; x=1725095343; bh=8UN7Y+jgjtnCbR4cn5pZ+0pZiBr7 USicCmksrTIWIqI=; b=D1mH2mpdJm+0a3l51bXltQRfatMOuNk0Ym0j9fu9tP9D K2AAeJiYIbbbtKuvxw4XYfg3uFFXZ0TvUvsV38sAmYMRrORVVlyCLqs2Ge85ngQw YIgZbS5rhls8wZkxiAFtqEmE/9m/vQ+IkF7NHYrsAcuZjxZVB07k8F/sPiK7mbbQ wSWXUujIab6E4zkHNs6bDNFhL7MIE/5KVtUrv6Q1jCrMidr7LyuoWoRh1EzP77z1 nIG0xZ/zGE8oBmDkulOkIKGVKSyou1jVtAbXZvJqRR9+PaOUmNplhCf0+5Eci8bF WxY2cYlNl7qHJw7W4SuyNE6RN7rz+RZq/5kqLzmiyg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:02 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1b0bff9d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:08:51 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 02/21] environment: make `get_git_common_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_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 6f43f2e8344..acf654d7ab6 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("git environment hasn't been setup"); + 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 Fri Aug 30 09:09:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784757 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 99EAE16FF37 for ; Fri, 30 Aug 2024 09:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008948; cv=none; b=auWe9RN1cMxfWG5nzoCpenVIqD1HpRKHBqZo1F7VqgtCTSRuSS1zfu4l9c+Yu7GxZVquBcVH6Rd5gEgIRPW3mBsvsuK4E2jldmh2CVrkecnwlwI7LAJ5A8sMYzs9YPn0S48KBZjz9eyrOG0TRWfFQJFvy3oUkFQxV5LV6SVpKDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008948; c=relaxed/simple; bh=ImRahWzBYX1NQ9G1mrbfsx9eZIE2fK1g1D2eTADBBZY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U0WWN44/weYyLFs1PCPquTRHA60P+spwopwUrn2XgQlwqrDQg0cew2ghOVRbwwyJZFyawpYBJSTYg06rHs1a14jy5hvmqS/oUueyNCL8uy2uhvd0NpdM75pBG4w7NP59YpOrm2pH5EdWLQNeX+96dU/CnaxXV9musD9i9jbe+NQ= 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=O2QRH7rz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JbYQTy1z; arc=none smtp.client-ip=103.168.172.154 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="O2QRH7rz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JbYQTy1z" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 8FC2911400E9; Fri, 30 Aug 2024 05:09:05 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 30 Aug 2024 05:09:05 -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=1725008945; x=1725095345; bh=aTqgQVNIv0 lb4c56b20ZoGmLGYLiBrpteWA5AJcW2y4=; b=O2QRH7rzH/SaLHkpbCFdPfjd8t MpEjnrnTrjmChWbOblAX+Q9CWGNncXLCJd4i+84xVOBLuEa/wvGRRIbMcQ0o4auA OCZv5ZW5QlXebRHaLVrALpt4uF06KrEtclxX+Hq6QVZpM22d5p8weu8kM2/Lb5d5 UOT7Tf7WIEEyal0bgT23NtpgEHvsyJSOAmy/FQGGhnzgY+Zx7JEhf7a2EpZ7x3el j1l5nuRdI5rDod4FnEDD7XTHGeWa1YGvrgpHJ2cX9LnjmTubZkYOfu7HZNSqPGoD aZ2erdca66iZG0FrJhG8npWyWAs/aWcjtDaFwtgeqLdGtY0VZ7kyKU/8Lgcg== 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=1725008945; x=1725095345; bh=aTqgQVNIv0lb4c56b20ZoGmLGYLi BrpteWA5AJcW2y4=; b=JbYQTy1zDg6EFAi1i5Y3AMbhnNbiNyqoqqfmp7Uu3t/7 paAg/t8LUyIdcIYsTW3+dtpnlI+gbbQlrOVATaAbVcP7r7EU57nfjFqBiGkY1Zva ikhyrQiy0EO7bvOZaHIU606wpC9QX9ds5RhBcvRfjE7PY6hLqv5WqsiXKfyf8GGc 0l7PKzLDiYZJuC8yhvVBrbD7f1entv2fAwLL5pZx/LguoLkU8PbuT7CXv0zFIMsO FCqqaBXFq+MyzuxvCKhgw/3X1XuJn7z3K5WvRrnmYWf4lss9Um0o3u3lHEh8bVX8 n/LtPzsmwh19N1oyg/W0tuc651CfVoDlBwwrBlF0tw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ddc458bf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:08:54 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:03 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 03/21] environment: make `get_object_directory()` accept a repository Message-ID: <43abfa7b139f456b83ab58d33aaf1e97a0225c67.1725008898.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_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 acf654d7ab6..914ee25a1f0 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("git environment hasn't been setup"); + 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 Fri Aug 30 09:09:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784758 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 840A916F0EF for ; Fri, 30 Aug 2024 09:09:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008951; cv=none; b=AQCm2FjH0FHyd7Go7IYAse4wGah3pbq7dLZjEhsTeysTTOcQwDBz/UGZhfbI4cZ67HRLDw1NgcVjfuBAjUzk3olbJ1VGgGKFLVXGJNIEQfwUDPVvz4cKkqkDXQxmqwQEq5MyJvTQaXOxEBvidiquSa9sYfC6QcL8Uu7es9QiBW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008951; c=relaxed/simple; bh=l7n4d7BJZ0Mf3pLvL7kwT+4mgSEOJRmUXj3jtkB1txw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nGh5P5SuCEo5EQwGo/2IN3aazcvp71nhVhA46neP+UVG8hmtflr/t3p/rmwuJHJKz7p04MeskofN7RlDlC2nJMOqMRLI9mPs7gqLqVnj+GB3IKcwWz7yaF2vQjXH+gRdHH9m76XBks6f0rU1+Ftq4Ebc1Zk/aMGUt8ygJv1YP+M= 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=Jja1i3aZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CFwSVFbz; arc=none smtp.client-ip=103.168.172.150 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="Jja1i3aZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CFwSVFbz" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id D6A161380266; Fri, 30 Aug 2024 05:09:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 30 Aug 2024 05:09:08 -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=1725008948; x=1725095348; bh=kVNjnRoQio hDVsNIf/2KePZBYvh0TZ4wL5PwC5mknBw=; b=Jja1i3aZ40aS5nYS2059PegTjM VgV7N9tGzUJIdL5iwn0G0sAmeR79pJmexjxmAWSO69LneDjEAD2gvntO5B8LJLoD WeLTfTDDpmntY3pzNQkEg2KNarpWM1W0LUUPkWVPqzzFZS6jtKJKDuuDGYnSSUeJ aQyFyhACjG3EF5ag5gu4TrJxBKKrUA0w5Eo3aVGpSr8Rjdfp1dNJnsBfzh2cw2dL qnyBmkBr1dhd++ZggDUH9NlHCuAxrl5fJYPH8vgxOrsFEJlRJwtxYlvcOVYo9L3f +Z0UmZpF+gCoEbQqwCPWlwH3tvRhgpLKVQV4FDHd9sHqn5OzOvk/qU0S+LlQ== 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=1725008948; x=1725095348; bh=kVNjnRoQiohDVsNIf/2KePZBYvh0 TZ4wL5PwC5mknBw=; b=CFwSVFbzeUTZ3AdcdnIOC3xqSxqD+Ea82xgRlCFlDkaN bd5eIx556WAsSG/jsvJ3+OkG55MSS/lEtS3cckR2PHFvSQaFsEfEeS4mkbT+R6uk z3E8wM12HA97FWskUcrxbefI/UQVJ4LdTS4sQkgqPrnm0pGC/Ck5+P8TTc4v4q3g 4kf6u+tZNrOde+g6R5WrR80jPBGx0vgtMO3aH0OacP1Yztx70tk2ZjgIV8soa65x be9L3Ln466JHSqRmp0i1Im7jlt7fr8Svl1daR7u5I4Ec/OLkWMu5a+q1FTaU4IMR BS057LGSjlAOH0z+1+FoEAqGK9j4TrXo8DyMASE8pQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:07 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8530c310 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:08:56 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 914ee25a1f0..a9bbde80b5d 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("git environment hasn't been setup"); + 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 Fri Aug 30 09:09:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784759 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 1732F170854 for ; Fri, 30 Aug 2024 09:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008953; cv=none; b=lYo6bEBFddHJIA7vEaUAO9RwrqBruarRxqTFJN11Y12i2u7HTiMj+81Z1XmFuIeHQ9v6C93vojXL0zi1UJeFMY7Hx520huhFv4qydl+8T1sT4LdZE/muPgauSu5g5YvOTSFT1abcBttkgsP3DLT9i7azmaZILyLBRYUyny/N6M4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008953; c=relaxed/simple; bh=5X+j8eyuOqAQEYFSOsriBQk4lo0I4Mf0c4J1JiolNQs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hCtTRbK0/3GcirY8B8n6fwR0Fn8jovYraA3YCwxU8lgx62H4QHcJw+ILThhNhH2DfYqVYoC7vmSzaCgAvS45YOfjC2NoCpR4csMkaub+B8t0h1FMW1c8kUXuATwFt7wcrrboQB0EcGYZ9vNdamCXuS2tdPbfkPUkehkvg/VoCFw= 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=Ib5dIjG2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=AJ5el9Nt; arc=none smtp.client-ip=103.168.172.150 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="Ib5dIjG2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AJ5el9Nt" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 40A281380277; Fri, 30 Aug 2024 05:09:11 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008951; x=1725095351; bh=LPGrX3oUDl m6APvwDZROzJz9tu2SOxRkhVo649AlV7o=; b=Ib5dIjG25ne1r3MsR/wZv31pb/ aansLYMt8P3K71sK1BBs6hriCazr/nhJVm3nn4MibcIrsmO8hdV6bIqpNXM7o4aJ 851YCq7yb6XcTjcfbb1ZnINU18yck2zcZ2AaR3/pmMM+T9hEeDmtZSE5UvUxyET6 SvsasKddYDFpMMUTQXLE4Y50rhCMPZ7y56uoeGD7LZ5sNcx5dtthIGpcnyHL8VmW G8DBJSK+C+1ZB+qKa9upAUhQaG7bIWcAxg2YU7yDu31Z93lNBB/kAqqVWVr1anDh SXJGy0Wb0jWoZ36rhZae+9HvOx60U0t68IZ7Xmtz0+CjFAjL0IX4QUVn7yqQ== 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=1725008951; x=1725095351; bh=LPGrX3oUDlm6APvwDZROzJz9tu2S OxRkhVo649AlV7o=; b=AJ5el9NtelJSgxnVQheZyI2vyGbppvFgKBfCUE8d1YDJ QsBtc4SABRyxeRxKgmFf6TDIIe1H1HbNSdYE0WnoP6QUKIYkRX/pUZHChl27DFnw mzB1WVHUx++khCc1Pv0mjD9F8RbfeGYTPUpg4RKS+VglPreEs78ARkCV+ruAoGR3 N5I+BIbJAO23F8n64HKaRHuJG+o7s/8uOswdCl2dQAUA9oa/Ug3derJQF4Na4WdZ zYsoik+wBDVomq1uIyhOvk74EeqQ5yyZ5U61cofeG5jxW+x0HiNsjtnSHK9maOLh Qb9VEBkJcHpg0Jk1KTS+Ro08yEnevNtW5AQ5BFnRCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhi thhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:10 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 49ec0036 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:08:59 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:08 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 05/21] environment: make `get_graft_file()` accept a repository Message-ID: <1cc727e4763e7989a3a0474faae5fa730539737c.1725008898.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_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 a9bbde80b5d..cdefcb4002d 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("git environment hasn't been setup"); + 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 Fri Aug 30 09:09:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784760 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 C10E516D9AA for ; Fri, 30 Aug 2024 09:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008957; cv=none; b=Frz4YOfinJufCZe8OFVg33z/hHavo9PLP6pvYlFoQBBc+UL/Ntc2rNmNDUAViJoE9d6sjTGSPHEj/+Dne5QwcK1+qOK6lg6VqplCWsuG4YXK5JKAnHuUIlBUJqqELCrGgkv6Rgro1I7mv/C7mKxitI+hCAr3YV3HwnO0Rj/q1Ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008957; c=relaxed/simple; bh=OFczgdoBIXESlGKY7PWCG5l0tetMiDiuu2fBUczJH2w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kIeaZyKquFPNkaT/EROzE1lDttgHxgMxBRdzCkb2LVUsuKNnBHpUfogw4lHCpRn247bzGnKcb9/Lu53PPXtXpTWbNtjmtGsPHSy0abzVLpeMv+04C7jBA4Ww6OcoYLeWOnWdCF7bS7oQkJKhjNGy86p2D3gQMSshuOwUGE+0OJA= 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=Ga5AQx8+; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=DdGU0Xjy; arc=none smtp.client-ip=103.168.172.150 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="Ga5AQx8+"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="DdGU0Xjy" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id D6AFA138024B; Fri, 30 Aug 2024 05:09:14 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 30 Aug 2024 05:09:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725008954; x=1725095354; bh=oG844HO9UJ SVp5oIsWv/vVhlRm9aUef9v9PvV/sovB4=; b=Ga5AQx8+DDi+huuaiUqc9Lxno2 XJwi23ZRyeuqC/i3Fc8yXaPBbtrACTg4QyNRDIhwAfeFgeO7jGQIOJ51xKLrfZME eHgf2xKL4vhG/TAcgKaC8/oGEQnVKkrc7fCbb2gWQXnP1zSMwd16Vpc1nc6vSiJ9 3llIhVhdqOkhXO6DKtuaCc6kgvOZVGSyBwAQKMIIZ+xkoN4wT0ueluOfwXApZwDs qoc1IYOmhwdUBNgjm5JNCwjwujy3jaoTjlKcIbOWdWCqPlHbDOgM37cu90QX9jv1 psm2aPdUQ6n0YbPCmwZytL2eWN3U3llMC+vzo8VUJg2lCS7IO0ZNSQvY6eeA== 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=1725008954; x=1725095354; bh=oG844HO9UJSVp5oIsWv/vVhlRm9a Uef9v9PvV/sovB4=; b=DdGU0XjyiH9ag8O1Jz54JN3FCFomFSKgoKR2eP5rfWqF pFB7vYLyhD47nAjBrGAVxPHoPywCETQ6H0j74tNNKJhGxuae/Aam8wWGCUggYZib XkNQWptBVOWPJcGHsGZXBBSji2x2IXNs5sDduqhGyDJEbLkMX+ZZPvojKZsdogrU vp90nKRrxTURzgUab0JVbs0U49ZRV0Ror/UYoln2uglIECxmr1va2K46w+lLb0lJ zy/0APvwjkNqZbBV3x0rxWDRNgJMZUqQ2KhNZssivWUHqQmLuyGQb1hD987lilLN PuvtCU7UJUs3ntXc+t5fQiaEiYw3rRoNzcfE2qmwww== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthho sghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 71f27b12 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:02 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:11 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 06/21] environment: make `get_git_work_tree()` accept a repository Message-ID: <22e9dcb28a981eaa1a37a8b41e8d061347ed6c2e.1725008898.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 cdefcb4002d..92238da3d9e 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 Fri Aug 30 09:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784761 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 EE899170A3F for ; Fri, 30 Aug 2024 09:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008960; cv=none; b=bgfbFOV03qZcWaRIoc4Vbds2PtgyKZHwoc04+DEN2qxUhX+JrQXG46NIPyHb4QAd9x9aXnSjaXJo0PvEaWRgMmZOAbihK405DdTCr8YQ6zkcJ/PFPDyx+JG12aETHCzIQT0tr0oqSpkfIJhkEw05RPAkoIzeWWw1rvPs7m3r9NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008960; c=relaxed/simple; bh=JoD51J+JOJqwnkiD/LyF2hQOEb4TAbVQzeoNTbQX55A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WgQkg74P9ObJ90TpDxzYsOupe72vFZwoff/Adlvr6kbQi39W+vJ2hk1/N2nKjc6AiKqiKbGIAR6wA1Zdv254h/+aR4FWgwLykI+pBeFtEWJ3xdFLFX3pITqIe5JA5QLq53G5yONO8Peg3/fsYH/HMlMIYujl/Wf9BAH7qHeoYEA= 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=BqH+XowC; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gBpM6bcP; arc=none smtp.client-ip=103.168.172.150 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="BqH+XowC"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gBpM6bcP" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 27EC4138023A; Fri, 30 Aug 2024 05:09:18 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 30 Aug 2024 05:09:18 -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=1725008958; x=1725095358; bh=OTItF557so uhcXA4J1+3V/q03k7S7/YyyAAQEVNCS4U=; b=BqH+XowCCwmLfS38ur9siUoZWg cl+x4+pDQm4rh+a/Pk9zsuaJdEse+/Q3rBsfmNaYMxL2UXC5KYWuOwtKCIsqXpYF ah+PvVD3zsj4s/PFnqQSmNsze+9qduF5CNynS2dLjaeCgCmZ5pF+FIj7/JKZvWmj EmDNer2yn60hgiu+Eu7RciH7t/XYrWTkJ4EAwLiLfzTqPw8D+i0xzENYIK1OuTu5 jRiwoZbVIMLI5J3T7sUF77qTv6BKZI6Pel26NwjlOjN9vV2XzeEpp/SBALQ5nxkb b/glm0+2vSrcw+or9+3PHXGNL5BkRnPHOQtAECbq4vVLV03Owzp3pmhseEHg== 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=1725008958; x=1725095358; bh=OTItF557souhcXA4J1+3V/q03k7S 7/YyyAAQEVNCS4U=; b=gBpM6bcPdVwa4dxSxPjwyWtc6s+xuRugmKiKzbNYoqOl VSoNAkye3hqkTZ1YS2ewgCPYqgVklQWZWqskgagzTeBJmHMauLZpjDN9RjXKZEFC ZwMYITe/+eWaJgcYMMZZDAtYhdbzqYbEBCjX9incV48cRr0RoSgk4nvaCG8WIZB1 p4LZltYLjY8u4rqwvFjSYSuUe2nySrmLVByjIkOw3WrYdACQCTglgD397kDwABxu htV362Qme/Mozo33xsSOrhA9bZb+wRjcUbrLe4YV2ofCZkpyZMLxRiu01OnXn4An 4EjHRP3Um/2NsXDJlngBW4Ouu9XLDajT5jU1hkV+EQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:17 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4c89eb75 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:06 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:14 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 07/21] config: document `read_early_config()` and `read_very_early_config()` 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: 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 Fri Aug 30 09:09: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: 13784762 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 17FB4171658 for ; Fri, 30 Aug 2024 09:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008963; cv=none; b=hw1ERl9zL6Q+hqvjHz2ua83INlgLS9B1N+LRB1oqIDVaB001Tti56dxfdFFGhH4A6WXlHfnzWcZsb30/5xdr9Mm718fMVGXZmpTRGxgd3z9uaH/6jf+ED7jpUMPocz5+pr3vw8b9affzmv6DMMzkiVxBVeXJYrXNC6e5BOQISAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008963; c=relaxed/simple; bh=Mq0U0WwJtn1EmExkLW4YOYN8JRX2YfmxhsusaMrwobo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WDePL99aoHoz9yYcphiW7RccrVjd6QbMyJymkYe5cL0jKJqUr4Oc2EagJ9ZYBwk/vc0etw963PIKaRg2ceHMje+QD1RxHtzppeizqqjc3Jv4swvhTNtO3JGowXn2Wl+fkLEAEq2QpwnX/vhCUtNqqS2uuL28Cc94OxrWrTdBZWM= 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=pOiNqv8E; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gVEdpXCa; arc=none smtp.client-ip=103.168.172.150 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="pOiNqv8E"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gVEdpXCa" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 6BC601380272; Fri, 30 Aug 2024 05:09:21 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 30 Aug 2024 05:09:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725008961; x=1725095361; bh=2G8FfczyXk 58W8Hdv/10UbX4Cpv4Vof3RnqLz6X/e/0=; b=pOiNqv8EpIGCebNufLLWPjLRJX 62LfQgARGjzVmdk4yPZz9ZakAPK8u3pWWIdnqcekjYbsecV6553gAuqM883yQ3oQ fjiqmlaWC+HPYinJrLXwif1V64cwBLeC7sCrcb3DPFXaYVDZ9vmR9NGlaOtr+iF4 BhJQ9e/FUacaHU1U4AiMedIgvMp1b2S4HGUzsHu9Xb1dTvWkKkCbk2LsW6djfozF uNDVJSPRh6nBzP80FSy9QWgT29o71JBYyAJJIWFQKoODHh1i4T3m7x8gb8G4aGUc loCbkvOf4XKk/M5RpguwFBc3ybA0DPF3yJrkzIi89Na4pOPIedQLWnBW08sw== 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=1725008961; x=1725095361; bh=2G8FfczyXk58W8Hdv/10UbX4Cpv4 Vof3RnqLz6X/e/0=; b=gVEdpXCaWbsKsF3sxvj56T/1uGqmUweFtQ5EEwY1Xdvm O/9jd+V8ascHoUkqwdhuI2s73SDi+NfJIF5/JQaFvHn7h/gntPUoaEnWqqvbEBmw Ap2jf7RxPmQfvx/MEIryh4hA2vAF+g1KAY1b8FoEO9OZLuXal63LqO0qQvJaDzyQ QEJlvokFtWHUvd7noEoBV9dICpz+mwDw5XMz3f/2vu3arLffQJaQUVf82sPvgxsw NJrqjcxRbCjHqkMKA0mk8+iItJS+jPkWfbe52tQdAnXTaAj/g9TUnwO/q0/A4reJ N8daQkciW7fdV+T70wyYRy6b4VtMMnXkD0v4n8qwjA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehj lhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c2064d1c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:09 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 08/21] config: make dependency on repo in `read_early_config()` explicit 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 `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 Fri Aug 30 09:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784763 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 A4CBB171E65 for ; Fri, 30 Aug 2024 09:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008966; cv=none; b=pgK1gfSExrLSDujEsMerIilRwn19bviVppD7DkbjzdbvAuY6Rk1qBmF77FqIJXA22Yyb5aBoBcv2KSSnieegtluQ2HUz77yLS1isibh5H5Jjk8PfzcJvcsnZIPTDui9/ngdUZqCzCJA2i9WDvBNPaxi/QN5eDKrEUyhxt64IuUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008966; c=relaxed/simple; bh=7FlUWH34xV50jWr4R+KmwLKrUw6lhPCMltwzgcXTnJ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=niAuu86WNGnJAeq1bfVC6q88VLNkAdIcYYV7UbcG7ml/nQ22/PUiSCtBC/d97pTIxaSdcJ3XpBH26Y+TnXoTiU8JmjGBl22eYWg3m8XFGeHTxNV3rJrvtBJpz7DWIVa3Dv/7K9T0nu5pGhCt0+42v2Ohj06WKrL5988jn4crm5U= 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=gkKILTTg; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Enfq3mVL; arc=none smtp.client-ip=103.168.172.154 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="gkKILTTg"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Enfq3mVL" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id AB6A2114022E; Fri, 30 Aug 2024 05:09:23 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 30 Aug 2024 05:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725008963; x=1725095363; bh=/V0TukJ6Dj WW7fQeR3viYT60KXRL9/FFuaVEmSmuoJc=; b=gkKILTTg/7AEDx/t6aqpg1Hgy/ fFq+jr/6ubzvleEHXOSTabi+xgxwZ+I4TBvfb2JVovJeGGMZPiED14YUPHZYlsU/ eRLhau6caWBK1TUSCMo85V17IruRR6Xd+L0YbCEyINfaGTZWuzrkWOSrf28LNsDl IApkHR4z+jvZ82PG2eWeN2oIyop+gosHAqZnGG8hbzmYGghrZGvC9EkVt9lUWTCg 399PMXWKfQhV2hGLA4UhZtz2RUBBIZAtN05HxRSrmT5IpPU7mRa7hSfenGP3SUa9 QAMMfoKnI61q1cANdg+Ybp4IA/Tm0YYaHxYlT6XNcA96IT9z2rrgv8Pury1w== 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=1725008963; x=1725095363; bh=/V0TukJ6DjWW7fQeR3viYT60KXRL 9/FFuaVEmSmuoJc=; b=Enfq3mVLKuMm0/mKYfPh2/S5CO9j9yBqk5Jy5cf1vqXO PBEb/ctd9bxbNPUaNrgs83RrETuJtBCT2jmPNVxfjsiMoSxjfLgfSXs9AfRQFkuM l9+eIeujVBT5NNbrQfPKjwWrq1mEfrPoYPueyN5W3Qcwpw+yFViQD3lIE9N4JySd pGgnoPqkuXGZafoKfVwdnmAAhjyoAXh6WQusGnG12Z9fTAutFi3wgD28dY1paEGn m9OR2Lvp/ddY+11Dd89Lk329ViA031pl0pDLjXMi1G9OBgOGP0cq+sSehweZRMPm k6K7o6No9zwfIclCvUnco8BFpswOf4jfVdhcWVXgXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:22 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 97930346 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:11 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:20 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 09/21] environment: move `odb_mkstemp()` 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()` function is quite clearly tied to the object store, but regardless of that it is located in "environment.c". Move it 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 Fri Aug 30 09:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784764 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 8C90316F282 for ; Fri, 30 Aug 2024 09:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008968; cv=none; b=E6XQo2XagX0R0+eLdAAQtb4nZkVJdvz5l5834LZDiznm9IvWk1aEExkc7WBVljiSiLcmok0+1RQOZW3NxdvJYlfTUwVjWmOK3s+MvkGiKMJxvBii4HJiLdT68d5APSYtct+VHeEYb14MEVId51vEW1PzU214j8F+Z7q7LlO1d+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008968; c=relaxed/simple; bh=D5MU50bYaWux5hG/GAGaU1v58ZHkCnoj1xT1ZltDFoA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bqGEg3kiINH5tXJ1A/j4ceVMTbeXDTlrsrYA+4rEoRVq3pJb4J2OhYBIrzAJ4S5LHnUa0964csxJvWCbR2pSOucnbzdadtq7s/9cLFAylrZNFfvKhT6KG+RXP7dTwW8SQSqNtmyq+CJV0C69UKMfFog1GNP/mg9RKGG/1a90hVM= 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=suZ2IXjf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EvWWP1Uq; arc=none smtp.client-ip=103.168.172.150 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="suZ2IXjf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EvWWP1Uq" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id E82BF1380266; Fri, 30 Aug 2024 05:09:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 30 Aug 2024 05:09:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725008965; x=1725095365; bh=aTq5u0vFnq usadQrB0mvYtORZo3HHmDPXzy0GjkOiLY=; b=suZ2IXjflcA73bTsk7G2lT8cu/ Omjm2lT7bwQVYoysr8GJQD53jdNyrqFqgz5h3E0Zvnm+76/17vMkSRykjkpzdtBI /Q74I2sZ+XCNimGSfhpevCFQ4qv7ko6mimqrPbZoNvqxi56SHcUPbWIG/QF8wv52 VylS+6f3dyOlN5NcTPdhEodbCWahLwmtchW5b2iL9gVKtHek20FzzDP7YmNyRYGd 7LpV4eiJfQ9CZYMIUWoXBi60NcgPL3Plk4qOsX8qWs+1glKnZuvaaMZZieYzWmq+ xgF5/nUvAmjkoU/ua2BpXBfrsr+VrFsWrS8pTsl6o/fOVn4BtccgEUyfQwzQ== 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=1725008965; x=1725095365; bh=aTq5u0vFnqusadQrB0mvYtORZo3H HmDPXzy0GjkOiLY=; b=EvWWP1UqUOBt2cBKV4VKN3qru9HziRcEjEx9vf8Gm4cO qJTXY9aWoeBJQcBZ5aJBBYZc+4BNw25M0E1xx2YKwAME5de4fzgedkjKKoIyzg49 5L3lJ3dP5X3DMWij368zYgO/GXYAN0ugnsfSokAUYgCZ7/qDoG2t9WgCvc+Ijj7w 7bajUsljaxVb0GdKymBukF2wIu1/gecxSbfXDuNmI0Bkk63ooX56F4DhqaQISYei fpWkMjIAO6zsDzMYXKlY7wrU7lUo4gv9KeOVGyO6fYgDXdpCqBewxENPOlN5ekzg 2vBVm4jyoAaiMmEGyQ1i4BNFigZkhu7SKOT+ECKWOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihht sehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eba67386 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:14 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:23 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 10/21] environment: make `get_git_namespace()` self-contained 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 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 Fri Aug 30 09:09: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: 13784765 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 1C8FB17624C for ; Fri, 30 Aug 2024 09:09:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008971; cv=none; b=s/4VeRxTrjMK+ZRowL5L1Gfqwm6TIP23JmbN9TSdj905OlYc9rV/51PRSVXuZQzOb1EnBQMI9c6TY5Nc3D3rgzCo3lgyAsDIjDLoe8K3gz7TjkFwCBl2HPYhs1IQjfh3U3sOcLaDp2vNFNMfYVErOWJRKJTmT4GUKjlo+Rne43Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008971; c=relaxed/simple; bh=vmg4O+C43gbc9a8720xG2Q3KVd0rdRalkEh7ez4EREk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=th94RvBif8Bd8LB0g9PU2cBG3PIQlJK6ukJL6e/NzwtU8Il168GUi5FJmmLi+Fnw1hrMTNHwqxPUprBmhWbw/G/u5LNhhvEs0Dswg6vX6fIII71IkqkVGu0nXunjaDZR7OAIFfaaMrG6FfYMXTktjKOB0jCgcjU9CKX1ZypzDNw= 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=jC/dovee; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RybAKDYV; arc=none smtp.client-ip=103.168.172.154 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="jC/dovee"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RybAKDYV" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 38FC3114022E; Fri, 30 Aug 2024 05:09:29 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 30 Aug 2024 05:09:29 -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=1725008969; x=1725095369; bh=h1LTUd8Wuu kzG8rpzc69xe+z4sTBiVd+qWVELezsM0I=; b=jC/dovee65YYP7ETQ+pqJBiQNA A+MJVPVji7ykPd8uRMNg+yqYN1B48te/gSCoM/teO26rjcU3kj+p+aGp6GMlNZjV JH7/Jfp8N2Oo5wfjRAz78otTYqzqJdKP1DotD4odF60W+bDgVA2v0nD1b5yB3WHc eUDhnFphtYRJRaKHSfP66pgV0yAef3AYuu+2FKGW8u7OugdSfgeJ4DXE/0KvNu0X +S8ttNn9KFQ6+ytkZ1MxrVVGqZpAj9y7BW7ESW6gX7xMTSOHZ12hyHXKLYbuXfj0 YpN5BqDf/pTcTpsIdeStiWVF3k0dnKRRfgGcOPMeThZztDKs5pWy3CA4Vrvg== 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=1725008969; x=1725095369; bh=h1LTUd8WuukzG8rpzc69xe+z4sTB iVd+qWVELezsM0I=; b=RybAKDYVjgGwHCMxFSIO7dmYGDrFbRe4vHvENNfAMfWl E6RH5kfw0DeWcrap18TqOSacWY2YyvKKGls2Mjkiw7o/UySUoxNzrr+SL14SAD2e YwY3VQKsE6Gn3J99ClygAQrxiChIQ4DpAvKJ/DjJD+rodj2/NW3bn8gmwaUkKR5O JFSyuKkBXl6n+LRf5IuRjHhRtxsx9MIL131ZpYxSxs7uy6+MSIoD395Ied5LlU5j aUxumgszZK/d3kF7+XOhQJA+a71B95J32FvZtpAQ61vCSGGdtlXm1tD0sinAdiQX fnrxEP1FhAKm82qs3K/IBYgpDlBiQI/h/rRG4cWkBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehj lhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:28 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c8b42ea6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:17 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 11/21] environment: move `set_git_dir()` and related into setup layer Message-ID: <9e0e2528b9434fc10d5f4af92e1cc1667959cb42.1725008898.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 Fri Aug 30 09:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784766 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 5F2BB178378 for ; Fri, 30 Aug 2024 09:09:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008974; cv=none; b=ZDjkFumPFvTlhk/DPMGNU+Flw6amcUy2rFNkpL0QcQu3+WRVK+5wjqK20nnNIQwus8El0FjOZLgozW9oZEPTiDbkhGQTy/4dTLNPwJHyIh78/bKjhWxNC1xoLnJlMjir6nqvZv98uzQaUwgwmbQBn9k/JGtnBCheWlF7nAxuYfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008974; c=relaxed/simple; bh=kMLGyR3Ewku+g8hr/XLCrAJLPqp78OdCj8FLv2ERCIo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xj2RutPQDSe3dQdztfEu5adLbXuGeO6G29jXgf52gVYkE3iyeZdh8rSO2uConS4XLpd0xZDAhdtvkvzjwvxdIrqqyPaxyFeg8We4WpCsKg7r6AICzbw0fobagem8XI0Mr5XnrMfurmyxAIRfOKOoueqYvKbgYIet6xgNgjI/xlo= 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=XeyClqVt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=CSo/JUo3; arc=none smtp.client-ip=103.168.172.150 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="XeyClqVt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="CSo/JUo3" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 7C274138027C; Fri, 30 Aug 2024 05:09:31 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008971; x=1725095371; bh=8OKSJA681b OeIyiFhXuEg76THmOc6VJPtf2c4TusuuM=; b=XeyClqVttKnIQXHudzH0S77ijj bAgOAxGC+lN83LcCv2i4dvQIHsJOAwhf2kPI/8b/LOij3BhagyipjwgH0Eqxy5qY k7lSUZWA+2lu9l64egp8pPBMUnYkrSZGRYdA7tBWKwgARHsydNPaDzVj5f7TE3xB kl8blqyz4No0SNIXkS4feR95LODHyiZimqhJgvxWiMDt7/n3IXkjBo/UdycxJWJy BMs06H+gqmflshYbEGYk0Q3sdZQVERMZthwwDmN3VSZgfsPZO7oA/c47rLKFhBI/ U3Pad5ZztamF/QQhSUwmwE8Jyw5RGULKTYScBlBEEqzd74HQnsUMdpBuECpw== 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=1725008971; x=1725095371; bh=8OKSJA681bOeIyiFhXuEg76THmOc 6VJPtf2c4TusuuM=; b=CSo/JUo3HbsYiGrypqqyTIAlCXUfL2eYks/Qm8zU0zz7 KcVX7Dwgsrt+UkrZRvqtPMoHu0wrZPS5eKfcix0y+EI0/DDQwJbRnQoXvGJdSYgk qZWpHNVI63GFFWVJqVArdhg8KJcZGuDvT3FcRzNkX4AlDXqt0Ci/Wqo8IOV47WVX VCOQIgRV6hVI8DoxF6icAkUMJSZ9YzIA9UsAB2nrhlUAVbP0jSHCETXJNN2qU7aK OleKTqGJIMT0LsPb4HSIKgAfmVT081IJCFMRL8jVhiHyWkYnSCDACZnAtTwiSH9L sYmccE/ymFGoo3Gz6V/oR/jiNsZ2qJuv/T89q97Tkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtg hpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopegtrghlvhhi nhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5b6c8182 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:20 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 12/21] environment: reorder header to split out `the_repository`-free section Message-ID: <78f77a006a0d577ffce5d5488042d8db113b37b2.1725008898.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 Fri Aug 30 09:09: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: 13784767 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 A48D716FF2A for ; Fri, 30 Aug 2024 09:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008979; cv=none; b=eomUVEaQeXQGadgiQyCME8wei/jP51eFFOD1GltabnC3E0RQ1wcRZvllYFdbt4KpPxxoSEihXuJJg5N3rIon+JjRkb5LcDdNh583YbTmMCqiLIR/bn1MAqmHBS4oLqFwWV6VGPfDkprnSvk4K5vDOYn3DORBQhl0xPN+jZHLPvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008979; c=relaxed/simple; bh=Tfm41KthbPJIKekzItTrXa7/jlVh+RROJe9u7kv783E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PyTWduwBuo+x3z4q++V2eqj7TJFFAaTM3n5244ocGK5+IS2ZATk0XXYAOdsKEzU6Yd/+kw5iWoLIj2/9S76/yYMpd30Eqn+YwneW0SUdPDrtWoMdNqh8N/5VI5lyeuAx2c3eSX8Af4HxRxhCni0gwiDwDcHt9bL/vtAIyqVkxdo= 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=rFMGuWJy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=C1AX6nB+; arc=none smtp.client-ip=103.168.172.150 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="rFMGuWJy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="C1AX6nB+" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id C5E151380277; Fri, 30 Aug 2024 05:09:36 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 30 Aug 2024 05:09:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1725008976; x=1725095376; bh=dot8BMVqQL Iv8o7x1bB64VwtSyFPLviYpW9L8yovN6M=; b=rFMGuWJyp1sq7ZX8qgoanGg1QG EbzGAGA9AjPCQup/HCzOTOV88I0OwRGVympU7Zja9+XXLqUJUB9v62UPZ7fo7DAa ZtzFO3xa7vHbgV1qO6jZiqiIGxxQAi8ByBHul7lkQvH3YtFIPzj0jao1qzWFZW+W vMtxP13d9l5Owe8wN5mtXVGFPZMsqaiiNOeQyRXcEi9lKKaHG2uWnyKs6mR9h1vT +kXRyFoVNBKj94I5EBAFwf08ncGARjv0WcBA64uWhU8yfOpfLUPRY0RZEUsBbUgd mJqg/E6ZCQmF2xhEumKdnn+0VVNjM1wAaS8gOtK1xe6ovmC+Yba1WBdt8N+A== 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=1725008976; x=1725095376; bh=dot8BMVqQLIv8o7x1bB64VwtSyFP LviYpW9L8yovN6M=; b=C1AX6nB+Fzwg4b61xeWRIC4RnlIORQbZYay2qqJwNn68 f8RSHB15wIS/K+vODUt6nn8BO71iAZsu2OsgTXlOTfLUDHSRX4FxHZEImjU1OfzC xR45Itg95FWmfieddyhaXxxcIWiWlCalKuBs3Cbgb6h1QilCfnYIpOMo3ziQ27g7 qUBvCXEXcvOhBxc5wKmda+Z9x0hTGMESus5cjVK2Q8yrnjSD9FjNn48tmkPjSsfd nJVe0v9iilU6h5jpW5J86ieGjC47iVmm+m8AXJz/Pp/ls1WNmYTKQtQlJfFdxVmd ZFfgU2jlHlbM/VhvdgHhlgFdSaHIz7GM0cw9fhoX1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehjlhht ohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:35 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fb251241 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:24 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 13/21] environment: guard state depending on a repository Message-ID: <9a3f466b53040d693ed9b2c2390d391a5420aad1.1725008898.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 Fri Aug 30 09:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784768 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 F20EE16FF41 for ; Fri, 30 Aug 2024 09:09:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008981; cv=none; b=V+glnzeg6F8OSHSYfslknX+z68Ksi8Tx38TwJAFHRqMm+nJ0T3ILhXlfgKK9WtsVTO/qjNw9wdHELJKzlN5BM7KKxKzmFMG/r6plvrlNfqFzLg0u/LSgJT4S1fuH+AYBNIazQ57SNjUPENEU45MWeEolJKQp0hhL3NOu1ewaV2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008981; c=relaxed/simple; bh=jVDhSaCroLryPc7BTjVD3V8dlBTv6lfvJP+J9TUmX8k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UxKnTonnZoLSgVBKG8LEYjMFAN+4ZQbnw8pfAjfIuOJ7PB5KhXicid0rh+1tLqHIw1TLzJ3UXVr/bjRD5iNfSSASR5ualhzPOlAr92dK6GJKH44iyjfbkKaz2NWCym5k3RsGnACnAhJu7aJv3J5YVwvMCVkkNvL0N8Sg46Kcarg= 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=EpqavXms; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R4bJeZUY; arc=none smtp.client-ip=103.168.172.150 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="EpqavXms"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R4bJeZUY" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 0FB7F138024B; Fri, 30 Aug 2024 05:09:39 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008979; x=1725095379; bh=EqkRaVpezP 5Gle8sx/YgIgo3+DjDvKZHMRTI7S95LHg=; b=EpqavXmsj968z7ZMw+4u4UJfJJ msHisHIyOtDjKe9xMJbZHgUg9BfaCaXpZqwDVZ/a8b/Y5fOYvpNd4hGc6opVMJzr XgcEhoAkOQ8mcLWLr+KQ4AM+IxLmG4DOkuwx9wakGUgEoHQGGsuBZnpn3HayhrjI LsfiFctAIaURc0A0MEnABu+WTUDufZsz7xUWFVtZ6uccFjpkFACHyIxhfjjcDjZ8 1bB0ex5FuwhxAT3/bvuFpHZMxjj3KhGDl11zkaF35TkWTVAvXd/0FNww+lntJkn9 B7BoxufdrXQDZrlc+1Of08zWuC/ceRMeHHGXYHJ/GOhI0szo6kX78331zvlA== 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=1725008979; x=1725095379; bh=EqkRaVpezP5Gle8sx/YgIgo3+DjD vKZHMRTI7S95LHg=; b=R4bJeZUY7Oh0ghjrBwwUlksTXtxUz6i0JkC8Fe5QSdbD YZ+FS9o2bqyKF/xL92+edyMCWnJ+kefU4wMlvcjOP7n5b2eNo7+JdCjuBr/2SMUt 1Z0ZY+B41kDApSQBYw+d2YUyR8AInhT4cuOuJGPmEg9nLqRUSjFwQHB5C3nDDrFU bwoOmBaJpi8OwjShKOpxY9ZtHrXwdTTCJHCavmOHGVjpWRzUeIoSmryDQyEX7Pyt 6nnv6r4HG89bFVMpTEeD/i4E02ayeG/WO/sskDYSCi6DN8ao5R7BaGRpozRBD29P tendtDhgRuXmkbuyp4Ipl82DSrQrWL1HpZwfCosz3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhi thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihhtshhtvghrsehpoh gsohigrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 564d0fcc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:27 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:36 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 14/21] repo-settings: split out declarations into a standalone header Message-ID: <0d7365c5190aabdf33990e36154d1807f199ed91.1725008898.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: While we 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 Fri Aug 30 09:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784769 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 EAD8D17A5B2 for ; Fri, 30 Aug 2024 09:09:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008984; cv=none; b=APG0iWocKCxG1xIWMZH29ivLIcn8SWtikUnlpKjGkb1BeiTs1xHI19ur+sUxlT3T9fK6a1kvR5RJ6FtX5z4OE7QUOOr9ysGDDeUQHNJEDGtsoTcuxokkni4pDGxnlAIMGA0XKpN+62fwAEdDGGUuY5ro7ZSUC0OfBSXE5SJGpyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008984; c=relaxed/simple; bh=3ORkFRBuyqXdandtYNYozwyVNu2Dw12MhAZRjPyW4eU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HWzMvx2nnicTSIq+F6WcejGXWVkEZ58e3vMeUVKEP+k0GviMJXne9RIpfu5Ed0EWmFczSbMf1hrZWjxeArN7W0CAofvuXJz3Px+op/5W/iWwvwmccpcfTYWqOUU1RvPVS+ajvSUUFuaMr+7+vfTUix8kEK4auIcc2DLRqsYpw0w= 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=BjVcshvX; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jGdFqC4S; arc=none smtp.client-ip=103.168.172.150 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="BjVcshvX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jGdFqC4S" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 5320D138024B; Fri, 30 Aug 2024 05:09:42 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008982; x=1725095382; bh=7Aphy95ykn Ym+jWCcE7WBSqseCmbbp062X5g/uxMJZ0=; b=BjVcshvX0VPA4AtpR5U5Tmxwaz hqD/59Jjg59g8G+8luhbD7lPmlPRC5MKqNxXs0G0xvxI06FDUpXyeYGFFym7sq4C HyMs/JL5c4ElvGMaCgry4gO+zNFpwAhKn6d9xkrjyxVgnxETCYoZG84CFyeTrMFg 5JXyPi2lpk3DxAjEdQUtvy5ESw5qRWxQL7t7cLGqK6Mn0lCIuENmORrtWzVc1BDw TxFIxgq6usdI44DKO88ZkozNX8lJrOO+6l+H3L7CWo6c8kBFc3riI5ZvENCmme0+ Da6snL+Y4dQ7q1d37EVFebqSC1RSy/mtT0RVUnAIbbtKHQlp7cjxfIMxshxQ== 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=1725008982; x=1725095382; bh=7Aphy95yknYm+jWCcE7WBSqseCmb bp062X5g/uxMJZ0=; b=jGdFqC4SbPytkYOPMFA29FlBbCWmDTKCfSqVIuZvErP2 yDzwFuMSjljddA3/T3r6ytRbIKm/MpxAMgfzSvcMg3jOhrQWilgqT8/K/xWhQ72z WCGYMs/Hzv904BNnqI/vC7WFP3+pxqOJTnw2uHrEYwY4S2szz/yvJxlE+12G2EEc u0D7CVTaO7O30gum9rK6iSh24Z3RCBX3vyUg/2+FBPG03CcQve1WvEXHCVooLSvi KF3C0T07uv7z2egTRflirDgSEftS24w7g8o/ys87yHTAmhzguGP/Cpfg328Wi+Lg L/l3hK1GVdOiQO+tX08LpTQK0oS68d2aFToo2pcNwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:41 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 3a439cee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:30 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 15/21] repo-settings: track defaults close to `struct repo_settings` Message-ID: <231c52ce82f8339f4e27b59bdc76e402572e91f8.1725008898.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 Fri Aug 30 09:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784770 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 655B816F0DF for ; Fri, 30 Aug 2024 09:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008986; cv=none; b=KOrUviOk9ZQ0omcaQrFGoN6Q7L6U1829GRrlF09ICLPE7QhwZe54QSXvGqIZRxnrZNuAyVNyrI/W+VmMKXbYddmqHRNCk0y4P36qQBwRM6Z4T9jm5w57JIz4mT3jH2dmL2BZeps7+zZsUKpFqEXvQeqFbe3FyePrmza79IoUqSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008986; c=relaxed/simple; bh=8eOG7V/j8a9xbiofvwfUgM8epzyfufMLuIRGC8lIKts=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i6Nl1kFqPtGQlMxp/5f556ZGTjQc2i4PE6YJuc7lJlFxX0eSiIn410U7yKArLxY68e47BM/eu6BiDGHeMnfF3qECB3d6GCF9ulWOzVvkQwABqqwym5mUM3pB3K8cf/bZ6fm0y5TvAiH3xeY38jK23T0ReWFKliO7/W27LMwVH5g= 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=K7jscsT2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mZbifFDg; arc=none smtp.client-ip=103.168.172.154 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="K7jscsT2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mZbifFDg" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 91B401140240; Fri, 30 Aug 2024 05:09:44 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008984; x=1725095384; bh=JTYkqay8tG Kra5vGqEltXTgHjzaFkvjI4FmWTrbSPgE=; b=K7jscsT2qkYWnXgXeGsWoXrncA H5JChDJgwq35k/jJIAo7XALFk1E6QijFBrnLpGa8KjfChB4shjLDlEV0BZ25MRAP U5eTXpcxDp0j8H7r5VCGk+wVCg9FBMyCtcb3+kZUaZf8nYwl9QSBRmQJEn4B4H5B 94c6RynvYTlrYuu2nf3hnDr4Zj6eExw8Tq+euG+ylBe9Sh8S6+hzQKnlG/3AzfUU wAVP8R31iZqiCETKRQgaArLz2kgULYnpr2NYATJL6rU0K3NJpv6GtcCowHUWpGUj vQT6uddUrcAJyxBwUt6ZaW5y8RLPWiI1TRc3K7/caL1h4Py0/C6m85uaq6iw== 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=1725008984; x=1725095384; bh=JTYkqay8tGKra5vGqEltXTgHjzaF kvjI4FmWTrbSPgE=; b=mZbifFDg0iS30LOjVNxHNw2gkDrKSynvmRN5QBZMijfT OV9kAUXx0SJmArhFg/f3m/8xKG1EQAemFSdTmMpU1/hG6tv2ubu8abA1ipGPMzAl FfSzNccmUCvlZ3zegSctde3qg2sLrd5bb/+8TgA8z/1UKBMep1lBqb+5kXzdxydR AjkIwhywBY/h8+ryDZYzd6hPlf7v7SZidGM/s1S21dRMIk9YLoeipHBjF3AzRZ/g wHY7Sie0VhsoTyqtjqQp5Pcrob5ubytkGcVR5ZeyziFrXYKFTpuqp67ArqR4UU2E NCXQijdA2agkEQTs32hFls1JAC+8fqbWu2b75OKakw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegtrghlvhhi nhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fbc8a45f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:33 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 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, which has the same effect. 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 Fri Aug 30 09:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784771 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 9667416F0DF for ; Fri, 30 Aug 2024 09:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008990; cv=none; b=aqo6JfOSWwRxEZO0YtEA9Zc3L1ppdIH3znS2fO4cPMZDJfcn3xNHfa+Pf7cQ3UkH5DC9iuLraHjZn5pzBnuC1/w6w6GlZQx088/B5WGBijUeWCzK4bU7oRoFdlIJKGquclpg6N3c+PVX39SdGUyxcUM4xVV3UYEC28OR6ABx/40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008990; c=relaxed/simple; bh=fSUnCJWataJWqrnhhlGDppGgbRQS2LhbUZ/v9fw3Fh0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cTHCP1kVwegSnZijMijueScbh8iCT1cLyOPpOtQmoEK6xu9n/BziIl8Pzb0zT8bp7eColLMQbhohAK6HV+osXQNYgn1x42j7LtK+juyeS7V+F9Q0VXMexDzWWm5UL+ipvoOWpTad75YkQgD/7whRSu/uufQpsY9K3o6J6x14H48= 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=JOpRYy/i; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PJrqlDyW; arc=none smtp.client-ip=103.168.172.154 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="JOpRYy/i"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PJrqlDyW" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D0ABF114022E; Fri, 30 Aug 2024 05:09:47 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008987; x=1725095387; bh=icPTQm46xs AVzTUWR+VyLDfzy1G4ON/xcomPtpmKYc8=; b=JOpRYy/iWLP42EwunpzZi6nyB5 Ey1zq6GTxCnPFnOtMpt/yl6H6eZE0ZSRZX8WME8pDbVs1JIBnYYnxKblfB+oy03+ GmySOWNzSgsyaVLHs2LUeTwL7Xmeqlj1mj2cqI/26vqGq4jwG7cAkBt2dhfuFvBm JxBkwfnzE01VK9W+8omTj+LddI4UFSzDtd0B+1QoKYs+3iIWulabBSBMBGelKrdu Um4RrTdt0BUsHLoZH78HBAnbEbp4MQpilFZBSJLZysGV2pE/auURt5GXKFui622+ VoiDJYs3l+EbF2dPlQJuSlnd6/AWWuNHALnVRlY3H/djAIP7ZwVIihX/CqPg== 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=1725008987; x=1725095387; bh=icPTQm46xsAVzTUWR+VyLDfzy1G4 ON/xcomPtpmKYc8=; b=PJrqlDyWWFaSVxrXX9CaRs5d3SGrTQrmW26aQwXDYlDC vh1mMnFCqjFoJm1JNRrAMZjBw+Y9Y3xpFsqTE5eyOjXiJZzinX3fVj9sjdVXT1z5 YLy+UwOxiVyj56VdaeX/FqlRVreK9a9wn2jXZd5gAKw9oz1lP32fe3RrO3ujbwvo hu2gOTZs3uro3+urK4UnHjGgySEHoKsMcpbvW0riaMIj+82JB55OUhR+lHLQ5wMY 0khU2lzp5HH0cegM2CdV8LcxSP0jzv0WHyrwFZNqvCHchyYtwYw5Sw6sfilB9xbV knKn/JfwyV3dFH51JYcv/DWmsyPM+Hz8MZboRelVCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhi thhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrh hnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b44855a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:35 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 17/21] refs: stop modifying global `log_all_ref_updates` variable Message-ID: <9cc8518a02d6bacfc11caa30c37f6bffaad69cfe.1725008898.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 Fri Aug 30 09:09:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784772 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 C536016F0DF for ; Fri, 30 Aug 2024 09:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008997; cv=none; b=lozhcFuVX/MokETgJUBT1u6JSxHd0FdmhzN7ZPu5dTRqFpbflwReXcPrt4ngJxn/RDZdbX+WsZNPNeFkgTVBtD+CiKmpch7fTFjQ/u1+P7v40tQv5LJOWO6yfBdpg6VuG6OQplI+dNPJ4i9Dmcy7ZnMA7iO3Sy6bZFsy4VlLICc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725008997; c=relaxed/simple; bh=9pfP4dcviIUTLnfk7IWbUtC9fvIm7q+MxrO3ZCKDzwQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TVsrSuFaLBmfGDrYUa19nxcPPOT+aZGqdri0STaSklytXVCk0yW75AsvoJLEFCodheFBd237Q0NdPLqddzh7FHWZBH4+oyBEvT6Cz2j01mdCHrxhuYzYHNIxpTBLfEvUZ2uM1beYx6K1PdRVxz94zQUjvKXzFk+rx9QlpfproHk= 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=rtlABMMh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dY4EMz4q; arc=none smtp.client-ip=103.168.172.150 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="rtlABMMh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dY4EMz4q" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 2CAA01380278; Fri, 30 Aug 2024 05:09:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 30 Aug 2024 05:09:55 -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=1725008995; x=1725095395; bh=CdZY+u5+q7 F4CgYABKCWSrAOvKXeGRglmGfFH9B1LmM=; b=rtlABMMhqz7BGfVhwzy/jsN2lO TKdwJhPkWLN1hmkhLcjZIpESmvkiUI68ZrsC+1j1jccZbbFsQyjLqZzR/Ls2806E iogHRbzCNCe1PxnPWlRd/nS/r96obrznfTU6PkRgVeBJzvGzzvW0TGF5zxTTHKdQ mPEBifi+G5TzziuT7FgU7l9d/3nEY+r/y10J/jQ7K4UyEraO3zNnFx9lwKohPm2m ve2ULwZyLP1wc3kA0vbGLz/ZU1WBDMsN+DzB8EE9ikorgweMzhysffR1srtshHcz 8t2jEXyZs0Ry9OkB8oj5C8P3WC3u06p72TC9gN8woOrWH9zesmptLMoJpvPg== 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=1725008995; x=1725095395; bh=CdZY+u5+q7F4CgYABKCWSrAOvKXe GRglmGfFH9B1LmM=; b=dY4EMz4qrXT7KOfzu8ohoBETwwo5WiRHICQdf9YmV9ub 72GtUMwD1PLHaSR+NeGsX/YNcNtOG66Bur+xk0KQB3fm4oCAODUVXGXyTIcmYITt 1D+/m+8cJ3fNaqd9rtkHcrZhlJnGHzzGPaJLp1CFSGuytDfaXLVJ5/ldFVW8WQ6P hU7ObaIelV1qGyJbosS56toermon/mEn5V50W0W1OWmVtmpZpJKa6PvBULT7x9qD 4yx4+ZzHMrxjSJYtFPSE/uiy1tjcHwAPwbjGX9TvghOen8JwriexQfw61qHq8pp5 4yMjs2aZnp+MNnWT//mN6h/0YMWCCyqWbvCgIdV7xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhv ihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 876554ac (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:43 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:50 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 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 Fri Aug 30 09:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784773 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 1643F17556C for ; Fri, 30 Aug 2024 09:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009000; cv=none; b=XhYsd18vJrmAqlEQVmW8Vw2EqJbHeUqpegiawnfrTXelclOuua1s9zTlwF+2EQaSlqL54xo5AvY7SuADc9VbxDCMp/O3jmDgIOf2zbsHIJ4vwDqEk+Ibf3pv8pzKKVl5GfOD20UjPfB2NBceAMpAJEHmnqDzFMz7sTP/lUuupHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009000; c=relaxed/simple; bh=/6suZb2unyRBj5SKgV/YNumGzC9362n/HWHt5VyUHqU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GrM8rOEWgj79vHbMWxAVTw8JHNNHPLoRB90twUiyLbdgT21Wff9K/ZPiksABU1+XKHVjceTFux0eaRxy1ZIaZ863V7ttQPwjQCIy9u9v8phMfGRb8TOk3xWqv/jCQGyjw1vFhKb3nhaBr+xgTtFJOgwwjUUR+bIL2GtlzzSFztI= 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=WfORKgX8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QMap5+VV; arc=none smtp.client-ip=103.168.172.150 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="WfORKgX8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QMap5+VV" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 76DFB1380278; Fri, 30 Aug 2024 05:09:58 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 30 Aug 2024 05:09: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=1725008998; x=1725095398; bh=dkQw+5FupR dKNKdyjK4XvrtwJVMJn3ONy0iDDli7EwA=; b=WfORKgX8qj+Q8AuaNyciXGL8o4 cQ8TEk6SHS1wO9HSKqvQgOG2JdnypOFy+Df9e08mATr/1TOqshOpv5RYdJFmRt/P 2ESqm42S3uYzdRgtXbXs+riyv2vnpLaKqdvhy6JFselAJwbLP1r7oPTKULGwnG/i /wvrYzHi7Cvi8/eZ2yKi0l0TD61yVXsWbCnLsPXVxWaxMFTncghAmEnrfuJCMyG6 eqfLXOMYNdjbfTRrktGsvxBgCV0BWDHuRKhS4SoMhAwUefNf9ya6kUBv6/LiMwG7 bfvrXjbMA+zrchIW6rCb4u1STc0+Xp+8BUcrfjpFXJpjtAmPnjvDLHjI9CNQ== 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=1725008998; x=1725095398; bh=dkQw+5FupRdKNKdyjK4XvrtwJVMJ n3ONy0iDDli7EwA=; b=QMap5+VV1UUjJMdHmlPgUVfXrBThhGFwJfgRsiSLd1RP NOpnaZBn4Ot7HptaK4xnAEWQV+usY4PCPBlWXUSGYCg1q60OpI4GTl4jlFXY7IHO va1H36dL2sUqBjDiZVpDZ3SkUElxus7k61reb2Wro3fK3oNkLmjbL/OCGvzAZtU/ OcXBlYx0zGHQ1hHMpq5HkpfRFBvnxxzQuBnzF1X62P4DqTqBoULga0Suk8uvP/Qt sJGMn8i6XMJvJ6e5YB6zRCm2MK3YTiVzvHVKDRKgnr42bkJCWvaksbNq2SOOijDr jdCa65v+RW5gM6M8BB6PMWKW2RYAY5c4QVxdg2uBDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihht shhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhooh hglhgvrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:57 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ec2dda2d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:46 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:55 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 19/21] environment: stop storing "core.preferSymlinkRefs" globally Message-ID: <194d858877f9954059800e9a9b698e8c04447946.1725008898.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 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 Fri Aug 30 09:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784774 Received: from fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 7BE00175D30 for ; Fri, 30 Aug 2024 09:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009003; cv=none; b=E8JDQ8HxIQuMEKE9MSfpDTti2RNVXyAyDGrg0QlQLqsNm/0h4fXIYVp8WbuWn65OcxXfcAnjy0JYSKxykxUWgYPD66k0Mi19YXOhu2HycpLGEnlgnXEgu9U9P4hMygATJ1DCVrQmA4/cnsTAH6rOGmL/awqsfLM4ZoYRmvM8PBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009003; c=relaxed/simple; bh=Iu3vDPgNXAZDAIcgXXU9Ke5jUY1p9Ytsn2EzS5cGhxE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Shwm0dSzsXhNlOi4ElVlLSK0Chkf4RNBUKvNzkos3FPHPhln44LJgiEd/7dOW9qbGP6J/0Zcz54MC/5r2j0cnLUlb1OGeCGN/SDEF9lc/6o4mBTGajoHKsAn3V08ryI+QKCk3KRA5E/72+NZiUgWSasIv7Pp1OzkSVg5gnLny6I= 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=qAEWl/UI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NsIdeeFv; arc=none smtp.client-ip=103.168.172.154 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="qAEWl/UI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NsIdeeFv" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C8A681140229; Fri, 30 Aug 2024 05:10:00 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 30 Aug 2024 05:10: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=1725009000; x=1725095400; bh=P3Tz/e7OIr UM3+si6TKcKwZZaFdVeqDfPakrWKeU4PM=; b=qAEWl/UIlq6tiGYvY2xgJsepSx 6aOCsaVX81vjosCb38tVNlDBoTsZo1l0ZcSfQmlokXa4HCfzGwCkso8ELlmq546T 5RoKSoJZps+5gdZZ2uJlLu3hzGRK4uhMHu6HWjtDqdwxuf+8Dx9rif2NrG2sIiVa SfWHsWmBZq+f5sS4cDzhBf+zbRC45ThHGnHMqj4N8M5yv42BFVMisr0ouWy/0bp8 Bh/I/Ld4rav8873dwLJnRKMgzbQzaeVzyKdRDw3RjyUAh56yvB0UYQ4dfEK0CWuv aoBVwGx0LxlZOY5FYOwU8vHZFqHLozvRUV1gLpbPqoDicSygEHdlCrsE8JXw== 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=1725009000; x=1725095400; bh=P3Tz/e7OIrUM3+si6TKcKwZZaFdV eqDfPakrWKeU4PM=; b=NsIdeeFvoA8CwTAM8DDLMqI2lTLJWCks35bgYX6s0puc qqat81KeobNPhEP2eJUfWv/n2XEjyvnOklutBRk6yAPpsu61GxNrMSTTrf9apjAQ Fao1ROodzO8sCdBMLZFxe92JV095HmJZpy/ED6zsHjAPD+nKRyuC68Yco/gFCbQa 9/KbH3jvQvCK53DnJLlGio3azw5v22V6msjKpEL5N6BCR+hnY7lhmBtwhZf0FRB8 BffAXjG1MYNPUdKuez3wN13UqzV9PXOOnCgGqIfBhoBpSqBj75Mrmh1ALyT8VaTY xcqcbUfq/pj10Y677tgm9/sVof3QX+wIh8KQsKzXWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepudeffeetteekudekffevudefgfelhefgteffhfdvveff keevleevjeejfefgfeeinecuffhomhgrihhnpeifrghrnhgrmhgsihhguhhouhhsrhgvfh hsrdhinhhtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep tggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhithhsthgvrh esphhosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdho rhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:09:59 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 25444885 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:49 +0000 (UTC) Date: Fri, 30 Aug 2024 11:09:58 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 20/21] environment: stop storing "core.warnAmbiguousRefs" 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 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 Fri Aug 30 09:10:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13784775 Received: from fout7-smtp.messagingengine.com (fout7-smtp.messagingengine.com [103.168.172.150]) (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 DDFE0175D4F for ; Fri, 30 Aug 2024 09:10:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009005; cv=none; b=mfH5Q6NkjB94HTS+sYdsHbPMPv0dYerqA8Xm1/iURSqwjYiBt/YV5iL90bmHASFinJOmdL3oJmc72GzjWr+8IUNWnB2DYY0fCxwm7MGo+0I7KOjO08PFQVS2vVxZ5N2mKrQTBxSad9vT4uK8rx+1goPV6cgiIFuTLob1W0GU6tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725009005; c=relaxed/simple; bh=U9J5P0oCJzY32aGIm9ibRn0px/mBMJPwQUTois44z6s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oIas3GUwomyxZizQGIZ60Eggy2Cuec9VfxFrwvybwE1hX7NQ7b79jA/ZV4kUD+yTj54AXhfPixA4+sniR3M0uyKgZTwwjdcc+WD4gim14DphOLyKRLQcA33J8Ot21efk5tx8/oZWe7rSr9nSGz/TiGSsgebhNv3r0gk9deGsTQw= 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=ZLHZ3dGx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iUvMm/bS; arc=none smtp.client-ip=103.168.172.150 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="ZLHZ3dGx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iUvMm/bS" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 208CA1380277; Fri, 30 Aug 2024 05:10:03 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 30 Aug 2024 05:10: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=1725009003; x=1725095403; bh=5yq6q6JNiw d4+YshgH/avjb7HWZjW0RZYeknNET2kqE=; b=ZLHZ3dGxc9UmBK8JP7pLvq5tMp 4l1WziSoe/V+3TrvFBYHKLLej3/25qkcZZoIegosFwe/8EjK9zCpTmkCxFdro4yU LgI9gWRPDdL6LGaB6WpX41Kce6RxKdyUSKh+uex+TcbWeOuokykiid2Va/y1eldU g/dxsjvGNHtmQo6e2PcTb0gQXvOml/DFAy060lSIKA1EBnSsVBVymJ7S+BgRzTr0 gyRV+inoqDEhxw5Y3U47wtgFqv20SDsgfQZ7jrU3jjKf18Z+whb/FY+pM+V75iKo bSuCS6IWOZ6brjUBdrpLXlB0ewIm6w0KfJ/zU78OSo2xRuH8J2/Se+Va9Fhw== 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=1725009003; x=1725095403; bh=5yq6q6JNiwd4+YshgH/avjb7HWZj W0RZYeknNET2kqE=; b=iUvMm/bSO4m4gBu67tYSemLOneOKf1HelUTyR/1oNwZD yMcEDcDAtGBlIVVE8f1dP+Qt67zksIbR8FIqCtDWUOUTB08o7y9Hp7pJs6aZJXj0 X/Vjg8k1l1YLZ+yGyJX4DDYm05e64PC9nHK+frOVGEomgMucaXUO4GJrjV6pcaDi /NxVVzat98rBvCttOta6hJyAjtT8mjordK3yBgahyXzrE8vvt67MY+CuWCYr8Mqh bJHT6hmI7mL6kUCBSh7Do10ZMwZGqN1Tj8i8z7fpmqhPJUoDDmOsQ5jXABNHNlRv LOfc65U4Hk2sQq7eB6SYyi58mzFJ0nSEuinyj7DhHg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtph htthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomhdprhgtphhtthhopehgihht sehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmh grihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 30 Aug 2024 05:10:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bc156321 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 30 Aug 2024 09:09:51 +0000 (UTC) Date: Fri, 30 Aug 2024 11:10:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan , Justin Tobler , Junio C Hamano Subject: [PATCH v2 21/21] environment: stop storing "core.notesRef" 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: 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