From patchwork Thu Aug 29 09:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782870 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9743C18C347 for ; Thu, 29 Aug 2024 09:38:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924308; cv=none; b=NYAa6psvI8WqKQgsN2Q9XMa694gS9J9KNtMlUPH+5PITL1kK/ShZaWX0XZa5tfF0aHqFoVNQ85gcKxG1FA5iu7Qc5L+TSMJtlaq4AWwt6cqMRlTLBS/ZmWQ7Ycw+ca0gq8u6q1nzNCA4hm5nrP4WtZDmKux/yOvV2MDBKp/4mJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924308; c=relaxed/simple; bh=XLNWRAc5tbEsgVhtOZVSFf/ScF1d8CzqiMR9pSA4qyA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ewR0PqA6XUw7lCFkqGyIB7VHML3eplcNCMFblKMSsbmlAHQnd18XGAKUNli4S1ugafRaWsy3SVIWGacG/4AuoMfeC6zr5Jmp82jRFL+eTiVmQXdo5pURrZrTjXbkdIhLLZBbtDckHQJQ8PCgzDUYZHPk0SdLC7VnALqN8UbB+G4= 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=iEg8wTo2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=YvRnu69i; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="iEg8wTo2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="YvRnu69i" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BD6A41151CA6; Thu, 29 Aug 2024 05:38:24 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 29 Aug 2024 05:38:24 -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=1724924304; x=1725010704; bh=yuv4dqsRDo 3T3dt+LBkW8KisRbylQwe3zqsWZcfWPd0=; b=iEg8wTo2qMene15cLQTDPTnSGE VeA/2yBXAgwTSYu2Lc9GSx+MZT4JuJeA6nX73HGhTf16Q8I4Bc1Vur/bZn/IY8zF FeYGWxTC2wM9zT/eaFrROpPAGJ+p2on3Iqrrb8RDy+5BrOuGFmMJfVC9kvRXgWJQ casmqgXMGpGyMojmdp4SitvVCLumtrvzd6rNhkHYluxXI0OlZQZKrFeVhmofn7fg VS5IAOa/MDd+RlqzsnOY2KEF9RtKo/sA7dBxypWdg0pnGFUp+mLW8+Ddk0hR1fAd u00eYMPZe4FyJwfiz1S5huyLyOwtkR8lMMdhYbeLQ0BKGQ6CXC6ifFkA/cKw== 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=1724924304; x=1725010704; bh=yuv4dqsRDo3T3dt+LBkW8KisRbyl Qwe3zqsWZcfWPd0=; b=YvRnu69iqdpo0NBsHrICucMVAP9bO90iULtJJQB0Otxx dZsYZi+IDh5QMmBwxk7c6O+CiFrMK+oy64/KfZxBRrowbDeKFxPCiGFjY7c6dMeB eI0DkXcQkw6FftC4umcErKYtxBr7RBXi7IrmFB/rXV214dYLPVFc3WfDeMWSvwmE mP/RN4SnYXocy2IYGcpYsWxB8iwRdwg+XVvw1w1JYPcH3gR1/PCdmXtT2Gn1Y0tJ 5RhvDlkvfRwszKadMuuTo4BkVR2Fwfo0gZw/tgvPoc+vdw0X0Md4G0wCeOsvU4ll S+BevY2WeuarIWfMMwSazQpsQJtF5wqXgs40er4aRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepieduieeitdehieeutdejudehkedvgfejudefgfeiuefg jeekudegfefgffeftdehnecuffhomhgrihhnpehgnhhurdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgs pghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheptggrlhhvih hnfigrnhesghhoohhglhgvrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghr nhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:23 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 791947e7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:15 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 01/21] environment: make `get_git_dir()` accept a repository Message-ID: <0fe3e3e1cccf2eae7d81ccecf431da623b39fa79.1724923648.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_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 | 2 +- builtin/am.c | 5 +++-- builtin/commit.c | 6 +++--- builtin/config.c | 2 +- builtin/difftool.c | 4 ++-- builtin/fsmonitor--daemon.c | 3 ++- builtin/merge.c | 3 ++- builtin/stash.c | 2 +- cache-tree.c | 3 ++- config.c | 4 +++- environment.c | 10 ++-------- environment.h | 1 - pathspec.c | 2 +- read-cache.c | 5 +++-- repository.c | 7 +++++++ repository.h | 2 ++ setup.c | 12 ++++++------ setup.h | 2 +- trace.c | 4 +++- transport-helper.c | 2 +- worktree.c | 4 ++-- 21 files changed, 48 insertions(+), 37 deletions(-) diff --git a/apply.c b/apply.c index 6e1060a952c..19fbb8fb93f 100644 --- a/apply.c +++ b/apply.c @@ -4111,7 +4111,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..55124ee28f0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -407,7 +407,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 +534,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 +1072,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..da9315e84d4 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -214,7 +214,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 +737,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..6c22912b63c 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -855,7 +855,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..ed56299098e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -642,7 +642,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..4e7ef7a7656 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -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..c5794fbf2c9 100644 --- a/read-cache.c +++ b/read-cache.c @@ -3238,10 +3238,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..988b494a954 100644 --- a/trace.c +++ b/trace.c @@ -21,6 +21,8 @@ * along with this program; if not, see . */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "environment.h" @@ -311,7 +313,7 @@ void trace_repo_setup(void) if (!startup_info->prefix) prefix = "(null)"; - trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(get_git_dir())); + trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository))); trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir())); trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree)); trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd)); diff --git a/transport-helper.c b/transport-helper.c index 09b3560ffdc..abe16eea651 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -143,7 +143,7 @@ static struct child_process *get_helper(struct transport *transport) if (have_git_dir()) strvec_pushf(&helper->env, "%s=%s", - GIT_DIR_ENVIRONMENT, get_git_dir()); + GIT_DIR_ENVIRONMENT, repo_get_git_dir(the_repository)); helper->trace2_child_class = helper->args.v[0]; /* "remote-" */ diff --git a/worktree.c b/worktree.c index 30a947426ee..11335c5d9a3 100644 --- a/worktree.c +++ b/worktree.c @@ -57,7 +57,7 @@ static void add_head_info(struct worktree *wt) static int is_current_worktree(struct worktree *wt) { - char *git_dir = absolute_pathdup(get_git_dir()); + char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository)); const char *wt_git_dir = get_worktree_git_dir(wt); int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir)); free(git_dir); @@ -171,7 +171,7 @@ struct worktree **get_worktrees(void) const char *get_worktree_git_dir(const struct worktree *wt) { if (!wt) - return get_git_dir(); + return repo_get_git_dir(the_repository); else if (!wt->id) return get_git_common_dir(); else From patchwork Thu Aug 29 09:38: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: 13782871 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF0AF18DF73 for ; Thu, 29 Aug 2024 09:38:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924315; cv=none; b=VR2eIO6eII39k9JDMzG2xTaoIHfZn9bCuWGuj84grH5FfeMOzfJIh+RyVVv3pu/xP+05O+M+Ff6ekbpJyn0t/rzvvCPsI72l72WNG3RPwvOMX1EQAlyRNMNvJPZ8vU7GGmAPhhDY5bYhv57a/eLumFWxabu7GJxDzMHuMy1tOZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924315; c=relaxed/simple; bh=qahYXYII+jZVavNixo7RM9/6p9OzUFUxcg7LxlbXBnI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZimEddmq/CQVD4QjGlw7HWFKZvCJfQxQxYsR4Sf86GC0Az9xNXp6ZlQ0NavDSpRC1zu1+ySxaWnOB+8MNkNjeyAeCDuVMmVyoHTgHQFib1IjmFclJCGjT8oLeBkgOV0mMKG6kyoB9glNQ0TMVCBxgU3KMar69R9a5GhSxkbEpvQ= 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=N8gpQtfp; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PzIe979U; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="N8gpQtfp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PzIe979U" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C487E1151CA6; Thu, 29 Aug 2024 05:38:32 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Thu, 29 Aug 2024 05:38:32 -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=1724924312; x=1725010712; bh=AGYK57YO5a d7Rt2Wd7jwT+5niVTVTXnkVO6SBdpXWqg=; b=N8gpQtfpNoWw/5B3+KRAdcdKnY PkFIpyNzeiJwazMzB483MhLwUScm8eeCJoKIWz8MAT0wVK/sYYjHC2oDlBbGIHFy yxs6z/HdU7n2Yw54ZnKcK2GnOdr8lRLhM85DOpTosK+lytgtQXVeFG4pO1Pvw3jq 6gM3EowqzKGhd1kIH8cOQHlFxWSD/gU2Ez8IWN1fbwDFExluTYS588LLk9WJtyT8 Fkfx6n3XHuIXbHz8wUphwcvWLe9L5TeLIMxFhmAUkVq8EXL8FNjTZWa3WX5cbACB Xtjn99n70Bp0p8KXchC1DsygVcOQEs5WcFz3NYOj/xaEDtYQFFj46Sas6gfw== 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=1724924312; x=1725010712; bh=AGYK57YO5ad7Rt2Wd7jwT+5niVTV TXnkVO6SBdpXWqg=; b=PzIe979U8RH/1lPFE1ZSqW2eDCjIi4S21ZZRkaXo3CR2 jxOV0/nTaw0AvahmChTxeVrjFInM1eZGhEKG6iZWHQx157cYMPHQEFZklbDu9SYf PHKRe3tfgl0TyKZ076RToZ7g06+IQeOwclX4gC+FIhqzB1n7OfSVWYXHWhM8JF0d 34xEAckxXHE/idonLUoNuv2M19kzmowLhXsBzAtGGGdmrfBQmLDQLdzIm9xq5JCc SFrtdJMSE2Y5bD5pgkLsfFy4FsZcoUydnkRIuYVkN/j4IpSkO/7AmpVSt1EplR9k Y9PbkWynnGTt7+nlzlVPxWRv1fQ6b2ExqUVFYgSaKQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:31 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eae01172 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:23 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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 | 2 +- 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, 21 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..4308a2a8549 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -1042,7 +1042,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 988b494a954..2d9ae1c1525 100644 --- a/trace.c +++ b/trace.c @@ -314,7 +314,7 @@ void trace_repo_setup(void) prefix = "(null)"; trace_printf_key(&trace_setup_key, "setup: git_dir: %s\n", quote_crnl(repo_get_git_dir(the_repository))); - trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(get_git_common_dir())); + trace_printf_key(&trace_setup_key, "setup: git_common_dir: %s\n", quote_crnl(repo_get_common_dir(the_repository))); trace_printf_key(&trace_setup_key, "setup: worktree: %s\n", quote_crnl(git_work_tree)); trace_printf_key(&trace_setup_key, "setup: cwd: %s\n", quote_crnl(cwd)); trace_printf_key(&trace_setup_key, "setup: prefix: %s\n", quote_crnl(prefix)); diff --git a/worktree.c b/worktree.c index 11335c5d9a3..0f032ccedff 100644 --- a/worktree.c +++ b/worktree.c @@ -72,7 +72,7 @@ static struct worktree *get_main_worktree(int skip_reading_head) struct worktree *worktree = NULL; struct strbuf worktree_path = STRBUF_INIT; - strbuf_add_real_path(&worktree_path, get_git_common_dir()); + strbuf_add_real_path(&worktree_path, repo_get_common_dir(the_repository)); strbuf_strip_suffix(&worktree_path, "/.git"); CALLOC_ARRAY(worktree, 1); @@ -143,7 +143,7 @@ static struct worktree **get_worktrees_internal(int skip_reading_head) list[counter++] = get_main_worktree(skip_reading_head); - strbuf_addf(&path, "%s/worktrees", get_git_common_dir()); + strbuf_addf(&path, "%s/worktrees", repo_get_common_dir(the_repository)); dir = opendir(path.buf); strbuf_release(&path); if (dir) { @@ -173,7 +173,7 @@ const char *get_worktree_git_dir(const struct worktree *wt) if (!wt) return repo_get_git_dir(the_repository); else if (!wt->id) - return get_git_common_dir(); + return repo_get_common_dir(the_repository); else return git_common_path("worktrees/%s", wt->id); } @@ -626,7 +626,7 @@ static int is_main_worktree_path(const char *path) strbuf_add_real_path(&target, path); strbuf_strip_suffix(&target, "/.git"); - strbuf_add_real_path(&maindir, get_git_common_dir()); + strbuf_add_real_path(&maindir, repo_get_common_dir(the_repository)); strbuf_strip_suffix(&maindir, "/.git"); cmp = fspathcmp(maindir.buf, target.buf); From patchwork Thu Aug 29 09:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782872 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 CEC5A18DF8E for ; Thu, 29 Aug 2024 09:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924319; cv=none; b=aCI+zTZrp55gb/27oQqjghXvAuTq99VB88od4HDk97nsOhlwb/jIq1RAMu5GhsTUbVCJvPIfA0J/zSQ7dJfcr20orpB5JoANZHEIIduk5HjOxWSW+O9/vzbnXS8Pk2HcBmYPl0ot0r6w9WADXtU0xz47hfmE9jviAArLKjCf2G4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924319; c=relaxed/simple; bh=JAJOkwrVzWz/5/6v6q0wSaJygEgnanZC79jYsGhVboc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VorMwBaa5x/k9vhAtaXEJ3n9awXkUFhxighiPRaOEwyACedASR3RBWYLa/5hYcNj6nwkZtZJG3+eU4kIqgLqERQqpZ09mLbjuW7c0eOM+BM9UMjUJ9g6g/GS6Vnqbeq/q94cRgzJChz80vxsvyPqQhSMI9LZHavFsqrpQE6jmWs= 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=KEyV4b5J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O3V7VXlV; arc=none smtp.client-ip=103.168.172.144 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="KEyV4b5J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O3V7VXlV" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id E16BF13900F4; Thu, 29 Aug 2024 05:38:35 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 29 Aug 2024 05:38:35 -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=1724924315; x=1725010715; bh=TcQur1p8L8 bU3BkUjgyzGUNQjOl+/FFO3SXzc9sojc0=; b=KEyV4b5JULdqBbmrQgRUptbNjd ApQxvDNaf5DR+pkj/0bPZU8jHI9/Bzdn7L8Ha8diUGZzj3fe/Jtj+Hoke0TqwuOC lW5pkNh7DRNsrpMsvGxmT5xJh6UxqXYTU1jMlwC2/urp5tJnBLdz8KMgCKHuUUjK 00qGCC/Y0PuWbyuku03inqG4y5bu0h4X35WFFklIEeqopq5l3l6C6y90sTfAnrvB j7ngdSuy9bL1mmxlgIvCIm1O8PHoJHa4IYJhUseTgKrjqwZibfqGE17Quq59bwAd 4I8MlhJaeeYMI2LR6/GzgcIEPOo+wmc9aoMBt2CgNi0PxqRo2E8/NKenLP4A== 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=1724924315; x=1725010715; bh=TcQur1p8L8bU3BkUjgyzGUNQjOl+ /FFO3SXzc9sojc0=; b=O3V7VXlV/T1NvS8rCZrhquxdazoMwiomVku5e5bOG069 OO6VkCZovsk80wgN09EvY3jXGTKhZFI2ONN9l1D9oVNziLzbQuXP5W56jTBk4Eu8 mbQnrB6CVf4ix+Hty+UdSl/CM1YE1MHaDIp++Sn00nAHd9+53hGjDvS7dy0TEFnG owGVvHKkPNLPbvke+9HhyrV/46DGG+NmTf2q+5LkWW1V1mSiTzLNeQPxPywfxcZq 6Kd5nVbiWYt+EjL7EZSpzPsNb+nw7pJ4RtVYc48HGddK2lXCvU66m1BAoUcVcHqx bEZYrUx7KCJgLIIZoSMVltNPaP+lCVyUuYWONMYHRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:34 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 58aa4f52 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:26 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:33 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 03/21] environment: make `get_object_directory()` accept a repository Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `get_object_directory()` function retrieves the path to the object directory for `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/commit-graph.c | 4 ++-- builtin/count-objects.c | 2 +- builtin/multi-pack-index.c | 2 +- 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 | 2 +- packfile.c | 2 +- prune-packed.c | 4 +++- repository.c | 7 +++++++ repository.h | 1 + server-info.c | 3 ++- setup.c | 2 +- tmp-objdir.c | 7 ++++--- 20 files changed, 39 insertions(+), 34 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 7102ee90a00..d7ebdf5c0d8 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -95,7 +95,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 +275,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..bd99eeaa954 100644 --- a/builtin/count-objects.c +++ b/builtin/count-objects.c @@ -116,7 +116,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..0b82f7480da 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -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..6cd3f9ef4c6 100644 --- a/pack-write.c +++ b/pack-write.c @@ -473,7 +473,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..4418268207f 100644 --- a/prune-packed.c +++ b/prune-packed.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" @@ -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..ffca36f4675 100644 --- a/server-info.c +++ b/server-info.c @@ -342,7 +342,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..b648bf97992 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -132,7 +132,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 +153,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 +268,7 @@ int tmp_objdir_migrate(struct tmp_objdir *t) } strbuf_addbuf(&src, &t->path); - strbuf_addstr(&dst, get_object_directory()); + strbuf_addstr(&dst, repo_get_object_directory(the_repository)); ret = migrate_paths(&src, &dst); From patchwork Thu Aug 29 09:38:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782873 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 DE16918DF73 for ; Thu, 29 Aug 2024 09:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924320; cv=none; b=hCmkGFJ3oHQ/p3/GyB7m2mozw+5Pw2Tm8jvcqTNhOAs5oUWpzMKN5diZp7Plfai1aRTnf9oLcj2o+tf8USBuu+jt+cS2efyVmR43qRTgIERcJRxo00RfYiLRNY7+xjSAIQkdySdEcGst0uzb2izZh45ZGnqDlFWz49n0Ko41dQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924320; c=relaxed/simple; bh=ciuZzXiQ5NDAhMtdT7pScJmkwMDGUpi+HuRSNUQDrPM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JUSySC6XDt4xyhYJNyorl890INNS6VxOoy1lE2hQnNnMMOKjSjhYuJUzjnaRQDRlzgdmgDt58WM+1UjhL5+87cBId1L3kbP8Tj2T5HvdDQoQOlv6btKcsZAZEWq9EBMSKovn/EAG32XezwtSx3OOj6A17lNTYei1jVa5pqpov7s= 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=RN19REtN; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=lwEKWj7O; arc=none smtp.client-ip=103.168.172.144 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="RN19REtN"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="lwEKWj7O" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 0F31A1390140; Thu, 29 Aug 2024 05:38:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 29 Aug 2024 05:38:38 -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=1724924318; x=1725010718; bh=nCYlEAbemo uDSJTCplkGGNYdt9k0R4ufan2lGxVs5yU=; b=RN19REtN7I4gWTOVphEWvg1clC zFaqcRFPCDok5fTT8zxKhc+W6yusajsJmXyd08b5jTfnfbWtn4c+9jlOlxJPSaGl z7qPd906irEEdnFCL6g/438mHoqcGurizvTKJKS2dUsO0bnOkJSxK3u6KxSYWgub JTIlxngoEne0QKvYzJwsHrTzrcH9Yam+IEK0uE78xtKbwRhGRSMvh0eZhKJGtfP6 DGlsrlXXQD3/RkSbtVDFHjJLTUeA0HqZkomcboMSbTj1/zaLiUBk5KZ+wWOilH1l Im4sb3j1xM/EFx855nxafMbAxo3U/5qhBMIe0aSehl+g1RVmtiCQXoUL8Lbg== 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=1724924318; x=1725010718; bh=nCYlEAbemouDSJTCplkGGNYdt9k0 R4ufan2lGxVs5yU=; b=lwEKWj7OstrPiZXzW6UphMLctY0aujIREO/+r9No5iRO BKOpADe8XD8BQJ/YnXneqG1yZZtbaG6XGjzAYl374WNvKa7CoOBeOO9ftXrdf5oV WfbglNeWFjL+yxN8owo7svxvkC+cCbvYnlmt4jR2o0UepCXGcJ0K1ghAII7NpUzZ oQq2wojJYwUaCnkYxckuZ82LshFcu5c4jKUR12qcAZPUnIBvdArxG8US2anfHrHA +PBUzTQIXAC0OGaEgP589tdRCGXQbRZ2PDb7isYjO9BoypvvEvwUd5CiQZGMliwa ya+L6dgmU6YVKTOcqVy/38oa0nWzRcXgj6frOuSi6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e1436728 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:29 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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 | 3 ++- environment.c | 7 ------- environment.h | 1 - repository.c | 7 +++++++ repository.h | 1 + wt-status.c | 2 +- 11 files changed, 35 insertions(+), 28 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 55124ee28f0..dea1733c6f6 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -472,7 +472,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; } @@ -1873,8 +1873,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 6c22912b63c..80ea1d52eef 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -695,7 +695,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")); } @@ -757,7 +759,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, @@ -839,7 +841,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; @@ -879,8 +881,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) { @@ -888,7 +890,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 ed56299098e..ae42da02b97 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -539,8 +539,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) { @@ -565,7 +565,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(); @@ -1405,8 +1405,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) @@ -1904,7 +1904,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..a1b29737214 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -44,7 +44,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..b41db1451ba 100644 --- a/wt-status.c +++ b/wt-status.c @@ -152,7 +152,7 @@ void wt_status_prepare(struct repository *r, struct wt_status *s) "HEAD", 0, NULL, NULL); s->reference = "HEAD"; s->fp = stdout; - s->index_file = get_index_file(); + s->index_file = repo_get_index_file(the_repository); s->change.strdup_strings = 1; s->untracked.strdup_strings = 1; s->ignored.strdup_strings = 1; From patchwork Thu Aug 29 09:38:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782874 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E9B118E046 for ; Thu, 29 Aug 2024 09:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924323; cv=none; b=rDPxVbIzKK1ZagpCaFtPxbKHwniqQnrwNXcvxS6G7sqGsofSSqyBtkD5OzQN8plJOCtJ8AmYHbQGB6Qw6xgGHGiaSjQ6lWP9aAa6n9cAd5hdBgN+Tc2qnS5omHXBfkycYQr47GkWNhCoTM7vQyvJ9rhXwtBP5qAFjsGCjJwLoRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924323; c=relaxed/simple; bh=pyrxoOuTkUVhijtviBmzXXvxJfPTjTG1NwYCoXtpwzs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ki2o6w/RIB+Ge6LKUdjw8sNVtAdxo90fPXWXR0gGworovPkSJv+BuFO6n39GVM8XOPFdgcyRvif+0lehdW2OnK4/Fla+Tqkbhcv9duEOX8PUVKA9dJUMBcgziNWOUCKxbJeVSBp13oWjL+RMqcQ+JnNu7AM8wDYXbzOQC6iAjF8= 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=fhys5DzE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PMrJM0pE; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="fhys5DzE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PMrJM0pE" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 133181151C1D; Thu, 29 Aug 2024 05:38:41 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 29 Aug 2024 05:38:41 -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=1724924321; x=1725010721; bh=0KD1oH/pqh uqlkPaBbdj4g0ez0kH3Ebj+TAcCiojBJI=; b=fhys5DzE/JlOXH23L1oJHAG+x+ +OLVKhnnChHoH6/dTS5aEwGCEaxmW96cMdRmBgHp28ExQEGKypeZrwY8BOLyA3KK nTU2Ul/36ouF+8pVkj/RzTzAT3BKwbOP8YfJwosbq3esbCJbjUXDB8ZDVe52GPpg PnkT3XMkk6/9aTikxkrbJY3uDC3QSd00ddvzndIUiu+Bht9CEuEnILiQCUVqgfE3 F0EtjsrW/zxfcncLEO2HNcFSfQEhDaESKZk+vV8hFcQLUHneJ2UfkdQk9MCLPgYq SL+UdDu4GbNzKiQyQJAjC6Y92E4HrBrlfytF+ftCNdQKa3rAIsdn68vIqgWA== 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=1724924321; x=1725010721; bh=0KD1oH/pqhuqlkPaBbdj4g0ez0kH 3Ebj+TAcCiojBJI=; b=PMrJM0pEagg3MUpXCtErHIwm8nmX7HSkTsg1d/uFWshM HIy3SFvDyFpGvxmmeei+uj2rwyLMRiYs5nwu1nDPsG9trMoFvrxSrmA3Z/fCcYCU QEOOWSzmpQuaTP6UnFHxOmsCaymWxEWyozM4JUv12fNQ0qT3lHbvUOUCMsHDolHi CmKGpJBG1GDMJ+PbVITWC9MmSjNyXN/OAJ/uOXFrz0CPJl3PWOn8Nug81PDV4gwt Bj7UA/f41D9EGNQ7a54MiR3KiqXRZIdknGgt7E4QwKDm9srOVkx7J3YW2fijGV3w ENkK2SQiwq3wdu7G81a9srJdbBijAbMHT38rT5KcDg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 00784d8b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:31 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 05/21] environment: make `get_graft_file()` accept a repository Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `get_graft_file()` function retrieves the path to the graft file of `the_repository`. Make it accept a `struct repository` such that it can work on arbitrary repositories and make it part of the repository subsystem. This reduces our reliance on `the_repository` and clarifies scope. Signed-off-by: Patrick Steinhardt --- builtin/replace.c | 2 +- commit.c | 4 ++-- environment.c | 7 ------- environment.h | 2 -- repository.c | 7 +++++++ repository.h | 1 + 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/builtin/replace.c b/builtin/replace.c index 34cc4672bc1..04fbe580895 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -514,7 +514,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 Thu Aug 29 09:38:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782875 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E75F418E341 for ; Thu, 29 Aug 2024 09:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924327; cv=none; b=RvzRRKRAP+XrobrCyK1AN0nmzeH2pyRscUr1cJWI9QevyGxkZrENT+FehUON0Db4/NvFbY0bovu8J2v0iikachF8lIX/lVqrWsGd1KDLTPVJgkd1z2aSn2/B/E54mQ413OD3O4bVE/wMjFVJd0WS5g2hGBqhksOoQtMWprzLsYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924327; c=relaxed/simple; bh=arbiSBanJoSm/KZMSnKDTyeTJffbk2EK4C083YLZdt8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MnLG834hToTCSnEW4kWNF4h0fPnbQDOuUyELdFGYZVa7BUvVli08eYJFyY+Uk1Awa9/5EkxIGWQyVwJeBJ0XAx9ORByjNQZjDuD5PsPzTyRQX6ctTi2aRVbMMOnlDxR/nfMgkVoP4CYJSWhqDnU1/0wrVd4Igoo8oAv63OpM6NE= 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=rY3B3ILf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZzJz7QFW; arc=none smtp.client-ip=103.168.172.144 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="rY3B3ILf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZzJz7QFW" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 07CDD1390140; Thu, 29 Aug 2024 05:38:44 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 29 Aug 2024 05:38: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=1724924324; x=1725010724; bh=9XmY1xeDnb KPYTcbeywNYPz7FP32soIeJ9RndrWmoR0=; b=rY3B3ILfde9sDCFK0aalAwVLwM A0St31YKLwD2v53v+ST3p/VobAYsXzuIhbkvJwDntzVNwnKBUZ4jUf36GiSwQ9th 04Vt+zsoU7+7Vi+QH5NOyYptMZYZy1IMclZrUTtrozowl6Im4Yz4nS8Irs8ulXrS 55CY4ZNBUqcUDO77iIWsYxQLcsGXJ71ceWlhUxhp7FKEOYv29ngO9GNGqsOM1oZo 1Mt+Mq6qDi0lZNn8r0XkjIzOHuzkDjqBKdgnJinYpEdcGCOJ2ckdv1uvqRVuVsXb YplVEJ4+GsMr8UbyAXXeeQla/aKcvZdbzceKCk+fNhKe0p3kO949ccGk6j8Q== 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=1724924324; x=1725010724; bh=9XmY1xeDnbKPYTcbeywNYPz7FP32 soIeJ9RndrWmoR0=; b=ZzJz7QFWHZys1RlIvHMjAXQYvfuU/W1s1Ul3O448xIMk AyXOBGspAspm8OYm+FtGaYuiOuK3AHzX6HjnYCGlh6wIovn+Ut+0Iwp3HTKbqTKY oH3zVdcRMD7WRqKOA9jKPj2xImyQcId/eSjaaXEVtO+zTbNEi05CrbfSYEWoUyxv Y9+PNsowzuisBKeX5iIXYer8s+hbaogTV0myMsmbErNTpXwFSGNFZzLvnI1hxga0 HAR2J/VTNFPydXge2QEpHvDfRRBFFRpL0qulBEOxE/lnImlPvnKeenUTQIGK9fsL X70DiSEdbOBCCBYamJXYl/zJ0disZtyeDbf5wPN4ZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eb3589f6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:34 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 06/21] environment: make `get_git_work_tree()` accept a repository Message-ID: <7fc346d3bb5c470a373d089b60f10204d3fd8efb.1724923648.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 | 3 ++- builtin/init-db.c | 4 ++-- builtin/reset.c | 4 ++-- builtin/rev-parse.c | 4 ++-- builtin/stash.c | 2 +- builtin/submodule--helper.c | 2 +- builtin/update-index.c | 2 +- dir.c | 2 +- environment.c | 7 +------ environment.h | 1 - fsmonitor.c | 2 +- pathspec.c | 2 +- repository.c | 5 +++++ repository.h | 1 + setup.c | 16 ++++++++-------- trace.c | 2 +- 18 files changed, 33 insertions(+), 32 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 da9315e84d4..7c16c55baaf 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -377,7 +377,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"); @@ -738,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(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..d7de0427845 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1291,7 +1291,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..2e5f477339b 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -441,7 +441,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 +474,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 4308a2a8549..65b0b5e2c0a 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -966,7 +966,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 @@ -991,7 +991,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 ae42da02b97..bc22164dd75 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -640,7 +640,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..2a8690dadd0 100644 --- a/dir.c +++ b/dir.c @@ -2838,7 +2838,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..cbc12f060e2 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -169,7 +169,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 2d9ae1c1525..094588c2165 100644 --- a/trace.c +++ b/trace.c @@ -307,7 +307,7 @@ void trace_repo_setup(void) cwd = xgetcwd(); - if (!(git_work_tree = get_git_work_tree())) + if (!(git_work_tree = repo_get_work_tree(the_repository))) git_work_tree = "(null)"; if (!startup_info->prefix) From patchwork Thu Aug 29 09:38: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: 13782876 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E4CD818E341 for ; Thu, 29 Aug 2024 09:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924332; cv=none; b=W0IAjXQyfOlcPc3Fw5cuSMANfGYq+ut1y5t55HZl+Q0pJgOh8FnIG8B8QGy4Fd3R+8KWeoK8rQCWDIYGqmveUpeOcYvh1D83ldYnqiElWXzzeC9y49OjKZ6y/5SEdT9Q+pGb1/Tnx73ECmkdLWEP24qSL/bmnjxF2D/LVhJjv+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924332; 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=bD+fdFnQd2yv4JBlXaLctNi6EIDF4ufyCfyJZhIongpxtCyyWl/8D/7Gol4wBzCowe4gJ4ibrgKNCLysFcni0fOolS/C70ltovZzZ5GRN+TH4CkkeyKYCbT8KEeW44Zd5AAEAVEgFhuo1KdvUJDQYHR9ctDP9/X1S/N2v2eGjvc= 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=k0dwmd5o; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=d/UE44NF; arc=none smtp.client-ip=103.168.172.144 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="k0dwmd5o"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="d/UE44NF" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id F392A138FC3A; Thu, 29 Aug 2024 05:38:49 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 29 Aug 2024 05:38:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924329; x=1725010729; bh=OTItF557so uhcXA4J1+3V/q03k7S7/YyyAAQEVNCS4U=; b=k0dwmd5ofYkHS4uSxRXDqzGfbd yl+1KJUiQEwObCd+9GfEPcJvJZgZfPESEOM/ljGbwYUjk8a/cOtOyanJYPSLUxKQ nCbJRXLEdl/PUHvPejbrtK30x7dxsb4bnNh7r0Txv0KM5V+NWZw27nruGNJKdHke GF4OuWI1e5UbEDCaQbnlFCmrQlWERT6rBuK86T3ciMoqCfcgIiYHC1MBfAEae8Y4 5Go31ZWuywMOAqMAGf17Kovi0gr1b1wlwW2in3LEHNdBHlkZ0Fn+XVcqPcLn20iw 5vo94+kaMSoEF2qGDicAf90d7597ava2303A6Jb0S5NJdNYdlCJwYB2CpY9g== 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=1724924329; x=1725010729; bh=OTItF557souhcXA4J1+3V/q03k7S 7/YyyAAQEVNCS4U=; b=d/UE44NFXWzldCWY1hf+d7WZyr096t3oACCzXv2l75vS 9g0VyMKRhAshpXePbyjXBl9+N62ddHxKrkSk4SoC1vKU5sVFv3CrLdtyJTq9H8o4 iTHVzwI8NdCYyRwA0E51CR0erxsEkIqQYsl81ex/DaCDpT/GwIwX3fb3a0I9DRGO kvHbxLSHHHgHCU8sxFaZT3Bf9jFVXD0auIp+Dhg2FAWPYA0cdTOSSO2ZG5UjBl5T axiVDJAIgbUWhdJGB4j58ps0VEm/zZcRQVqU2WmbmyCvpqgGCqw0fupq8+COYV37 8FXWEHBWGt5KpqdEl2jjJScB+KMxBXqBapNTK9GNuQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:49 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1985bb1e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:40 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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 Thu Aug 29 09:38: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: 13782877 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E4C8018E37D for ; Thu, 29 Aug 2024 09:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924335; cv=none; b=d9uuh12nxNR71X1rnBesSTvV32HDWWagQgFqHu9YL2W8vmFvl5d56MYJaivYLqyc4wxxrH0APXCkMZRv5PussrvN3XLbhv2cJ0N39Q0uUHsHBUkOn7vBIb4rHxqNk5NCLJzLNeQfE3zmg04Ndb0t30EYvh49LJ7hHmjZalqiVdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924335; c=relaxed/simple; bh=Mq0U0WwJtn1EmExkLW4YOYN8JRX2YfmxhsusaMrwobo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X3FMRyLiaDnje/INR6jq910RRaz8jmQ6erF9bO5WoGOaRJWeFQ3BgpI6C+nkng27E4FUVAsyxskDxA2Z1PQ50t6MYo4cAwN+7WzCGbc/pRzs/0yjLqyeAr/ES1fFMJgrM9zUjSxtnbi/4oP6uCwVHfINdxJmMy83ERrIMQyUX1g= 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=Z/6EFTua; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bIoagbc5; arc=none smtp.client-ip=103.168.172.144 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="Z/6EFTua"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bIoagbc5" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 054A5138FC3A; Thu, 29 Aug 2024 05:38:53 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 29 Aug 2024 05:38:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924333; x=1725010733; bh=2G8FfczyXk 58W8Hdv/10UbX4Cpv4Vof3RnqLz6X/e/0=; b=Z/6EFTua89gTfJecIM2/Kyp8dv ItovRsC7+Y6VUB3i+5wjUj3UvmRRVXsifhWjWpA5QzTrlFms5WQZAtl2UwWxRGyk JQF0Qn7xdxR6El6rp4xXeRG6qakcu9s0e8XQ1tram7Zfr2KWu5X/kb+naL4zQntr cvpqLgofhwg6wFP+vj67TBRDHUfTKHEYT/W9PNL3Tc/zJWlsu4m/1ICA7+DLa6HI dh2DaiVx5ibYNpMPcrcof3o5bIGXIHxLtcrCZFd+F2Pxs+44Hv7Bm4cQIBLX9AQA j5fftCiEUA9uPjorzOHdU0SMi+2dWItq/RB8dgRpc+9HDHewfp1gi0a9LGGA== 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=1724924333; x=1725010733; bh=2G8FfczyXk58W8Hdv/10UbX4Cpv4 Vof3RnqLz6X/e/0=; b=bIoagbc5YjYdK24/YXjWGQLTKGVVFAyE7dSUZkNOIBXj DsKaJwH3VXa0tSmfgDBLZ7MRNqECvfTK3mMwianL2Y1ZYXPTesyQD8JzzMNKvwih zvhhQvJ97IVwF10x8u5fYzIiYr1reuS3B2rLXhKcIpuipG2D37G9UxRrLBIyDji6 st1tPAvr95T80aRhDjCpWxGIUNWwWIINQwI1Ch6jQbDXf0cWgiirhgiYuOmFGE3t l3w8rF8vvk9wvPyb3qu2Me22W3jUaiD682OiIJAyW8WclbZN9VTxMDAYbhqyHrvV mfSDJofWaImrj3RKmfAkZr/tcAE74hsa9KV38klLEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 526ae21f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:43 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:50 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 08/21] config: make dependency on repo in `read_early_config()` explicit Message-ID: <85e40696cc96c0956de4c9221e7ae49b1789163b.1724923648.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `read_early_config()` function can be used to read configuration where a repository has not yet been set up. As such, it is optional whether or not `the_repository` has already been initialized. If it was initialized we use its commondir and gitdir. If not, the function will try to detect the Git directories by itself and, if found, also parse their config files. This means that we implicitly rely on `the_repository`. Make this dependency explicit by passing a `struct repository`. This allows us to again drop the `USE_THE_REPOSITORY_VARIABLE` define in "config.c". Signed-off-by: Patrick Steinhardt --- alias.c | 6 ++++-- config.c | 10 ++++------ config.h | 2 +- help.c | 2 +- pager.c | 7 +++++-- t/helper/test-config.c | 3 ++- trace2/tr2_cfg.c | 4 +++- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/alias.c b/alias.c index 4daafd9bdae..1a1a141a0ae 100644 --- a/alias.c +++ b/alias.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "alias.h" #include "config.h" @@ -37,7 +39,7 @@ char *alias_lookup(const char *alias) { struct config_alias_data data = { alias, NULL }; - read_early_config(config_alias_cb, &data); + read_early_config(the_repository, config_alias_cb, &data); return data.v; } @@ -46,7 +48,7 @@ void list_aliases(struct string_list *list) { struct config_alias_data data = { NULL, NULL, list }; - read_early_config(config_alias_cb, &data); + read_early_config(the_repository, config_alias_cb, &data); } void quote_cmdline(struct strbuf *buf, const char **argv) diff --git a/config.c b/config.c index a8357ea9544..043e1c8a078 100644 --- a/config.c +++ b/config.c @@ -6,8 +6,6 @@ * */ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "advice.h" @@ -2204,7 +2202,7 @@ static void configset_iter(struct config_set *set, config_fn_t fn, void *data) } } -void read_early_config(config_fn_t cb, void *data) +void read_early_config(struct repository *repo, config_fn_t cb, void *data) { struct config_options opts = {0}; struct strbuf commondir = STRBUF_INIT; @@ -2212,9 +2210,9 @@ void read_early_config(config_fn_t cb, void *data) opts.respect_includes = 1; - if (have_git_dir()) { - opts.commondir = repo_get_common_dir(the_repository); - opts.git_dir = repo_get_git_dir(the_repository); + if (repo && repo->gitdir) { + opts.commondir = repo_get_common_dir(repo); + opts.git_dir = repo_get_git_dir(repo); /* * When setup_git_directory() was not yet asked to discover the * GIT_DIR, we ask discover_git_directory() to figure out whether there diff --git a/config.h b/config.h index f5fa833cb98..5c730c4f899 100644 --- a/config.h +++ b/config.h @@ -198,7 +198,7 @@ int git_config_from_parameters(config_fn_t fn, void *data); * `the_repository` has not yet been set up, try to discover the Git * directory to read the configuration from. */ -void read_early_config(config_fn_t cb, void *data); +void read_early_config(struct repository *repo, config_fn_t cb, void *data); /* * Read config but only enumerate system and global settings. diff --git a/help.c b/help.c index c03863f2265..413c93edaea 100644 --- a/help.c +++ b/help.c @@ -618,7 +618,7 @@ const char *help_unknown_cmd(const char *cmd) memset(&other_cmds, 0, sizeof(other_cmds)); memset(&aliases, 0, sizeof(aliases)); - read_early_config(git_unknown_cmd_config, NULL); + read_early_config(the_repository, git_unknown_cmd_config, NULL); /* * Disable autocorrection prompt in a non-interactive session diff --git a/pager.c b/pager.c index 9c24ce62633..40b664f893c 100644 --- a/pager.c +++ b/pager.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "editor.h" @@ -92,7 +94,8 @@ const char *git_pager(int stdout_is_tty) pager = getenv("GIT_PAGER"); if (!pager) { if (!pager_program) - read_early_config(core_pager_config, NULL); + read_early_config(the_repository, + core_pager_config, NULL); pager = pager_program; } if (!pager) @@ -298,7 +301,7 @@ int check_pager_config(const char *cmd) data.want = -1; data.value = NULL; - read_early_config(pager_command_config, &data); + read_early_config(the_repository, pager_command_config, &data); if (data.value) pager_program = data.value; diff --git a/t/helper/test-config.c b/t/helper/test-config.c index e193079ed54..33247f0e92e 100644 --- a/t/helper/test-config.c +++ b/t/helper/test-config.c @@ -96,7 +96,8 @@ int cmd__config(int argc, const char **argv) struct config_set cs; if (argc == 3 && !strcmp(argv[1], "read_early_config")) { - read_early_config(early_config_cb, (void *)argv[2]); + read_early_config(the_repository, early_config_cb, + (void *)argv[2]); return 0; } diff --git a/trace2/tr2_cfg.c b/trace2/tr2_cfg.c index d96d908bb9d..22a99a0682a 100644 --- a/trace2/tr2_cfg.c +++ b/trace2/tr2_cfg.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "strbuf.h" @@ -124,7 +126,7 @@ void tr2_cfg_list_config_fl(const char *file, int line) struct tr2_cfg_data data = { file, line }; if (tr2_cfg_load_patterns() > 0) - read_early_config(tr2_cfg_cb, &data); + read_early_config(the_repository, tr2_cfg_cb, &data); } void tr2_list_env_vars_fl(const char *file, int line) From patchwork Thu Aug 29 09:38:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782878 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E285418E745 for ; Thu, 29 Aug 2024 09:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924338; cv=none; b=nlWmT6Ww5i6+WcwCrnyJ7azxC1idsBhiUZvACP7R/HwR41gDQu8Yj5ronuRTu0x4NfsFDpUhm73ym/EEL+COdqDMFVqvodVzg4Mc6YEUvwyIyZPPje6Vw/qVWrksa5bXb+VhELPjHZQwnlJFE0mxce57mXaqnVyfBwXTakY4goI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924338; c=relaxed/simple; bh=QmWTmIvhpHM/oVktMS/6Ee4C8yvrejce12hND3uphdU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BMFDpem+0uljmMeiBMD65oWEgVa/0LYsYF8uSESVsIBnGUNRMYSszJCw6sp1KjcNVis87gXj0QOTLiJ0tCzmsmL7WWc74KPOJvDDdePr5x3afywQ2TopHqRoTI9NMHoJqOtSjPEqKsJslqQhG4u1oNbvS1JoBgt/1dBUS6wjsIU= 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=szCOf7gY; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fwVqDOh2; arc=none smtp.client-ip=103.168.172.144 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="szCOf7gY"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fwVqDOh2" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id F26ED138FC3A; Thu, 29 Aug 2024 05:38:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 29 Aug 2024 05:38: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=1724924335; x=1725010735; bh=eY0BWSJmUe a/oC4SgDpxZ9RnyqLvySn/M72sEw9Qq4E=; b=szCOf7gYljEnOuv5a8z2GW/hUE 4UZFF0NFgRCMoOU3RcIhPOZqiqkh22gb/wmMIBk59umslL9vZuC7EwADllZ4lFYl c1wciK09PQtoxf/JTq7fiewddz0HVcgZy7mIfxDpgaI3DQOZ66z3JVzRF2VY69Fi PU8axqAFT00OpmxB34fXKa8V/lC02FvAq9k6jNJI5RomGMZVOCfN0Cn9I4BBOSdP 5Z809gA9hbkGuZwRnLckYJDWJWlT7vXrOxQgZqYBqiS6Oxp+3O/142Wzz3iJGkKn Aw80M9G5xuz1Hruc5vuUTJCETQfGjFS022vfBoV4kTR6T7RbIgY9bEiMBRlQ== 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=1724924335; x=1725010735; bh=eY0BWSJmUea/oC4SgDpxZ9RnyqLv ySn/M72sEw9Qq4E=; b=fwVqDOh2wG/NXubJFfxb4M9lbCB88oEB9AgEM+J6Q7Se 3tScaFt8rSVZW8QeNOsA0d1VYG6oxFcfp3Zi/+zNBXIPB1h2t3UhDORst9Tmkv+P MLzUzhiuV644v+fbiz+fq1DWe+ZqfypB58aaQmgLILMSnwZCW9PmjS6TBO2OJGzq wYg1rCYKItuwPhLhCUBQ63/oCUG6UffiJ54YghOIozu1zEZPxIgC2g6roMk0/Xqv DDMxjYZ9sXjyevh0UPKiGeUXMkUmjoFkLBtAZ66+5f4YOK6KDjHqBYp7sKjqJ8Fv f69u/ve5bitvvrpShCdtNikJQkl3XA99qPInheFlug== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2b3f0aa6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:46 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:53 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 09/21] environment: move `odb_mkstemp()` into object layer Message-ID: <8321454adc8f4a1ebf68cd5adc93a19ef03c8f27.1724923648.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 `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 | 1 + environment.c | 34 ---------------------------------- environment.h | 15 --------------- object-file.c | 33 +++++++++++++++++++++++++++++++++ object-store-ll.h | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/bundle-uri.c b/bundle-uri.c index 1e0ee156ba3..c5f9948d6bf 100644 --- a/bundle-uri.c +++ b/bundle-uri.c @@ -13,6 +13,7 @@ #include "config.h" #include "fetch-pack.h" #include "remote.h" +#include "object-store-ll.h" static struct { enum bundle_list_heuristic heuristic; diff --git a/environment.c b/environment.c index 4d0637b3822..f337efd1dd5 100644 --- a/environment.c +++ b/environment.c @@ -23,7 +23,6 @@ #include "commit.h" #include "strvec.h" #include "object-file.h" -#include "object-store-ll.h" #include "path.h" #include "replace-object.h" #include "tmp-objdir.h" @@ -268,39 +267,6 @@ void set_git_work_tree(const char *new_work_tree) repo_set_worktree(the_repository, new_work_tree); } -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) -{ - int fd; - /* - * we let the umask do its job, don't try to be more - * restrictive except to remove write permission. - */ - int mode = 0444; - git_path_buf(temp_filename, "objects/%s", pattern); - fd = git_mkstemp_mode(temp_filename->buf, mode); - if (0 <= fd) - return fd; - - /* slow path */ - /* some mkstemp implementations erase temp_filename on failure */ - git_path_buf(temp_filename, "objects/%s", pattern); - safe_create_leading_directories(temp_filename->buf); - return xmkstemp_mode(temp_filename->buf, mode); -} - -int odb_pack_keep(const char *name) -{ - int fd; - - fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); - if (0 <= fd) - return fd; - - /* slow path */ - safe_create_leading_directories_const(name); - return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); -} - static void set_git_dir_1(const char *path) { xsetenv(GIT_DIR_ENVIRONMENT, path, 1); diff --git a/environment.h b/environment.h index 52e1803aba6..682d4f2e3b5 100644 --- a/environment.h +++ b/environment.h @@ -200,21 +200,6 @@ extern int grafts_keep_true_parents; extern int repository_format_precious_objects; -/* - * Create a temporary file rooted in the object database directory, or - * die on failure. The filename is taken from "pattern", which should have the - * usual "XXXXXX" trailer, and the resulting filename is written into the - * "template" buffer. Returns the open descriptor. - */ -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); - -/* - * Create a pack .keep file named "name" (which should generally be the output - * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on - * error. - */ -int odb_pack_keep(const char *name); - const char *get_log_output_encoding(void); const char *get_commit_output_encoding(void); diff --git a/object-file.c b/object-file.c index fa4121b98ad..968da27cd41 100644 --- a/object-file.c +++ b/object-file.c @@ -419,6 +419,39 @@ enum scld_error safe_create_leading_directories_const(const char *path) return result; } +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern) +{ + int fd; + /* + * we let the umask do its job, don't try to be more + * restrictive except to remove write permission. + */ + int mode = 0444; + git_path_buf(temp_filename, "objects/%s", pattern); + fd = git_mkstemp_mode(temp_filename->buf, mode); + if (0 <= fd) + return fd; + + /* slow path */ + /* some mkstemp implementations erase temp_filename on failure */ + git_path_buf(temp_filename, "objects/%s", pattern); + safe_create_leading_directories(temp_filename->buf); + return xmkstemp_mode(temp_filename->buf, mode); +} + +int odb_pack_keep(const char *name) +{ + int fd; + + fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600); + if (0 <= fd) + return fd; + + /* slow path */ + safe_create_leading_directories_const(name); + return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); +} + static void fill_loose_path(struct strbuf *buf, const struct object_id *oid) { int i; diff --git a/object-store-ll.h b/object-store-ll.h index c5f2bb2fc2f..53b8e693b1b 100644 --- a/object-store-ll.h +++ b/object-store-ll.h @@ -231,6 +231,21 @@ struct raw_object_store { struct raw_object_store *raw_object_store_new(void); void raw_object_store_clear(struct raw_object_store *o); +/* + * Create a temporary file rooted in the object database directory, or + * die on failure. The filename is taken from "pattern", which should have the + * usual "XXXXXX" trailer, and the resulting filename is written into the + * "template" buffer. Returns the open descriptor. + */ +int odb_mkstemp(struct strbuf *temp_filename, const char *pattern); + +/* + * Create a pack .keep file named "name" (which should generally be the output + * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on + * error. + */ +int odb_pack_keep(const char *name); + /* * Put in `buf` the name of the file in the local object database that * would be used to store a loose object with the specified oid. From patchwork Thu Aug 29 09:38:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782879 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 A17E818E75D for ; Thu, 29 Aug 2024 09:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924341; cv=none; b=lVo0VZhaOPx0s7H0UNOUeDx7tqMbm60tqP9N8s/nLqfMKYD9+o7nDReTSOxjF7VTBmI+piD1xOFEkYX6s0sbqY/mfKtMfG7X0lkb0/VV9+O6u3PZXXv1c7VKFE8/vNJUgPBIgr5sSi6DH3NKefse//sdzsXwQ7kiftO/atcja2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924341; 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=EeEo6kthhIx9KuVOgCrqLbzxzt5Z4OwnjV93WsCUrQkiJve4e+X0UP9szqkTbYFMEsTJkr2yRr+sX6cb6uhabHjiJLh+xgIoaA3YERO3eVjNuxz8WLzXG5MQrDIYjfHR52tK+6T7QiWrMFEq+R5a+Db8l+aJqEIpu3C+tAC7NvA= 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=P2gAWmmK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=RZ/E2TbT; arc=none smtp.client-ip=103.168.172.144 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="P2gAWmmK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RZ/E2TbT" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id F14EB138FC3A; Thu, 29 Aug 2024 05:38:58 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 29 Aug 2024 05:38: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=1724924338; x=1725010738; bh=aTq5u0vFnq usadQrB0mvYtORZo3HHmDPXzy0GjkOiLY=; b=P2gAWmmKz4PpR34YE7XhTvCbmJ SsYfgd417hlIw/oeWIzMxV7TdRtuCKbz5vcunurJukGl/ORf8yGvW8MojjhNM3bp mDbhMiLyvSgXqoz7ysz25JJruuGE6Gz/t/YhbLEPcere9ZY/jBq0acitZ0LGHLmD VFDqYtzINib13mVByLw5YyjcmA2rs/sjFXgTPiczYDj1ECBoIzoWvqluccNcsQQJ bU1X0BQhY9Ubm/4hkauhXvCwJnrd6mqNg3A2EdbfAXeiE4jLL/Y1tCWrE14l5hsA i/4hST3eqL6LpkSZOYB4OuQ1XDYCVMZ79cfRjT1T/1VJVthtHx5RoeJFn7WQ== 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=1724924338; x=1725010738; bh=aTq5u0vFnqusadQrB0mvYtORZo3H HmDPXzy0GjkOiLY=; b=RZ/E2TbTrNJbLeHbXH4dzVoeTbrEKpYl00pIgjJQjyEh Nvo7zLT46TLh6qBjbLYpULVVq/JduRGY5gYarIyjoZAY7UHOD6tRZvSwuKcTqi1p /A8RwO4/SDt9K++NuzLWJMBNQwM7SeSUWmuu3imFAr2ztbsJR0Pblh8Ech+qsBWU CCVv3lnCF9d/qYYaCTa/vN5yC8FsTCdO2ZbdjXgOHk5j1V1QCniIxFa+zXVUhKlt HYwMtEghLP6NaklL+4u/sQi9qOrFJdhlvenly4Xwq8yOqMINyhn8/LwK+bFB1TmF vsqqUMEWsH9IOXlbuP8USKIckuw/2j7W1oJkzde+XA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:38:58 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b1ed2542 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:49 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:56 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 10/21] environment: make `get_git_namespace()` self-contained Message-ID: <0b3916b2d0d33215a86fcbb79302aa6f145e89fc.1724923648.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The logic to set up and retrieve `git_namespace` is distributed across different functions which communicate with each other via a global environment variable. This is rather pointless though, as the value is always derived from an environment variable, and this environment variable does not change after we have parsed global options. Convert the function to be fully self-contained such that it lazily populates once called. Signed-off-by: Patrick Steinhardt --- environment.c | 57 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/environment.c b/environment.c index f337efd1dd5..49844418419 100644 --- a/environment.c +++ b/environment.c @@ -122,8 +122,6 @@ int core_preload_index = 1; /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; -static char *git_namespace; - /* * Repository-local GIT_* environment variables; see environment.h for details. */ @@ -146,27 +144,6 @@ const char * const local_repo_env[] = { NULL }; -static char *expand_namespace(const char *raw_namespace) -{ - struct strbuf buf = STRBUF_INIT; - struct strbuf **components, **c; - - if (!raw_namespace || !*raw_namespace) - return xstrdup(""); - - strbuf_addstr(&buf, raw_namespace); - components = strbuf_split(&buf, '/'); - strbuf_reset(&buf); - for (c = components; *c; c++) - if (strcmp((*c)->buf, "/") != 0) - strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); - strbuf_list_free(components); - if (check_refname_format(buf.buf, 0)) - die(_("bad git namespace path \"%s\""), raw_namespace); - strbuf_addch(&buf, '/'); - return strbuf_detach(&buf, NULL); -} - const char *getenv_safe(struct strvec *argv, const char *name) { const char *value = getenv(name); @@ -205,8 +182,6 @@ void setup_git_env(const char *git_dir) : "refs/replace/"); update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); - free(git_namespace); - git_namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); if (shallow_file) set_alternate_shallow_file(the_repository, shallow_file, 0); @@ -229,9 +204,35 @@ int have_git_dir(void) const char *get_git_namespace(void) { - if (!git_namespace) - BUG("git environment hasn't been setup"); - return git_namespace; + static const char *namespace; + + struct strbuf buf = STRBUF_INIT; + struct strbuf **components, **c; + const char *raw_namespace; + + if (namespace) + return namespace; + + raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT); + if (!raw_namespace || !*raw_namespace) { + namespace = ""; + return namespace; + } + + strbuf_addstr(&buf, raw_namespace); + components = strbuf_split(&buf, '/'); + strbuf_reset(&buf); + for (c = components; *c; c++) + if (strcmp((*c)->buf, "/") != 0) + strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf); + strbuf_list_free(components); + if (check_refname_format(buf.buf, 0)) + die(_("bad git namespace path \"%s\""), raw_namespace); + strbuf_addch(&buf, '/'); + + namespace = strbuf_detach(&buf, NULL); + + return namespace; } const char *strip_namespace(const char *namespaced_ref) From patchwork Thu Aug 29 09:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782880 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7564118E75D for ; Thu, 29 Aug 2024 09:39:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924345; cv=none; b=jeu2rSXHs6LIsLJKCTZwpvP/acOlbKKPyDpCwu9WrXMqSEZ7eVoBIjK9LWr1XgqQO7jZFn6fiVF+4ojyT6FA/3kxisC/f4VT0RN/whRt/EzPhqM+pkGZOORNYbPP0F6lgUu+QLt2CQU0NvQZ+j3lRdxHqxPiwCz+Gt1ajB26FgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924345; c=relaxed/simple; bh=+OFXAcgoVOhiOvSYh00zQIke64MpS8p+PvIiSliGWBI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=g5hIQIOb9UaBpw5zJW00Tp7jBpruKXYw7UjtCU0pl9R0dVQCRbKvAn//coCiOdTVYzYDuCtyZ82ZujppOGLO9/1lvEF1nul0vlEzEk6pUwCTmi4xhfLW75RwfQz+7N0tFMwBSo0TQ/b1hIjRiqobTnBb9x7wnD47JQwL8B+rWgg= 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=Mmv/vP5J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=A34FvVO0; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Mmv/vP5J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A34FvVO0" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 0A7071151CB0; Thu, 29 Aug 2024 05:39:02 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 29 Aug 2024 05:39:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924342; x=1725010742; bh=NOS00PYJoc bEQi9lJL4zQpVlvLnPJU6sNrfNxEaxCQM=; b=Mmv/vP5JCZBtpPl8crToJ2UitA PJGvOK5AzDGyOGe7bbChagDL2JdZ8+cp58Ru2mk9fAl9djpK8rDn/GwoC5O4wf0v wsSCdJCOrrhvz/PrmeDKaOcwS3OxcjKcXSGszbMw2VFRp0iapSnVdHafKyVnLbay YpmUEFvM5xadJenuD0T2nGSkkx/hgWKV6WNQiy2QMRyE5SI/EpVUKSe6RAVqQEfj vvSTpBTAmgkVh5qerT9MU+IdOFcLIDAZwgyctpBnH8NCxoExexcaC97KINo9JY0U uWkgdbfgDiKa+XUDPSS8zIMTdwjiVxGuEGZ1zmo5D3g3LKWLvF1sUr4YYe5w== 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=1724924342; x=1725010742; bh=NOS00PYJocbEQi9lJL4zQpVlvLnP JU6sNrfNxEaxCQM=; b=A34FvVO0aXT9m4evcRNfG+LxXvEOeOFsyKRrP06rrsjq vaoneYTgbPKZQROEGa4UsJRvRD7Rstap7LQ/Kospg1BkxOUf/CrJ6Zu8f8Sec+Dr mkJ7xM3HdbFRNFXZ0h9HEJyZq1uFYdOO1/969M2M8pyXbmQroK+MGTZFURJiI0uB X5tGUAksVMXrQeXOjC+1yqeI/vFN3qgz9RzAgVpN0wE+S4hrs48zqX7UKbmsdn0G dAchDvC6NY0hL8dEC2znRZ0DhDrWZoB0sB+If4HPjPMbiJhbeGU9b1VVJzlcfxr7 GWDdzo0k/iTKNjvGyJjwM2stEs48RN3686APJhYXGQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6bff9a45 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:52 +0000 (UTC) Date: Thu, 29 Aug 2024 11:38:59 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 11/21] environment: move `set_git_dir()` and related into setup 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 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 | 118 +++++++++++++++++++++++++++++++++++++++++++++++--- setup.h | 3 ++ 4 files changed, 115 insertions(+), 113 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..a4a9fbb3a2a 100644 --- a/setup.c +++ b/setup.c @@ -2,24 +2,30 @@ #include "git-compat-util.h" #include "abspath.h" +#include "chdir-notify.h" +#include "config.h" #include "copy.h" +#include "dir.h" #include "environment.h" #include "exec-cmd.h" +#include "exec-cmd.h" #include "gettext.h" #include "hex.h" +#include "object-file.h" #include "object-name.h" +#include "path.h" +#include "quote.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 "chdir-notify.h" -#include "path.h" -#include "quote.h" +#include "strvec.h" +#include "tmp-objdir.h" +#include "trace.h" #include "trace2.h" #include "worktree.h" -#include "exec-cmd.h" static int inside_git_dir = -1; static int inside_work_tree = -1; @@ -1613,6 +1619,106 @@ enum discovery_result discover_git_directory_reason(struct strbuf *commondir, return result; } +void setup_git_env(const char *git_dir) +{ + char *git_replace_ref_base; + const char *shallow_file; + const char *replace_ref_base; + struct set_gitdir_args args = { NULL }; + struct strvec to_free = STRVEC_INIT; + + args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); + args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); + args.graft_file = getenv_safe(&to_free, GRAFT_ENVIRONMENT); + args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); + args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); + if (getenv(GIT_QUARANTINE_ENVIRONMENT)) { + args.disable_ref_updates = 1; + } + + repo_set_gitdir(the_repository, git_dir, &args); + strvec_clear(&to_free); + + if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) + disable_replace_refs(); + replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT); + git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base + : "refs/replace/"); + update_ref_namespace(NAMESPACE_REPLACE, git_replace_ref_base); + + shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT); + if (shallow_file) + set_alternate_shallow_file(the_repository, shallow_file, 0); + + if (git_env_bool(NO_LAZY_FETCH_ENVIRONMENT, 0)) + fetch_if_missing = 0; +} + +static void set_git_dir_1(const char *path) +{ + xsetenv(GIT_DIR_ENVIRONMENT, path, 1); + setup_git_env(path); +} + +static void update_relative_gitdir(const char *name UNUSED, + const char *old_cwd, + const char *new_cwd, + void *data UNUSED) +{ + char *path = reparent_relative_path(old_cwd, new_cwd, + repo_get_git_dir(the_repository)); + struct tmp_objdir *tmp_objdir = tmp_objdir_unapply_primary_odb(); + + trace_printf_key(&trace_setup_key, + "setup: move $GIT_DIR to '%s'", + path); + set_git_dir_1(path); + if (tmp_objdir) + tmp_objdir_reapply_primary_odb(tmp_objdir, old_cwd, new_cwd); + free(path); +} + +void set_git_dir(const char *path, int make_realpath) +{ + struct strbuf realpath = STRBUF_INIT; + + if (make_realpath) { + strbuf_realpath(&realpath, path, 1); + path = realpath.buf; + } + + set_git_dir_1(path); + if (!is_absolute_path(path)) + chdir_notify_register(NULL, update_relative_gitdir, NULL); + + strbuf_release(&realpath); +} + +static int git_work_tree_initialized; + +/* + * Note. This works only before you used a work tree. This was added + * primarily to support git-clone to work in a new repository it just + * created, and is not meant to flip between different work trees. + */ +void set_git_work_tree(const char *new_work_tree) +{ + if (git_work_tree_initialized) { + struct strbuf realpath = STRBUF_INIT; + + strbuf_realpath(&realpath, new_work_tree, 1); + new_work_tree = realpath.buf; + if (strcmp(new_work_tree, the_repository->worktree)) + die("internal error: work tree has already been set\n" + "Current worktree: %s\nNew worktree: %s", + the_repository->worktree, new_work_tree); + strbuf_release(&realpath); + return; + } + git_work_tree_initialized = 1; + repo_set_worktree(the_repository, new_work_tree); +} + const char *setup_git_directory_gently(int *nongit_ok) { static struct strbuf cwd = STRBUF_INIT; diff --git a/setup.h b/setup.h index fd2df7cd525..e496ab3e4de 100644 --- a/setup.h +++ b/setup.h @@ -94,6 +94,9 @@ static inline int discover_git_directory(struct strbuf *commondir, return 0; } +void set_git_dir(const char *path, int make_realpath); +void set_git_work_tree(const char *tree); + const char *setup_git_directory_gently(int *); const char *setup_git_directory(void); char *prefix_path(const char *prefix, int len, const char *path); From patchwork Thu Aug 29 09:39:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782881 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E608918F2D1 for ; Thu, 29 Aug 2024 09:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924348; cv=none; b=lETsPq/USFx2g6CXlFN9EIVCmqeynIA6r659M4wv6ayTv3tHkxjldGUrUsh0k1xMTlUjrs5dKu+JwZ7q7jMQA+hv7d4P4TWC5IPgo/z3BzmlKCgabGn/f/jwOn+V1DfJrLGs8RlnRYTPfhLpN67ceJhy2m4C3c/tSLCf7jkt7y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924348; 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=RSmjg3LqBoKyV7Z2Ot7Kaa0EH5ibFM2nwBGU6d1c9pH7cmAp/Ig1UKuggceYoYdLoYOT0vYck8cPtISOQ5V0l9TbUURvIW6+75+6WT/eZfv2vLY36tepkl/RFOdomREW2kQHFyUIPciFdysLILtqwXh5FYYuQ7AcU+Ugc0Cx3Wc= 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=f4Mh4r44; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=LIEvRHbJ; arc=none smtp.client-ip=103.168.172.144 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="f4Mh4r44"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="LIEvRHbJ" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 12A43138FC3A; Thu, 29 Aug 2024 05:39:06 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 29 Aug 2024 05:39:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924346; x=1725010746; bh=8OKSJA681b OeIyiFhXuEg76THmOc6VJPtf2c4TusuuM=; b=f4Mh4r44h2HfHWBPLSrlrI4C9/ V/c2EkM1dsqaU8fKRhkAT6f/w7V9Gi6wzzX/ln430KGWqv9LFzKWPJjL9XC+ThSw eG1Xfz2VrptD7N9jbcmb548ylvhNMjU7Zcl0qJN27B6Vu6gwkrN3qdc+S7i70nfj Qw5wc4Ai3KdDSFoh8clCOHL6TNgel9qioZ/q/lUyWbSW2GDr0rpGIj2i0hb7P6z3 Wjy24hIqSjzt/ZWK3LgAECQ3oQV2RYpl30cjiecugopwZC73yRPeKGtCvAr0p9Sq g7PbEat2BoatbhlEHwt6DOQovzrvXHNecWZynqFb3mT18mTHIuF0hlr3igEA== 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=1724924346; x=1725010746; bh=8OKSJA681bOeIyiFhXuEg76THmOc 6VJPtf2c4TusuuM=; b=LIEvRHbJJt51AW9v3wCY+4w1b+BiwFKuTqBRvsbDzygY XmsjuRTjTKwIPGEIpeKsdnnpEV2XwxB5b/RnQ3QefBibichON1DS+ddeJCdIAqDr fwhaSa3hH+GGMzDsGM5i+z6z3f/HCDgN3qi3TGWButIj8dnFihRpGAJ5WKMuDspn WRy2kAY/5xGovPzjqyN5ykxvb9YQtPFkGe1YQ7a1hK+ZnfjnDzJ7dLywyubSZg0o Q9Cc/eIVNr/Lv3UX2MjWcs2853iLEKQ7Et2k4XVBrKjZRfmECz6F7zA8PHBeiT0v GzuOAKn0dqrr9HihOdPvu4KvgKlnMJgA7qLLzRAqPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c0f3bb72 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:38:57 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 12/21] environment: reorder header to split out `the_repository`-free section 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: Reorder the "environment.h" header such that declarations which are free from `the_repository` come before those which aren't. The new structure is now: - Defines for environment variable names. - Things which do not rely on a repository. - Things which do, including those that implicitly rely on a parsed repository. This includes for example variables which get populated when reading repository config. This will allow us to guard the last category of declarations with `USE_THE_REPOSITORY_VARIABLE`. Signed-off-by: Patrick Steinhardt --- environment.h | 81 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/environment.h b/environment.h index b8460396790..f1a7c645db5 100644 --- a/environment.h +++ b/environment.h @@ -1,22 +1,6 @@ #ifndef ENVIRONMENT_H #define ENVIRONMENT_H -struct strvec; - -/* - * The character that begins a commented line in user-editable file - * that is subject to stripspace. - */ -extern const char *comment_line_str; -extern char *comment_line_str_to_free; -extern int auto_comment_line_char; - -/* - * Wrapper of getenv() that returns a strdup value. This value is kept - * in argv to be freed later. - */ -const char *getenv_safe(struct strvec *argv, const char *name); - /* Double-check local_repo_env below if you add to this list. */ #define GIT_DIR_ENVIRONMENT "GIT_DIR" #define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" @@ -86,6 +70,8 @@ const char *getenv_safe(struct strvec *argv, const char *name); */ #define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" +#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" + /* * Repository-local GIT_* environment variables; these will be cleared * when git spawns a sub-process that runs inside another repository. @@ -94,6 +80,28 @@ const char *getenv_safe(struct strvec *argv, const char *name); */ extern const char * const local_repo_env[]; +struct strvec; + +/* + * Wrapper of getenv() that returns a strdup value. This value is kept + * in argv to be freed later. + */ +const char *getenv_safe(struct strvec *argv, const char *name); + +/* + * Should we print an ellipsis after an abbreviated SHA-1 value + * when doing diff-raw output or indicating a detached HEAD? + */ +int print_sha1_ellipsis(void); + +/* + * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). + */ +int use_optional_locks(void); + +const char *get_git_namespace(void); +const char *strip_namespace(const char *namespaced_ref); + void setup_git_env(const char *git_dir); /* @@ -102,13 +110,19 @@ void setup_git_env(const char *git_dir); */ int have_git_dir(void); +/* + * Accessors for the core.sharedrepository config which lazy-load the value + * from the config (if not already set). The "reset" function can be + * used to unset "set" or cached value, meaning that the value will be loaded + * fresh from the config file on the next call to get_shared_repository(). + */ +void set_shared_repository(int value); +int get_shared_repository(void); +void reset_shared_repository(void); + extern int is_bare_repository_cfg; int is_bare_repository(void); extern char *git_work_tree_cfg; -const char *get_git_namespace(void); -const char *strip_namespace(const char *namespaced_ref); - -#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" /* Environment bits from configuration mechanism */ extern int trust_executable_bit; @@ -134,16 +148,6 @@ extern unsigned long big_file_threshold; extern unsigned long pack_size_limit_cfg; extern int max_allowed_tree_depth; -/* - * Accessors for the core.sharedrepository config which lazy-load the value - * from the config (if not already set). The "reset" function can be - * used to unset "set" or cached value, meaning that the value will be loaded - * fresh from the config file on the next call to get_shared_repository(). - */ -void set_shared_repository(int value); -int get_shared_repository(void); -void reset_shared_repository(void); - extern int core_preload_index; extern int precomposed_unicode; extern int protect_hfs; @@ -153,11 +157,6 @@ extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; -/* - * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). - */ -int use_optional_locks(void); - enum log_refs_config { LOG_REFS_UNSET = -1, LOG_REFS_NONE = 0, @@ -172,6 +171,7 @@ enum rebase_setup_type { AUTOREBASE_REMOTE, AUTOREBASE_ALWAYS }; +extern enum rebase_setup_type autorebase; enum push_default_type { PUSH_DEFAULT_NOTHING = 0, @@ -181,15 +181,12 @@ enum push_default_type { PUSH_DEFAULT_CURRENT, PUSH_DEFAULT_UNSPECIFIED }; - -extern enum rebase_setup_type autorebase; extern enum push_default_type push_default; enum object_creation_mode { OBJECT_CREATION_USES_HARDLINKS = 0, OBJECT_CREATION_USES_RENAMES = 1 }; - extern enum object_creation_mode object_creation_mode; extern char *notes_ref_name; @@ -209,9 +206,11 @@ extern char *askpass_program; extern char *excludes_file; /* - * Should we print an ellipsis after an abbreviated SHA-1 value - * when doing diff-raw output or indicating a detached HEAD? + * The character that begins a commented line in user-editable file + * that is subject to stripspace. */ -int print_sha1_ellipsis(void); +extern const char *comment_line_str; +extern char *comment_line_str_to_free; +extern int auto_comment_line_char; #endif From patchwork Thu Aug 29 09:39:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782882 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEAFC18CC19 for ; Thu, 29 Aug 2024 09:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924352; cv=none; b=s45pvuCA/AviRt8X4uUSDpaFzJGldRIEV4R2VNleo5FZ0XF84Vt7+v2D8bPPBvpNwRBEX2QdqHDxKSKdfY31fcbHAyBCH/R9Lewnxv+sspYf591MgWqo3FIHzjOeiHq6Euf6CAcy19JQhyVLGXBTQmyonOAxiVyybm7HzNPwJxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924352; c=relaxed/simple; bh=6Dm+WJpSQI+ZLufDPxqKaqDXzxZn7sY61bKrIOJsX/U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JD6LF7cz9ovzuQV+//4yIl4mcOM70HeYF4a2G5gyjlAWzTuVVEl3IGHSMKd3cgpSqgg0si4YK5AilCB2k0SN24ELJ52Iy8onzOcd0jktYybPg1zJLNprTE/fHsV7+/+Qc7hWt1HZ6dg3lzWvBrXo74pYzO+9dYKrJipv4E3U5n8= 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=pchx7Dqa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iCr1MLr5; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="pchx7Dqa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iCr1MLr5" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 103461151CC3; Thu, 29 Aug 2024 05:39:10 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 29 Aug 2024 05:39:10 -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=1724924350; x=1725010750; bh=Kgn3SDPe2m QhJN5yMyTMiPRu4A5V5kHIQ+PHXE8QtFQ=; b=pchx7DqaCK1uq0xN+n650nr4c+ 7t/H+xoglvMazpS4o34bztLZM6NAVRPQhY0qCr/LBo2PHqKCjyKrYU6an0cCB7d7 8KNYhrgsRZj0LVrzAuw+0jP8VkGh4sC7iVc2k/nZcdE8L2wIxD3sK+CA2wO8A+Nu Um0mEm0I1wWNMVaodSyUhow54eXd+X5E2xNo/3mAb1SoKVD4uGEFaNs1lnCAIl6e PylnRzEK0hLj8zVKQeocth0wAAyP/O7AThN0ZNPjy96Lo1x852QOo/DsdKliKoj3 EZe/gohDckVSuulkAUkRbhdDMEYbECFGCniwvmYRp0i3YlRcAFidjNBkDrhQ== 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=1724924350; x=1725010750; bh=Kgn3SDPe2mQhJN5yMyTMiPRu4A5V 5kHIQ+PHXE8QtFQ=; b=iCr1MLr5UHmW6VxWYKaGCm2N04ACRnorkzb5W4lilIZS fPJ1OKJFFz3F+mWZAp03qZMzofqpLXfkr1qL6rE/PjrrSXe+qZb1lMX3hhw6nA+r 6Ltk4xoisVPqeNY6VBtJ0P4ZFPZ/woBCb08db3X3FZbM97N8bubre/LnAezbP+vQ eBhVH10cx3Iq8Oq2bKR2QqYaE6IZs6l7yUCNF26bdenN9AL1hFBZNaxR4Y0eVbZ6 eXNMMPFdlWf1eObhsquD6m7Npb1g/GfvhF2Lfp4PpS528H7M5Mg+pSsU0KHIytZt 1xzzYcaELWBqTpTJpvAsKi9+eh1A4HUiE4bHKY78BA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d14ef3c2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:00 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 13/21] environment: guard state depending on a repository Message-ID: <27a7d00de78098a84ac3ff31aee075a5944821dc.1724923648.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 --- 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 ++ 12 files changed, 49 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 043e1c8a078..f3066c37477 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,8 @@ * */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "advice.h" diff --git a/environment.h b/environment.h index f1a7c645db5..934859e1c59 100644 --- a/environment.h +++ b/environment.h @@ -102,6 +102,28 @@ int use_optional_locks(void); const char *get_git_namespace(void); const char *strip_namespace(const char *namespaced_ref); +/* + * TODO: All the below state either explicitly or implicitly relies on + * `the_repository`. We should eventually get rid of these and make the + * dependency on a repository explicit: + * + * - `setup_git_env()` ideally shouldn't exist as it modifies global state, + * namely the environment. The current process shouldn't ever access that + * state via envvars though, but should instead consult a `struct + * repository`. When spawning new processes, we would ideally also pass a + * `struct repository` and then set up the environment variables for the + * child process, only. + * + * - `have_git_dir()` should not have to exist at all. Instead, we should + * decide on whether or not we have a `struct repository`. + * + * - All the global config variables should become tied to a repository. Like + * this, we'd correctly honor repository-local configuration and be able to + * distinguish configuration values from different repositories. + * + * Please do not add new global config variables here. + */ +# ifdef USE_THE_REPOSITORY_VARIABLE void setup_git_env(const char *git_dir); /* @@ -213,4 +235,5 @@ extern const char *comment_line_str; extern char *comment_line_str_to_free; extern int auto_comment_line_char; -#endif +# endif /* USE_THE_REPOSITORY_VARIABLE */ +#endif /* ENVIRONMENT_H */ diff --git a/name-hash.c b/name-hash.c index 3a58ce03d9c..95528e3bcd2 100644 --- a/name-hash.c +++ b/name-hash.c @@ -5,6 +5,9 @@ * * Copyright (C) 2008 Linus Torvalds */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" diff --git a/path.c b/path.c index a3bf25b7def..93491bab141 100644 --- a/path.c +++ b/path.c @@ -2,6 +2,8 @@ * Utilities for paths and pathnames */ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "abspath.h" #include "environment.h" diff --git a/preload-index.c b/preload-index.c index 63fd35d64b1..7926eb09a69 100644 --- a/preload-index.c +++ b/preload-index.c @@ -1,6 +1,9 @@ /* * Copyright (C) 2008 Linus Torvalds */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "pathspec.h" #include "dir.h" diff --git a/prompt.c b/prompt.c index 8935fe4dfb9..f21c5bf1c7e 100644 --- a/prompt.c +++ b/prompt.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "parse.h" #include "environment.h" diff --git a/refs/files-backend.c b/refs/files-backend.c index 1cff65f6ae5..1bbb550f3af 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "../git-compat-util.h" #include "../copy.h" #include "../environment.h" diff --git a/sparse-index.c b/sparse-index.c index 9958656ded1..542ca5f411c 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "gettext.h" diff --git a/statinfo.c b/statinfo.c index 3c6bc049c15..30a164b0e68 100644 --- a/statinfo.c +++ b/statinfo.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "environment.h" #include "statinfo.h" diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index bf0e23ed505..f57c8d706aa 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "test-tool.h" #include "abspath.h" #include "environment.h" diff --git a/tree-diff.c b/tree-diff.c index 9252481df36..5eab8af631b 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -1,6 +1,9 @@ /* * Helper functions for tree diff generation */ + +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "diff.h" #include "diffcore.h" diff --git a/userdiff.c b/userdiff.c index 989629149f6..d43d8360d17 100644 --- a/userdiff.c +++ b/userdiff.c @@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE + #include "git-compat-util.h" #include "config.h" #include "userdiff.h" From patchwork Thu Aug 29 09:39:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782883 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE53418F2D1 for ; Thu, 29 Aug 2024 09:39:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924354; cv=none; b=PsUzwYo41rswsd5KYMI6JRgna3UymdPOh/V5WXjJ3B9uE/uoDSLmf7IpeWvlUtX3yVBGIB1G5R8sBUK8vkxXQriEATmV+ZKdSFN19De0SWXpuOXMVrA51//beiyMKzy6zq5UCGi093AasdGCu4FuQ3+7scsfI/tT3Uz4aVITEjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924354; 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=AmpbiAWJmW4DTaNzdPWLj8pq11oSIzvaPePZMnIoum7eIWrwja1TY6Pa6y3UXwVXq4Yr2/s+izP/b1voKmAJt067pFNNumk02rtnx5ocowUuXPjhVMGWmLXG3oJ7NlgogjHNDY4CrtDLIZpnd64QL88584Ir+CrRICoEh71nW/c= 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=nELchdf9; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cnFBIjWv; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="nELchdf9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cnFBIjWv" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1428C1151CE6; Thu, 29 Aug 2024 05:39:12 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 29 Aug 2024 05:39:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924352; x=1725010752; bh=EqkRaVpezP 5Gle8sx/YgIgo3+DjDvKZHMRTI7S95LHg=; b=nELchdf9pQiP3jQ2b3Cgno8AQY aVlsBeEY+F82V/2aZnF/aijAu4LvR55zyaDbc8dtDeOnKIWjmEede4bQwMi7m3Zl tnqwLq2tzKILa+H/HBotPsGOfWcQh8f3sYbrraK//wlUMMyHY3Cw69fjF1Z5P/CU t7tb9Jqrwy9F69mAA8K/Y0XI+UTwgDt4uXy/M4YPGdWGYL+7iKyWH7yQVWGO0Gk5 udjkeH9N7Ti6A8Ve4av9/rxPNVrNtIXAwd4GvAnFs+aubKBz86wgQK9yJS2VekR8 d5XEIagAtM/LqHvTuY+PjQ811abDAKPmXCZsNcwv5Rog8UFG0KsWwkiiznfQ== 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=1724924352; x=1725010752; bh=EqkRaVpezP5Gle8sx/YgIgo3+DjD vKZHMRTI7S95LHg=; b=cnFBIjWv70uxvYLJmrP+e5M1AZhg+MdH+AzQxl+yDDgN oYZXHRYo645kVehuwmYUeC0gwr2IJBeBkRQxVIWyPIYXk6I3BV0JCK1nLYmgnXAe 1yfTCUdKyS1i44z2Ixx4H15/As8NjHo3JGpfDq3uBLB9XRSZGMVdHOlzzRfZFXQR +LN4Iv3VxevecUVJR3U9AKfxFjB5/L+3fAZQrPVIB4/x6IZMIITtGcCnEHY+9ZRu hcqEqrJSuarqXV/7AZYUmBJ0EwGBheqGYVxwCyHMzcX+3aWqwYrKZYaxty88hBuV IqaB/FOfkoOJzCRsxaljSFPUQ3N7ac4z9DRgWu+wAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id eaf0917c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:03 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:10 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 14/21] repo-settings: split out declarations into a standalone header Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: While we have "repo-settings.c", we do not have a corresponding "repo-settings.h" file. Instead, this functionality is part of the "repository.h" header, making it hard to discover. Split the declarations out of "repository.h" and create a standalone header file with them. Signed-off-by: Patrick Steinhardt --- repo-settings.c | 1 + repo-settings.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ repository.h | 51 +------------------------------------------- 3 files changed, 58 insertions(+), 50 deletions(-) create mode 100644 repo-settings.h diff --git a/repo-settings.c b/repo-settings.c index 2b4e68731be..6165546e80a 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "config.h" +#include "repo-settings.h" #include "repository.h" #include "midx.h" diff --git a/repo-settings.h b/repo-settings.h new file mode 100644 index 00000000000..ff20a965373 --- /dev/null +++ b/repo-settings.h @@ -0,0 +1,56 @@ +#ifndef REPO_SETTINGS_H +#define REPO_SETTINGS_H + +struct fsmonitor_settings; +struct repository; + +enum untracked_cache_setting { + UNTRACKED_CACHE_KEEP, + UNTRACKED_CACHE_REMOVE, + UNTRACKED_CACHE_WRITE, +}; + +enum fetch_negotiation_setting { + FETCH_NEGOTIATION_CONSECUTIVE, + FETCH_NEGOTIATION_SKIPPING, + FETCH_NEGOTIATION_NOOP, +}; + +struct repo_settings { + int initialized; + + int core_commit_graph; + int commit_graph_generation_version; + int commit_graph_changed_paths_version; + int gc_write_commit_graph; + int fetch_write_commit_graph; + int command_requires_full_index; + int sparse_index; + int pack_read_reverse_index; + int pack_use_bitmap_boundary_traversal; + int pack_use_multi_pack_reuse; + + /* + * Does this repository have core.useReplaceRefs=true (on by + * default)? This provides a repository-scoped version of this + * config, though it could be disabled process-wide via some Git + * builtins or the --no-replace-objects option. See + * replace_refs_enabled() for more details. + */ + int read_replace_refs; + + struct fsmonitor_settings *fsmonitor; /* lazily loaded */ + + int index_version; + int index_skip_hash; + enum untracked_cache_setting core_untracked_cache; + + int pack_use_sparse; + enum fetch_negotiation_setting fetch_negotiation_algorithm; + + int core_multi_pack_index; +}; + +void prepare_repo_settings(struct repository *r); + +#endif /* REPO_SETTINGS_H */ diff --git a/repository.h b/repository.h index c603e969ae7..24a66a496a6 100644 --- a/repository.h +++ b/repository.h @@ -2,9 +2,9 @@ #define REPOSITORY_H #include "strmap.h" +#include "repo-settings.h" struct config_set; -struct fsmonitor_settings; struct git_hash_algo; struct index_state; struct lock_file; @@ -14,59 +14,12 @@ struct submodule_cache; struct promisor_remote_config; struct remote_state; -enum untracked_cache_setting { - UNTRACKED_CACHE_KEEP, - UNTRACKED_CACHE_REMOVE, - UNTRACKED_CACHE_WRITE, -}; - -enum fetch_negotiation_setting { - FETCH_NEGOTIATION_CONSECUTIVE, - FETCH_NEGOTIATION_SKIPPING, - FETCH_NEGOTIATION_NOOP, -}; - enum ref_storage_format { REF_STORAGE_FORMAT_UNKNOWN, REF_STORAGE_FORMAT_FILES, REF_STORAGE_FORMAT_REFTABLE, }; -struct repo_settings { - int initialized; - - int core_commit_graph; - int commit_graph_generation_version; - int commit_graph_changed_paths_version; - int gc_write_commit_graph; - int fetch_write_commit_graph; - int command_requires_full_index; - int sparse_index; - int pack_read_reverse_index; - int pack_use_bitmap_boundary_traversal; - int pack_use_multi_pack_reuse; - - /* - * Does this repository have core.useReplaceRefs=true (on by - * default)? This provides a repository-scoped version of this - * config, though it could be disabled process-wide via some Git - * builtins or the --no-replace-objects option. See - * replace_refs_enabled() for more details. - */ - int read_replace_refs; - - struct fsmonitor_settings *fsmonitor; /* lazily loaded */ - - int index_version; - int index_skip_hash; - enum untracked_cache_setting core_untracked_cache; - - int pack_use_sparse; - enum fetch_negotiation_setting fetch_negotiation_algorithm; - - int core_multi_pack_index; -}; - struct repo_path_cache { char *squash_msg; char *merge_msg; @@ -273,8 +226,6 @@ int repo_read_index_unmerged(struct repository *); */ void repo_update_index_if_able(struct repository *, struct lock_file *); -void prepare_repo_settings(struct repository *r); - /* * Return 1 if upgrade repository format to target_version succeeded, * 0 if no upgrade is necessary, and -1 when upgrade is not possible. From patchwork Thu Aug 29 09:39:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782884 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0634818FC84 for ; Thu, 29 Aug 2024 09:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924357; cv=none; b=rl1ynZ28LBAmrnFj2dzWo0+Jjm5i3YVphk9SxLwglTsOn/4qYZziaxX5Eh3aBAlvviOqfG1+Ihvw+nDtLTxHNqvL+Qh8TXmMTaBNFv0bFXeDKVCf487uHQyaidXsz6/M6XeNP06FkjWvFX8mEv0gV1Z3F6w7Of0z6bfRG3Wt3Qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924357; 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=cYJQljqP0hxDOxwzdHZsJDHLWbVk+2T9CQVqUkFdtpxKeT1ilJ4GYRxn/AR4S2ybKwaWC4Rtl477OVjrKC2XK/YnZGCd8n303tdT/R4m9e58ZvFwL5fM2VXb0tjY2E51SitHJbxBsB8NdB1SO1H7ZNyUKAmI3PtbFY2660V12Q4= 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=Sj/YGSkB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k7CCHGrA; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Sj/YGSkB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k7CCHGrA" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 138D71151CC3; Thu, 29 Aug 2024 05:39:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 29 Aug 2024 05:39:15 -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=1724924355; x=1725010755; bh=JTYkqay8tG Kra5vGqEltXTgHjzaFkvjI4FmWTrbSPgE=; b=Sj/YGSkBW7a/BXnpaCzlnuYnkv BjzEomXDrosjOZ/XsIuhv5UgronOg+5OrYmrRLEmVwUn5QX63sBiAHF8XGjbdSQa dWc1UQLf6kWh4xbTwFOzuFtFBgrHvFp9gpsqDdDKddWAL6S22TNNwGsm3HuTtPxt rMtikxz1C3IJUkyDc1nUZ0nxegIeDnizt+U9BcX1edPrc3T+YhhuoV1gpeM2HmvE cxHVsyedJK5MKcuB8BJlQjyScmUaQYhNBX/8kjTnXewAjPFKU0OII+FLdEnrQa6l twi5Z1asWgR3hrAIRpBK3uuNiOhvb0MdOM5raZrp7YxX0Hwc6GU0upH4Txqg== 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=1724924355; x=1725010755; bh=JTYkqay8tGKra5vGqEltXTgHjzaF kvjI4FmWTrbSPgE=; b=k7CCHGrAUTOWnQOZHBIRBA4fgr5Ox9NLHnYjae/gk1Ey hR72zbGt+V4K84DJNGMbot5L92VUOssG7TZxF0SfIMpywy6BZv3FCFUumxFuRiUX rQELgVFvr935pyAq0RAAilkAXEMhUyJWAlCFCNdLUEmvHn11XtAKaaYHx4gbni2y Fqae1xHUQKpdB9ha5RX6aOH1zgKbPerf0WxJojTggKxFrszlISvv6/OHH4XN3vL3 qePPiStF1IMOiNz9Ex5AbTm5T35UpAZyvR9mJSdCJXwCop92rm89YSZhqgKl1iTk MOyD+oPPd8GFFUhg4B8PtA2YgiRPxM4FX5Iw8Vx2dw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:14 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c193a4b2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:06 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 15/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 Thu Aug 29 09:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782885 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 E9E6218FC93 for ; Thu, 29 Aug 2024 09:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924360; cv=none; b=bng4Cvwc5965MgWkNe4MZOeGXoud1pCbZQMAlYVx4xboFUREcXFg/CsSEG3JXmKKQ+tRH4RTflzwESfhdGySKBHx4OyTlE/iYrJCTT6wN5LrCaHqy+egiMZ6Xf+z8U4I3JK4JEVpHvTrc86S01BiDKiqu66gJhUq6oHfgqRdx6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924360; c=relaxed/simple; bh=GUyIfW6CDxEdHvtnqHtKMLzImLo3kOaGCUgfdjpKoBI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FmNyiiYvimep9IfMWf8EA5NgxgrTWGD9/SHf8CcKrP+n558diYG21r+BM/1E6L7RXdBAtnK8NfRNydLuGl55C/KO/xJkm0RdYbYy711KpPae7xAMfWn21Gc64eDPjJLmCQCKS6B96PYfCcDYMaZm+7xfqRB52r39bX3qcl04LCY= 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=M26m+6jl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=heSAj11S; arc=none smtp.client-ip=103.168.172.144 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="M26m+6jl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="heSAj11S" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 1BE531390160; Thu, 29 Aug 2024 05:39:18 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 29 Aug 2024 05:39: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=1724924358; x=1725010758; bh=qH4ofANSUL AAJLhYZ5RTn1IbVE0EY6y7lCCY4ViaQYE=; b=M26m+6jlvBLr8g3ernGWtWadrU 9g98Mv5ETXl0iq07KGFqKWLsDb+FiTXOgBRsWp8rk/L9mTLcCmLfLfJjhQGKcu/0 IU8zoYSE8sf9Kx/o83PCK2ryu/k8Z0kmCJYZEgwjcXo14nj7kjHxWREKQT/wdXdS NNYHtOc4+M27/7yD3bhYB2w/Kh1llTNS5hvc4hjoS9Rqy3qM+zwBOFEW4pycjioH uRP6fLeeehp4qE3XFFYU7zXdE6UcAFvbPAl2ta7jklQmUECIgsc4mtbMB9HDc6kh +UWBcmWZ3GsUHRgLkwkD7ig0aYBxXD0xcNFZXjHDXNg7Ya6xQfltdAwBU/tg== 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=1724924358; x=1725010758; bh=qH4ofANSULAAJLhYZ5RTn1IbVE0E Y6y7lCCY4ViaQYE=; b=heSAj11SLCb6vJPemOjS0t5frAguGH52u17TNEsdg3KI tp8huslFd5ITpOvxSIz85XJs+cKLEzW1hUO0N2Gk+I/FNphsityYRVxTJsv+R0U0 eyoQFCv754qBQiqkyxFjBdQQYYPngM80veLQlLSdoWKlEuY+kvp9MwhkkijVsnZy RrEA8VB8IYHAKKUb184JZ2dld5ar9ofs425rdmj+P37cup/gclp6TGVM6DJimQ6k PDM4piUaa9zZeQoB1Ruz/aTTtb3yOAf9uC3J9/ImnTNkVj7q7n0Nb9ZzfsVpotKf Hsl5DrLxBGfCri+F/3fcuOTBOr3SJ0xiPmqVSRMp7g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:17 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 815fe078 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:08 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 16/21] refs: stop modifying global `log_all_ref_updates` variable Message-ID: <626e24aac7a3b38b427f91ea18da107452a5193a.1724923648.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 | 2 +- environment.h | 8 ++------ refs.c | 3 ++- refs.h | 4 +++- refs/files-backend.c | 22 +++++++++++----------- refs/reftable-backend.c | 12 +++++++----- repo-settings.h | 7 +++++++ 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 4cfe6fab505..a0214486471 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -954,7 +954,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..822e0063ef6 100644 --- a/refs.c +++ b/refs.c @@ -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..c143cde8aa4 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -1443,6 +1443,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 +1587,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 +1604,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 +1703,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 +1802,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 +1890,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 +1898,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 +1931,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 ff20a965373..736968490a3 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -16,6 +16,13 @@ enum fetch_negotiation_setting { FETCH_NEGOTIATION_NOOP, }; +enum log_refs_config { + LOG_REFS_UNSET = -1, + LOG_REFS_NONE = 0, + LOG_REFS_NORMAL, + LOG_REFS_ALWAYS +}; + struct repo_settings { int initialized; From patchwork Thu Aug 29 09:39: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: 13782886 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDC8318DF88 for ; Thu, 29 Aug 2024 09:39:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924364; cv=none; b=sLh062M4a8R1FIWodWktL8CcLpQuATf5MtVpg+HH/Mx/phnY94cRrqWvp/sqvfhS22D1S9RTTz9EWKbnwRAvNixz2AMkcSHrOkCIRt9Cfhgcwy3tU2fxZBh6QgUI6Xm3Jvx9uoFN0MPrUKp+SProhdG/gADhzkZdGCbpByD8qow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924364; c=relaxed/simple; bh=QhOmx/aIXGPfrHSFpaXz6bF1jBsWQW2M4ag8Rwp1bkg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eUo84muSe+5XExZgth42vRgZCft/G6CH4oShLq5p4Z9VkQx5s2Dg2tD4XcD/8VU7fAO5rbBmBsG0CNDejLPgOZIbbFutH+2qfGcZOvlhFX8muchxC4feQkiFFERg9WZE9SQPVDc9Yt2MbTOSyzDGztHAo/2fmAbl+Fsfbk0egfM= 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=Mgi8fiUj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=miAXi8HY; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Mgi8fiUj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="miAXi8HY" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 23756114AB22; Thu, 29 Aug 2024 05:39:22 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 29 Aug 2024 05:39:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924362; x=1725010762; bh=7DhmpHsQgE H8ppZupZ/aV81ATaprt7JBx1niZUk91U8=; b=Mgi8fiUjjrTzokqwMtvwX5IEBa ua17sF5rpc1NHn0EU4m80E+qSGOGavJuzDR3gcPekt7oOt7FvrGF7juEcTFmLzW6 XoNaOHZF2BB6l7Y4hvL0QCtE/RQ3lJV/lg1sSN6y5aaGU6oTc1WztsQb0kUIwnZM c+jQwlk1F0rmuEFJVQwROVM9qLdAXqN0SiXdFBM/+z1Evl8djPdqftiJRQ4VYl8X UKBKahowJuUDCWCmbNvp1LbLiJ6twQTyWGXH8fR5ETB7nIXnC8IRd2WWvBnLi/O3 pzWxxTiNuWhehb077KWGy1IAN8JT0ozVYzcHtV428+KPlpm1BH+rztHJWCwg== 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=1724924362; x=1725010762; bh=7DhmpHsQgEH8ppZupZ/aV81ATapr t7JBx1niZUk91U8=; b=miAXi8HYUNV/HRNn8+igeukoAnrq2WV8AuP0NdeGTUQ/ zM7Xs2+lLiUBXEZbHz0u4SbIsbzKmFyEpTu90I9cPgUHi+GJ/KPmlKBRKhnGqhrO YefFRO/BUJsvpBqjz6UvtBGMgm0HfmndSi8un7S1xtQ5uILKiNrO9qnTpIdvJSii jbCU7/DKxxfkWpLmJq2lBOzFIZ5/ljLwhh3XAn8rB+rpokG2P3JPGzaWP71F43Fh +gNY8Wh8tn90Cup3tuEQl+VBlx53Ht/B+RDi6APHJ4BgoojlF851yXnw5stJExeS 7MHtHcRyw/dOoGb7OjSqDFeMgOatuD9tFKdt6dgE1A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:21 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 01e51b30 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:12 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 17/21] repo-settings: track defaults close to `struct repo_settings` 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 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 736968490a3..d03b6e57f0c 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -57,6 +57,11 @@ struct repo_settings { int core_multi_pack_index; }; +#define REPO_SETTINGS_INIT { \ + .index_version = -1, \ + .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ + .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ +} void prepare_repo_settings(struct repository *r); From patchwork Thu Aug 29 09:39:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782887 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0486B18FDC5 for ; Thu, 29 Aug 2024 09:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924367; cv=none; b=EuxV8JNPJBAcpak/kG2GKQHOb5GGMpgY6jnv8Xq8eVvLT4TLoFJV3lh3OxnBRo8qArQTBwuBdS5fHqCs1WJYrTb25le22QenJ1zzwDR1jSYt7xC3VR1v5M66o7ETRl1gRb/hlPm/wrV5zYxM+0I1DYgbj4n+aHIl4IgrH827EGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924367; c=relaxed/simple; bh=vFyjcGoh5HDlkIro+NqtwKY+IGL1yij0QuZ0cz60pfc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZGejwxvmSBLNShUyi5L8XYAb65K8WirbuWsbwC6ja8dzZyorozYKena+PfjFAsBhaGqWkE7tpCRiWPNVRbJ371e4YB/rOrWoGhSmDMC44/J8m42HxOqrECUU3UQ7WVjffp5h5uRKYKglacf6vB8GAQGbkLKgGK38cUZIcG1cYXk= 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=e85ETykW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=qIWKEBup; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="e85ETykW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="qIWKEBup" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 333111151AB9; Thu, 29 Aug 2024 05:39:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 29 Aug 2024 05:39: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=1724924365; x=1725010765; bh=wj+mxw2cA9 x0EHxgij7SOhJAZxcM7/4jCuPYMsiaPak=; b=e85ETykWdFyrcpVyoCyyhXBMp7 pBTDDKBHOHkhBIhbIkf4kT5WiY/TIN/TYWLH3H+8ga0l4etAcwtua4/8bNQsB++8 Ck3B0e6ylJnCOZjUEr1KIyTl+EJyTIXaZaUEly14yOokLmT28qCSJoz3Osg3k6r9 IMKxvDvbtoN8oAn7KWeG0bOyNBE4u/7CuQcw342V8/IZ2pRkQ5wcwgcJzi9z6xxw RVVuVIUcvzc07+8G2psBJoMJtGvJ+5T+kYudSVbZkOHxtiwQNDETcpeMi92Cn3Xr d/ytNg10rRvxgCX6bCvLNv5lri+lhFULgRt4EA/HfPX8qWVoBw63jwsTP6Dw== 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=1724924365; x=1725010765; bh=wj+mxw2cA9x0EHxgij7SOhJAZxcM 7/4jCuPYMsiaPak=; b=qIWKEBups3xgon+JwFhUx3dI5zFnq13oE590h4waNnUd oMslmDskNAgv58CLxG3eQUE7P57KAnOPKVBOXd0lAMSByxaJRtyYQwzfeXntiOD4 8pPsdSAmB+b6jYOhQoaDQpT8M/+5/XorkbGjuuK53dnIFzqXsPwSQ+avn/Ao3Us4 EngR6KxpGMp6salXaUQQW6TKnRST9GzAZZZIDVj2wMGVzBS1MoX/3AR/+4qAX1Pa FH0l540ZWgFd/rAK38ytjwCuzuY9We+QunmkL88mSPMN9mzFwrs9q7A2UyrDAb3y yT7pAsWgTZVTXanmJLvl1bmLTwyIXA7oZYnGWaxVUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:24 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id c0cd4474 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:15 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:22 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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 a0214486471..84a2dbeee79 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -950,6 +950,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 c143cde8aa4..6ad495744b0 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -74,6 +74,7 @@ struct files_ref_store { unsigned int store_flags; char *gitcommondir; + enum log_refs_config log_all_ref_updates; struct ref_cache *loose; @@ -106,6 +107,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", @@ -1703,7 +1705,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 a4a9fbb3a2a..c37dc4f7c48 100644 --- a/setup.c +++ b/setup.c @@ -2354,7 +2354,7 @@ static int create_default_files(const char *template_path, else { git_config_set("core.bare", "false"); /* allow template config file to override the default */ - if (log_all_ref_updates == LOG_REFS_UNSET) + if (repo_settings_get_log_all_ref_updates(the_repository) == LOG_REFS_UNSET) git_config_set("core.logallrefupdates", "true"); if (needs_work_tree_config(original_git_dir, work_tree)) git_config_set("core.worktree", work_tree); From patchwork Thu Aug 29 09:39:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782888 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 D361119049E for ; Thu, 29 Aug 2024 09:39:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924370; cv=none; b=keVoFtTYYSNlD1lGKUYSZas2Y7+0TR9FJhqp85+8pPLrF4xbniqkQJwK4TP7xEbWffGeGPSmbedHY/aXbqoVDUECrtbqwkoIfxYV3Q2IhQ5cyXbFpnknhLsuuIuZgdKROYV9f2cEWQAnChUsZt/pmaPYMNqJWp7jlhmQsh6zxzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924370; c=relaxed/simple; bh=y1oewqVxCKNDiUZjtNoeQa66fZCYFAQJxV6DKpu0Dps=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Qsy6Yps4Bb4kFBfZiUFRCxeXe8AlrkklI4WCCbW2wxXVYCiBxOwFbY23C6y/V1cT2gkcjcYMdyIevaeikB2OzhBF8NmuaesXrLZnxFUK7yatL2I2jr04s2u80Zx0oQvB2YEBsJQKWaBW0Wg+Y91tLmQuJaeRL2BdEW7zgF5Do4s= 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=VBSG5uwM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HMOSQyk0; arc=none smtp.client-ip=103.168.172.144 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="VBSG5uwM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HMOSQyk0" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 34B061390119; Thu, 29 Aug 2024 05:39:28 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Thu, 29 Aug 2024 05:39:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924368; x=1725010768; bh=naIkpSGSXB 0K+OQko4obu3+kcDOEmpUyhNpXDgFl3D0=; b=VBSG5uwMl+YfTONdMSrjlKzWBx IKU/b9xOEIGSMJyzhuQ2SX5/1X4Eh9EhUF/uPrx78Z6ASxRyAFLWWH0/MUGBnRph 2E2CePu+Uw9BtiVMHQEo4svdGwAjMX5LR1nvYNFw+eh5RH9ItWkUsGTx8eEFfpxT 36SqtbiL42Ny8bXULAlxf5qNswZrZX/JqzURySCCUYNbbYrr0OJ9kzgxbgQ3ii1q 1s45TRr7yeaQOxINR6kGMrdVlOklkG4kXVQATY/YY6yBGxH/Cy0HoGORINiepNjW uEQtc8iTDeDSDyFt0pcV1dTeML/SZI4h7872q6gP30jTgvPCfQ749qi4SrNg== 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=1724924368; x=1725010768; bh=naIkpSGSXB0K+OQko4obu3+kcDOE mpUyhNpXDgFl3D0=; b=HMOSQyk0Q2Ml9oGDIN+UT7tGrv1eXxa1JIUzQv4E0BJK zKC3a8PSWuJL7GGTAKIfc0JE1jHQc9ZGFYhJYJL1FMGP4Xa8mkk5CBm/l/m3xG2g kZDTZxV4HSnsV6ZnPjCxvXWPVD0CgTaFLkzru+i2TH9rey3jSMb5fLw4LFNaGStJ Fz6n5Dh+qD6d8vxYr1w98IpmxLI7Xvhd1hWO7g/eSGOg0//SZCrHixiaekOuO1ny 19rAwp9ZnmMaTxlW507B62bHR9Azh94Q4Dc4OWUKVao7zC513NQG+iFhKXD3igQY dSGZC+Y26DV1QLt73fYHSRqJtyo2YiqtnJwMjCcITw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:27 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6c9ed07c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:18 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:25 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 19/21] environment: stop storing "core.preferSymlinkRefs" globally Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Same as the preceding commit, storing the "core.preferSymlinkRefs" value globally is misdesigned as this setting may be set per repository. There is only a single user of this value anyway, namely the "files" backend. So let's just remove the global variable and read the value of this setting when initializing the backend. Signed-off-by: Patrick Steinhardt --- config.c | 5 ----- environment.c | 1 - environment.h | 1 - refs/files-backend.c | 5 ++++- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 47101c3e977..a59890180a3 100644 --- a/config.c +++ b/config.c @@ -1447,11 +1447,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.prefersymlinkrefs")) { - prefer_symlink_refs = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "core.warnambiguousrefs")) { warn_ambiguous_refs = git_config_bool(var, value); return 0; diff --git a/environment.c b/environment.c index 992d87e0d60..6805c7b01df 100644 --- a/environment.c +++ b/environment.c @@ -34,7 +34,6 @@ int has_symlinks = 1; int minimum_abbrev = 4, default_abbrev = -1; int ignore_case; int assume_unchanged; -int prefer_symlink_refs; int is_bare_repository_cfg = -1; /* unspecified */ int warn_ambiguous_refs = 1; int warn_on_object_refname_ambiguity = 1; diff --git a/environment.h b/environment.h index 315fd319951..0cab644e2d3 100644 --- a/environment.h +++ b/environment.h @@ -156,7 +156,6 @@ extern int has_symlinks; extern int minimum_abbrev, default_abbrev; extern int ignore_case; extern int assume_unchanged; -extern int prefer_symlink_refs; extern int warn_ambiguous_refs; extern int warn_on_object_refname_ambiguity; extern char *apply_default_whitespace; diff --git a/refs/files-backend.c b/refs/files-backend.c index 6ad495744b0..b8a0b27d24e 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" @@ -75,6 +76,7 @@ struct files_ref_store { char *gitcommondir; enum log_refs_config log_all_ref_updates; + int prefer_symlink_refs; struct ref_cache *loose; @@ -108,6 +110,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", @@ -2941,7 +2944,7 @@ static int files_transaction_finish(struct ref_store *ref_store, * We try creating a symlink, if that succeeds we continue to the * next update. If not, we try and create a regular symref. */ - if (update->new_target && prefer_symlink_refs) + if (update->new_target && refs->prefer_symlink_refs) if (!create_ref_symlink(lock, update->new_target)) continue; From patchwork Thu Aug 29 09:39:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782889 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 F29D1190698 for ; Thu, 29 Aug 2024 09:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924372; cv=none; b=sPDt9wrxewvw/MxSgCd3tGLa5AElMSOrLpdUCxqi1I4x/KBRxTYSy3lnR+hbRbPHkhuRZloRvpASpfiHTBCm0NUlhSBnhOXOZan1LZealH2y4wX6NVx7H9/iQY3uM7HvnP6qSyJLECTim9885TSXLfh6h8UfpirL/MDqXC5e77E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924372; c=relaxed/simple; bh=Oc/TSoFv6/iYtIEW+1fOLOSoOCK73ggocGrkPK0LxE4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nih402mPHH73vsvZU4D4myF1SqDFOK1HEDUyzCFnCeRUymvaPJfS2S3eeB4uDL0bn3m8wLLt0lIh1AWziwnTE4BTzeMHmL87OaDcqonfxa5KYTbBCH6/HosT4nwv16BoamuOOFOXsQpYNUZtstD5gZpQoycn+HBVZPKY5DWA5VE= 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=qN+5KI2u; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XJH+AFUr; arc=none smtp.client-ip=103.168.172.144 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="qN+5KI2u"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XJH+AFUr" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 35BDB1390162; Thu, 29 Aug 2024 05:39:30 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Thu, 29 Aug 2024 05:39:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924370; x=1725010770; bh=WyNdldPUzz 5dqRYOdZvlKIwOlWCvnuUB+UnIKepSVCE=; b=qN+5KI2uL/SoDoRIlIG2xbar2L qlw/tpmJA+jgyFfuOrTKFKWS9Evnq5poWjYKHHfpkFGN1vUrMy2Xb107apmEkYgp g+jBkrRNOCID3E/AKxVsfY/HxSGvo0BOSRcgGTE7XcveHO6Qof/emuy7QjqaqNP5 V2+RvBSLPE5VwJcxsF2KTxsDFjVZUAJmrXdhjeL2hvwnXcwlukuwBzC+hgDzgxso 53Jb3tEgo7IbSiKndTDr75Egp54FaTALCs7cO4AAYX+We0/AV7GrfWOqwl/v2RT5 W4y3BADAI0d30nGECzGzz5VuWhDSpooRKT553UJmeqE6RAN92JXc/j2AoWbw== 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=1724924370; x=1725010770; bh=WyNdldPUzz5dqRYOdZvlKIwOlWCv nuUB+UnIKepSVCE=; b=XJH+AFUrLXwPl+MTJXGjRIzMQJ1xvV4aUzwTU/geZSNp oSXrbcwwAV6kQBOwEUcbNknsai8JusfiL8iYBBFd9IQrwxNUAYTRdb2PN0CFAnAL GSYsxsgDbrUPEmK6qnEefKZExBi3r52ryGqM5XdxCPdU2n2walfXSDMtrgqcFeTK /ZC3cqBOAJ+Il2hGe6Zh6kKPDV8k57kYP4rrB+KgKKtG91hDb7Qb/xKFy/9/teDg mFRPFglYowxz7SWYZ7QcKZRFowjnYNEYxatNZM0NoTWKOcnBRAspFWqEwrD7zSbk 27KTFenndeuViTJFu09QcMhZSla9zoQ7Cr0ng83iCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepudeffeetteekudekffevudefgfelhefgteffhfdvveff keevleevjeejfefgfeeinecuffhomhgrihhnpeifrghrnhgrmhgsihhguhhouhhsrhgvfh hsrdhinhhtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthho pegtrghlvhhinhifrghnsehgohhoghhlvgdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:29 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 482586d8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:21 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:28 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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 | 3 ++- config.c | 5 ----- environment.c | 1 - environment.h | 1 - object-name.c | 4 ++-- ref-filter.c | 2 +- refs.c | 4 ++-- repo-settings.c | 9 +++++++++ repo-settings.h | 4 ++++ 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 65b0b5e2c0a..bd06f6cc4c4 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -898,7 +898,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..baeed4deeed 100644 --- a/object-name.c +++ b/object-name.c @@ -959,7 +959,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 +1020,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..6a1f4c1ee98 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2160,7 +2160,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 822e0063ef6..bc348632121 100644 --- a/refs.c +++ b/refs.c @@ -730,7 +730,7 @@ int expand_ref(struct repository *repo, const char *str, int len, if (r) { if (!refs_found++) *ref = xstrdup(r); - if (!warn_ambiguous_refs) + if (!repo_settings_get_warn_ambiguous_refs(repo)) break; } else if ((flag & REF_ISSYMREF) && strcmp(fullref.buf, "HEAD")) { warning(_("ignoring dangling symref %s"), fullref.buf); @@ -775,7 +775,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len, if (oid) oidcpy(oid, &hash); } - if (!warn_ambiguous_refs) + if (!repo_settings_get_warn_ambiguous_refs(r)) break; } strbuf_release(&path); diff --git a/repo-settings.c b/repo-settings.c index 1322fd2f972..4699b4b3650 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -140,3 +140,12 @@ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *re return LOG_REFS_UNSET; } + +int repo_settings_get_warn_ambiguous_refs(struct repository *repo) +{ + prepare_repo_settings(repo); + if (repo->settings.warn_ambiguous_refs < 0) + repo_cfg_bool(repo, "core.warnambiguousrefs", + &repo->settings.warn_ambiguous_refs, 1); + return repo->settings.warn_ambiguous_refs; +} diff --git a/repo-settings.h b/repo-settings.h index 76adb96a669..51d6156a117 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -56,16 +56,20 @@ struct repo_settings { enum fetch_negotiation_setting fetch_negotiation_algorithm; int core_multi_pack_index; + int warn_ambiguous_refs; /* lazily loaded via accessor */ }; #define REPO_SETTINGS_INIT { \ .index_version = -1, \ .core_untracked_cache = UNTRACKED_CACHE_KEEP, \ .fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \ + .warn_ambiguous_refs = -1, \ } void prepare_repo_settings(struct repository *r); /* Read the value for "core.logAllRefUpdates". */ enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo); +/* Read the value for "core.warnAmbiguousRefs". */ +int repo_settings_get_warn_ambiguous_refs(struct repository *repo); #endif /* REPO_SETTINGS_H */ From patchwork Thu Aug 29 09:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13782890 Received: from fhigh5-smtp.messagingengine.com (fhigh5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07F3F1917DC for ; Thu, 29 Aug 2024 09:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924375; cv=none; b=K+/DVLCY3lqmedvH/G4zLxTwQa8GU2UzKARZYR5NbBxZFZI/xLt+/96aYa8fxm+d73ZC3+T/j6qc8Z+o05aAuGya+zyflvknvu3v+JpMMYux84/U6cUQVlb/7HNAZAsh7xhMfnIyDJ9G8UKjnazjKI/RrQZPBirAOoj8WjDit1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724924375; 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=kWd4rEKblogeGYbGZpyJYUQZYuoMUOLqHQ/56oeTF88XdxYXE5oG/mLwtX6UKt41seOwEens7vkvPCNDTHt7Lhzr6U6l8WFehkKbKggewT6G05DHWyK7arVDtUkk/4InrmRGkikX1YKH3Fh1XfxnMc6YkLbWmPSsugX5tBB7BD8= 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=aXeH9nB0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ZcwbzKDG; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="aXeH9nB0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ZcwbzKDG" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3CF161151C1D; Thu, 29 Aug 2024 05:39:33 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 29 Aug 2024 05:39:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1724924373; x=1725010773; bh=5yq6q6JNiw d4+YshgH/avjb7HWZjW0RZYeknNET2kqE=; b=aXeH9nB02uDinjlpXE9MSs7gNy BEno1LuvJnHHdnYZ0jZM4u8LBYBeMXYas5fbvsfbxXpxu6+Y4OyxTL/XTC80IpsL j8W4LmOIJSsdJ837tU1rm8S8LN3xFm/rjl//DWtHe6KpcixUjy2eDkjrVDfKN6iX vZCb78th+CVYUy5pEloZY50PuBUCGMRmW/mTQSDSsmJb7iOuBsTnsvXZsdM+tC5x 7jVzDHtFRkBEUhfWi2+XAsevVh+YnmDPA4pOFLwSj983x2BOJAWdLK6jhTPP0eyq IQShkVnd3/XyYwtMjlLne0UPAvnUoW5O66GJHY+wWHyrxcfL6HfgNhhtNBDQ== 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=1724924373; x=1725010773; bh=5yq6q6JNiwd4+YshgH/avjb7HWZj W0RZYeknNET2kqE=; b=ZcwbzKDGXWSuiP6u7GXUmfZdwj0dUm88R+f0J6xV0m56 LMurnHqhD56uXw+PjlmGWyVTu06QET4BqWbe2GJVVqfy5UIF42NgBr1vkYFuN0I7 FvfQwVSoFneP1uNd6sX8IyfPZgN93ziWgtTxnTPzeqmNSr2u+x+idcVe16PIOP6y 9x4B8wkbaTEUQztMSnshDLqVQjwzH0ieQniCMOFMXHiIdyoucptuP/mvS0dYFUb0 9H3/hYzgy1be4tSpXmdZ5GJ98MBpmpiGwTgN1ONVrhijl/NRxwinWaxYrhzarKgA LvfcUKwyF+d1w1BkxzrHSc7W8S13Mlzeb38g6gANpg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepgeenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepvddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtoheptggrlhhvihhnfigrnhesghhoohhglhgvrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Aug 2024 05:39:32 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 128652f5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Aug 2024 09:39:24 +0000 (UTC) Date: Thu, 29 Aug 2024 11:39:31 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Calvin Wan Subject: [PATCH 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