Skip to content

Commit edc2c92

Browse files
pks-tgitster
authored andcommitted
environment: make get_git_work_tree() accept a repository
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14c90ac commit edc2c92

18 files changed

+36
-34
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
10811081
path = add_prefix(prefix, argv[1]);
10821082
argv[1] = argv[2];
10831083
} else { /* (2a) */
1084-
if (argc == 2 && is_a_rev(argv[1]) && !get_git_work_tree())
1084+
if (argc == 2 && is_a_rev(argv[1]) && !repo_get_work_tree(the_repository))
10851085
die("missing <path> to blame");
10861086
path = add_prefix(prefix, argv[argc - 1]);
10871087
}

builtin/difftool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
378378
struct hashmap wt_modified, tmp_modified;
379379
int indices_loaded = 0;
380380

381-
workdir = get_git_work_tree();
381+
workdir = repo_get_work_tree(the_repository);
382382

383383
/* Setup temp directories */
384384
tmp = getenv("TMPDIR");
@@ -739,7 +739,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
739739
if (!no_index){
740740
setup_work_tree();
741741
setenv(GIT_DIR_ENVIRONMENT, absolute_path(repo_get_git_dir(the_repository)), 1);
742-
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
742+
setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(repo_get_work_tree(the_repository)), 1);
743743
} else if (dir_diff)
744744
die(_("options '%s' and '%s' cannot be used together"), "--dir-diff", "--no-index");
745745

builtin/fsmonitor--daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "abspath.h"
33
#include "config.h"
44
#include "dir.h"
5-
#include "environment.h"
65
#include "gettext.h"
76
#include "parse-options.h"
87
#include "fsmonitor-ll.h"
@@ -1291,7 +1290,8 @@ static int fsmonitor_run_daemon(void)
12911290

12921291
/* Prepare to (recursively) watch the <worktree-root> directory. */
12931292
strbuf_init(&state.path_worktree_watch, 0);
1294-
strbuf_addstr(&state.path_worktree_watch, absolute_path(get_git_work_tree()));
1293+
strbuf_addstr(&state.path_worktree_watch,
1294+
absolute_path(repo_get_work_tree(the_repository)));
12951295
state.nr_paths_watching = 1;
12961296

12971297
strbuf_init(&state.alias.alias, 0);

builtin/init-db.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
231231
set_git_work_tree(work_tree);
232232
else
233233
set_git_work_tree(git_work_tree_cfg);
234-
if (access(get_git_work_tree(), X_OK))
234+
if (access(repo_get_work_tree(the_repository), X_OK))
235235
die_errno (_("Cannot access work tree '%s'"),
236-
get_git_work_tree());
236+
repo_get_work_tree(the_repository));
237237
}
238238
else {
239239
if (real_git_dir)

builtin/reset.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "object-name.h"
2727
#include "parse-options.h"
2828
#include "path.h"
29+
#include "repository.h"
2930
#include "unpack-trees.h"
3031
#include "cache-tree.h"
3132
#include "setup.h"
@@ -441,7 +442,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
441442
else
442443
trace2_cmd_mode(reset_type_names[reset_type]);
443444

444-
if (reset_type != SOFT && (reset_type != MIXED || get_git_work_tree()))
445+
if (reset_type != SOFT && (reset_type != MIXED || repo_get_work_tree(the_repository)))
445446
setup_work_tree();
446447

447448
if (reset_type == MIXED && is_bare_repository())
@@ -474,7 +475,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
474475
goto cleanup;
475476
}
476477
the_repository->index->updated_skipworktree = 1;
477-
if (!no_refresh && get_git_work_tree()) {
478+
if (!no_refresh && repo_get_work_tree(the_repository)) {
478479
uint64_t t_begin, t_delta_in_ms;
479480

480481
t_begin = getnanotime();

builtin/rev-parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
967967
continue;
968968
}
969969
if (!strcmp(arg, "--show-toplevel")) {
970-
const char *work_tree = get_git_work_tree();
970+
const char *work_tree = repo_get_work_tree(the_repository);
971971
if (work_tree)
972972
print_path(work_tree, prefix, format, DEFAULT_UNMODIFIED);
973973
else
@@ -992,7 +992,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
992992
const char *pfx = prefix;
993993
if (!is_inside_work_tree()) {
994994
const char *work_tree =
995-
get_git_work_tree();
995+
repo_get_work_tree(the_repository);
996996
if (work_tree)
997997
printf("%s\n", work_tree);
998998
continue;

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
641641
cp.git_cmd = 1;
642642
cp.dir = prefix;
643643
strvec_pushf(&cp.env, GIT_WORK_TREE_ENVIRONMENT"=%s",
644-
absolute_path(get_git_work_tree()));
644+
absolute_path(repo_get_work_tree(the_repository)));
645645
strvec_pushf(&cp.env, GIT_DIR_ENVIRONMENT"=%s",
646646
absolute_path(repo_get_git_dir(the_repository)));
647647
strvec_push(&cp.args, "status");

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ static int clone_submodule(const struct module_clone_data *clone_data,
17091709
exit(128);
17101710

17111711
if (!is_absolute_path(clone_data->path))
1712-
clone_data_path = to_free = xstrfmt("%s/%s", get_git_work_tree(),
1712+
clone_data_path = to_free = xstrfmt("%s/%s", repo_get_work_tree(the_repository),
17131713
clone_data->path);
17141714

17151715
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)

builtin/update-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11941194
"remove or change it, if you really want to "
11951195
"enable the untracked cache"));
11961196
add_untracked_cache(the_repository->index);
1197-
report(_("Untracked cache enabled for '%s'"), get_git_work_tree());
1197+
report(_("Untracked cache enabled for '%s'"), repo_get_work_tree(the_repository));
11981198
break;
11991199
default:
12001200
BUG("bad untracked_cache value: %d", untracked_cache);

dir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "object-store-ll.h"
2121
#include "path.h"
2222
#include "refs.h"
23+
#include "repository.h"
2324
#include "wildmatch.h"
2425
#include "pathspec.h"
2526
#include "utf8.h"
@@ -2838,7 +2839,7 @@ static const char *get_ident_string(void)
28382839
return sb.buf;
28392840
if (uname(&uts) < 0)
28402841
die_errno(_("failed to get kernel name and information"));
2841-
strbuf_addf(&sb, "Location %s, system %s", get_git_work_tree(),
2842+
strbuf_addf(&sb, "Location %s, system %s", repo_get_work_tree(the_repository),
28422843
uts.sysname);
28432844
return sb.buf;
28442845
}

0 commit comments

Comments
 (0)