From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Calvin Wan <calvinwan@google.com>
Subject: [PATCH 02/21] environment: make `get_git_common_dir()` accept a repository
Date: Thu, 29 Aug 2024 11:38:26 +0200 [thread overview]
Message-ID: <cdd6dd308c3e1dc0e53fe2d66f8dd0a2b4a9fb22.1724923648.git.ps@pks.im> (raw)
In-Reply-To: <cover.1724923648.git.ps@pks.im>
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 <ps@pks.im>
---
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);
--
2.46.0.421.g159f2d50e7.dirty
next prev parent reply other threads:[~2024-08-29 9:38 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 9:38 [PATCH 00/21] environment: guard reliance on `the_repository` Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 01/21] environment: make `get_git_dir()` accept a repository Patrick Steinhardt
2024-08-29 20:15 ` Justin Tobler
2024-08-30 7:42 ` Patrick Steinhardt
2024-08-29 9:38 ` Patrick Steinhardt [this message]
2024-08-29 9:38 ` [PATCH 03/21] environment: make `get_object_directory()` " Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 04/21] environment: make `get_index_file()` " Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 05/21] environment: make `get_graft_file()` " Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 06/21] environment: make `get_git_work_tree()` " Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 07/21] config: document `read_early_config()` and `read_very_early_config()` Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 08/21] config: make dependency on repo in `read_early_config()` explicit Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 09/21] environment: move `odb_mkstemp()` into object layer Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 10/21] environment: make `get_git_namespace()` self-contained Patrick Steinhardt
2024-08-29 9:38 ` [PATCH 11/21] environment: move `set_git_dir()` and related into setup layer Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 12/21] environment: reorder header to split out `the_repository`-free section Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 13/21] environment: guard state depending on a repository Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 14/21] repo-settings: split out declarations into a standalone header Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 15/21] branch: stop modifying `log_all_ref_updates` variable Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 16/21] refs: stop modifying global " Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 17/21] repo-settings: track defaults close to `struct repo_settings` Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 18/21] environment: stop storing "core.logAllRefUpdates" globally Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 19/21] environment: stop storing "core.preferSymlinkRefs" globally Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 20/21] environment: stop storing "core.warnAmbiguousRefs" globally Patrick Steinhardt
2024-08-29 9:39 ` [PATCH 21/21] environment: stop storing "core.notesRef" globally Patrick Steinhardt
2024-08-29 19:59 ` [PATCH 00/21] environment: guard reliance on `the_repository` Junio C Hamano
2024-08-30 6:58 ` Patrick Steinhardt
2024-08-30 16:32 ` Junio C Hamano
2024-09-02 9:29 ` Patrick Steinhardt
2024-08-30 9:08 ` [PATCH v2 " Patrick Steinhardt
2024-08-30 9:08 ` [PATCH v2 01/21] environment: make `get_git_dir()` accept a repository Patrick Steinhardt
2024-09-11 21:12 ` karthik nayak
2024-09-12 11:17 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 02/21] environment: make `get_git_common_dir()` " Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 03/21] environment: make `get_object_directory()` " Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 04/21] environment: make `get_index_file()` " Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 05/21] environment: make `get_graft_file()` " Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 06/21] environment: make `get_git_work_tree()` " Patrick Steinhardt
2024-09-11 15:15 ` Justin Tobler
2024-09-12 11:16 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 07/21] config: document `read_early_config()` and `read_very_early_config()` Patrick Steinhardt
2024-09-11 15:59 ` Justin Tobler
2024-09-12 11:17 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 08/21] config: make dependency on repo in `read_early_config()` explicit Patrick Steinhardt
2024-09-04 1:46 ` James Liu
2024-09-04 7:14 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 09/21] environment: move `odb_mkstemp()` into object layer Patrick Steinhardt
2024-09-11 21:26 ` karthik nayak
2024-09-12 11:17 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 10/21] environment: make `get_git_namespace()` self-contained Patrick Steinhardt
2024-09-11 16:21 ` Justin Tobler
2024-08-30 9:09 ` [PATCH v2 11/21] environment: move `set_git_dir()` and related into setup layer Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 12/21] environment: reorder header to split out `the_repository`-free section Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 13/21] environment: guard state depending on a repository Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 14/21] repo-settings: split out declarations into a standalone header Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 15/21] repo-settings: track defaults close to `struct repo_settings` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 16/21] branch: stop modifying `log_all_ref_updates` variable Patrick Steinhardt
2024-09-11 17:14 ` Justin Tobler
2024-09-12 11:17 ` Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 17/21] refs: stop modifying global " Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 18/21] environment: stop storing "core.logAllRefUpdates" globally Patrick Steinhardt
2024-09-12 11:10 ` karthik nayak
2024-08-30 9:09 ` [PATCH v2 19/21] environment: stop storing "core.preferSymlinkRefs" globally Patrick Steinhardt
2024-08-30 9:09 ` [PATCH v2 20/21] environment: stop storing "core.warnAmbiguousRefs" globally Patrick Steinhardt
2024-09-04 2:10 ` James Liu
2024-08-30 9:10 ` [PATCH v2 21/21] environment: stop storing "core.notesRef" globally Patrick Steinhardt
2024-09-04 2:12 ` [PATCH v2 00/21] environment: guard reliance on `the_repository` James Liu
2024-09-04 7:14 ` Patrick Steinhardt
2024-09-12 11:14 ` karthik nayak
2024-09-12 11:17 ` Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 01/21] environment: make `get_git_dir()` accept a repository Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 02/21] environment: make `get_git_common_dir()` " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 03/21] environment: make `get_object_directory()` " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 04/21] environment: make `get_index_file()` " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 05/21] environment: make `get_graft_file()` " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 06/21] environment: make `get_git_work_tree()` " Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 07/21] config: document `read_early_config()` and `read_very_early_config()` Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 08/21] config: make dependency on repo in `read_early_config()` explicit Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 09/21] environment: move object database functions into object layer Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 10/21] environment: make `get_git_namespace()` self-contained Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 11/21] environment: move `set_git_dir()` and related into setup layer Patrick Steinhardt
2024-09-12 11:29 ` [PATCH v3 12/21] environment: reorder header to split out `the_repository`-free section Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 13/21] environment: guard state depending on a repository Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 14/21] repo-settings: split out declarations into a standalone header Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 15/21] repo-settings: track defaults close to `struct repo_settings` Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 16/21] branch: stop modifying `log_all_ref_updates` variable Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 17/21] refs: stop modifying global " Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 18/21] environment: stop storing "core.logAllRefUpdates" globally Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 19/21] environment: stop storing "core.preferSymlinkRefs" globally Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 20/21] environment: stop storing "core.warnAmbiguousRefs" globally Patrick Steinhardt
2024-09-12 11:30 ` [PATCH v3 21/21] environment: stop storing "core.notesRef" globally Patrick Steinhardt
2024-09-12 20:40 ` [PATCH v3 00/21] environment: guard reliance on `the_repository` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cdd6dd308c3e1dc0e53fe2d66f8dd0a2b4a9fb22.1724923648.git.ps@pks.im \
--to=ps@pks.im \
--cc=calvinwan@google.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).