Skip to content

Commit feffb34

Browse files
committed
Merge branch 'ps/path-sans-the-repository'
The path.[ch] API takes an explicit repository parameter passed throughout the callchain, instead of relying on the_repository singleton instance. * ps/path-sans-the-repository: path: adjust last remaining users of `the_repository` environment: move access to "core.sharedRepository" into repo settings environment: move access to "core.hooksPath" into repo settings repo-settings: introduce function to clear struct path: drop `git_path()` in favor of `repo_git_path()` rerere: let `rerere_path()` write paths into a caller-provided buffer path: drop `git_common_path()` in favor of `repo_common_path()` worktree: return allocated string from `get_worktree_git_dir()` path: drop `git_path_buf()` in favor of `repo_git_path_replace()` path: drop `git_pathdup()` in favor of `repo_git_path()` path: drop unused `strbuf_git_path()` function path: refactor `repo_submodule_path()` family of functions submodule: refactor `submodule_to_gitdir()` to accept a repo path: refactor `repo_worktree_path()` family of functions path: refactor `repo_git_path()` family of functions path: refactor `repo_common_path()` family of functions
2 parents 6a64ac7 + 028f618 commit feffb34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+639
-490
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ static enum bisect_error check_good_are_ancestors_of_bad(struct repository *r,
930930
if (!current_bad_oid)
931931
return error(_("a %s revision is needed"), term_bad);
932932

933-
filename = git_pathdup("BISECT_ANCESTORS_OK");
933+
filename = repo_git_path(the_repository, "BISECT_ANCESTORS_OK");
934934

935935
/* Check if file BISECT_ANCESTORS_OK exists. */
936936
if (!stat(filename, &st) && S_ISREG(st.st_mode))

branch.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static void prepare_checked_out_branches(void)
397397
worktrees = get_worktrees();
398398

399399
while (worktrees[i]) {
400-
char *old;
400+
char *old, *wt_gitdir;
401401
struct wt_status_state state = { 0 };
402402
struct worktree *wt = worktrees[i++];
403403
struct string_list update_refs = STRING_LIST_INIT_DUP;
@@ -437,7 +437,8 @@ static void prepare_checked_out_branches(void)
437437
}
438438
wt_status_state_free_buffers(&state);
439439

440-
if (!sequencer_get_update_refs_state(get_worktree_git_dir(wt),
440+
wt_gitdir = get_worktree_git_dir(wt);
441+
if (!sequencer_get_update_refs_state(wt_gitdir,
441442
&update_refs)) {
442443
struct string_list_item *item;
443444
for_each_string_list_item(item, &update_refs) {
@@ -448,6 +449,8 @@ static void prepare_checked_out_branches(void)
448449
}
449450
string_list_clear(&update_refs, 1);
450451
}
452+
453+
free(wt_gitdir);
451454
}
452455

453456
free_worktrees(worktrees);

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static void am_state_init(struct am_state *state)
158158

159159
memset(state, 0, sizeof(*state));
160160

161-
state->dir = git_pathdup("rebase-apply");
161+
state->dir = repo_git_path(the_repository, "rebase-apply");
162162

163163
state->prec = 4;
164164

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ static void write_refspec_config(const char *src_ref_prefix,
835835

836836
static void dissociate_from_references(void)
837837
{
838-
char *alternates = git_pathdup("objects/info/alternates");
838+
char *alternates = repo_git_path(the_repository, "objects/info/alternates");
839839

840840
if (!access(alternates, F_OK)) {
841841
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -1219,7 +1219,7 @@ int cmd_clone(int argc,
12191219

12201220
strbuf_reset(&buf);
12211221
strbuf_addf(&buf, "%s/refs", git_dir);
1222-
safe_create_dir(buf.buf, 1);
1222+
safe_create_dir(the_repository, buf.buf, 1);
12231223

12241224
/*
12251225
* additional config can be injected with -c, make sure it's included

builtin/commit.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
352352
struct pathspec pathspec;
353353
int refresh_flags = REFRESH_QUIET;
354354
const char *ret;
355+
char *path = NULL;
355356

356357
if (is_status)
357358
refresh_flags |= REFRESH_UNMERGED;
@@ -524,9 +525,9 @@ static const char *prepare_index(const char **argv, const char *prefix,
524525
if (write_locked_index(the_repository->index, &index_lock, 0))
525526
die(_("unable to write new index file"));
526527

527-
hold_lock_file_for_update(&false_lock,
528-
git_path("next-index-%"PRIuMAX,
529-
(uintmax_t) getpid()),
528+
path = repo_git_path(the_repository, "next-index-%"PRIuMAX,
529+
(uintmax_t) getpid());
530+
hold_lock_file_for_update(&false_lock, path,
530531
LOCK_DIE_ON_ERROR);
531532

532533
create_base_index(current_head);
@@ -542,6 +543,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
542543
out:
543544
string_list_clear(&partial, 0);
544545
clear_pathspec(&pathspec);
546+
free(path);
545547
return ret;
546548
}
547549

builtin/config.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,13 @@ static void location_options_init(struct config_location_options *opts,
775775
opts->source.file = opts->file_to_free = git_system_config();
776776
opts->source.scope = CONFIG_SCOPE_SYSTEM;
777777
} else if (opts->use_local_config) {
778-
opts->source.file = opts->file_to_free = git_pathdup("config");
778+
opts->source.file = opts->file_to_free = repo_git_path(the_repository, "config");
779779
opts->source.scope = CONFIG_SCOPE_LOCAL;
780780
} else if (opts->use_worktree_config) {
781781
struct worktree **worktrees = get_worktrees();
782782
if (the_repository->repository_format_worktree_config)
783783
opts->source.file = opts->file_to_free =
784-
git_pathdup("config.worktree");
784+
repo_git_path(the_repository, "config.worktree");
785785
else if (worktrees[0] && worktrees[1])
786786
die(_("--worktree cannot be used with multiple "
787787
"working trees unless the config\n"
@@ -790,7 +790,7 @@ static void location_options_init(struct config_location_options *opts,
790790
"section in \"git help worktree\" for details"));
791791
else
792792
opts->source.file = opts->file_to_free =
793-
git_pathdup("config");
793+
repo_git_path(the_repository, "config");
794794
opts->source.scope = CONFIG_SCOPE_LOCAL;
795795
free_worktrees(worktrees);
796796
} else if (opts->source.file) {
@@ -1087,7 +1087,7 @@ static int show_editor(struct config_location_options *opts)
10871087
git_config(git_default_config, NULL);
10881088
config_file = opts->source.file ?
10891089
xstrdup(opts->source.file) :
1090-
git_pathdup("config");
1090+
repo_git_path(the_repository, "config");
10911091
if (opts->use_global_config) {
10921092
int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
10931093
if (fd >= 0) {

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
328328

329329
static void write_crash_report(const char *err)
330330
{
331-
char *loc = git_pathdup("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
331+
char *loc = repo_git_path(the_repository, "fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
332332
FILE *rpt = fopen(loc, "w");
333333
struct branch *b;
334334
unsigned long lu;
@@ -3280,7 +3280,7 @@ static char* make_fast_import_path(const char *path)
32803280
{
32813281
if (!relative_marks_paths || is_absolute_path(path))
32823282
return prefix_filename(global_prefix, path);
3283-
return git_pathdup("info/fast-import/%s", path);
3283+
return repo_git_path(the_repository, "info/fast-import/%s", path);
32843284
}
32853285

32863286
static void option_import_marks(const char *marks,

builtin/fsck.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static void check_unreachable_object(struct object *obj)
326326
printable_type(&obj->oid, obj->type),
327327
describe_object(&obj->oid));
328328
if (write_lost_and_found) {
329-
char *filename = git_pathdup("lost-found/%s/%s",
329+
char *filename = repo_git_path(the_repository, "lost-found/%s/%s",
330330
obj->type == OBJ_COMMIT ? "commit" : "other",
331331
describe_object(&obj->oid));
332332
FILE *f;
@@ -1057,17 +1057,21 @@ int cmd_fsck(int argc,
10571057
struct worktree *wt = *p;
10581058
struct index_state istate =
10591059
INDEX_STATE_INIT(the_repository);
1060-
char *path;
1060+
char *path, *wt_gitdir;
10611061

10621062
/*
10631063
* Make a copy since the buffer is reusable
10641064
* and may get overwritten by other calls
10651065
* while we're examining the index.
10661066
*/
10671067
path = xstrdup(worktree_git_path(the_repository, wt, "index"));
1068-
read_index_from(&istate, path, get_worktree_git_dir(wt));
1068+
wt_gitdir = get_worktree_git_dir(wt);
1069+
1070+
read_index_from(&istate, path, wt_gitdir);
10691071
fsck_index(&istate, path, wt->is_current);
1072+
10701073
discard_index(&istate);
1074+
free(wt_gitdir);
10711075
free(path);
10721076
}
10731077
free_worktrees(worktrees);

builtin/gc.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ static void process_log_file(void)
9999
/* There was some error recorded in the lock file */
100100
commit_lock_file(&log_lock);
101101
} else {
102+
char *path = repo_git_path(the_repository, "gc.log");
102103
/* No error, clean up any old gc.log */
103-
unlink(git_path("gc.log"));
104+
unlink(path);
104105
rollback_lock_file(&log_lock);
106+
free(path);
105107
}
106108
}
107109

@@ -300,8 +302,11 @@ static int too_many_loose_objects(struct gc_config *cfg)
300302
int num_loose = 0;
301303
int needed = 0;
302304
const unsigned hexsz_loose = the_hash_algo->hexsz - 2;
305+
char *path;
303306

304-
dir = opendir(git_path("objects/17"));
307+
path = repo_git_path(the_repository, "objects/17");
308+
dir = opendir(path);
309+
free(path);
305310
if (!dir)
306311
return 0;
307312

@@ -550,7 +555,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
550555
if (xgethostname(my_host, sizeof(my_host)))
551556
xsnprintf(my_host, sizeof(my_host), "unknown");
552557

553-
pidfile_path = git_pathdup("gc.pid");
558+
pidfile_path = repo_git_path(the_repository, "gc.pid");
554559
fd = hold_lock_file_for_update(&lock, pidfile_path,
555560
LOCK_DIE_ON_ERROR);
556561
if (!force) {
@@ -611,7 +616,7 @@ static int report_last_gc_error(void)
611616
int ret = 0;
612617
ssize_t len;
613618
struct stat st;
614-
char *gc_log_path = git_pathdup("gc.log");
619+
char *gc_log_path = repo_git_path(the_repository, "gc.log");
615620

616621
if (stat(gc_log_path, &st)) {
617622
if (errno == ENOENT)
@@ -826,11 +831,12 @@ struct repository *repo UNUSED)
826831
}
827832

828833
if (daemonized) {
829-
hold_lock_file_for_update(&log_lock,
830-
git_path("gc.log"),
834+
char *path = repo_git_path(the_repository, "gc.log");
835+
hold_lock_file_for_update(&log_lock, path,
831836
LOCK_DIE_ON_ERROR);
832837
dup2(get_lock_file_fd(&log_lock), 2);
833838
atexit(process_log_file_at_exit);
839+
free(path);
834840
}
835841

836842
gc_before_repack(&opts, &cfg);
@@ -892,8 +898,11 @@ struct repository *repo UNUSED)
892898
warning(_("There are too many unreachable loose objects; "
893899
"run 'git prune' to remove them."));
894900

895-
if (!daemonized)
896-
unlink(git_path("gc.log"));
901+
if (!daemonized) {
902+
char *path = repo_git_path(the_repository, "gc.log");
903+
unlink(path);
904+
free(path);
905+
}
897906

898907
out:
899908
gc_config_release(&cfg);

builtin/init-db.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ int cmd_init_db(int argc,
132132
* and we know shared_repository should always be 0;
133133
* but just in case we play safe.
134134
*/
135-
saved = get_shared_repository();
136-
set_shared_repository(0);
135+
saved = repo_settings_get_shared_repository(the_repository);
136+
repo_settings_set_shared_repository(the_repository, 0);
137137
switch (safe_create_leading_directories_const(argv[0])) {
138138
case SCLD_OK:
139139
case SCLD_PERMS:
@@ -145,7 +145,7 @@ int cmd_init_db(int argc,
145145
die_errno(_("cannot mkdir %s"), argv[0]);
146146
break;
147147
}
148-
set_shared_repository(saved);
148+
repo_settings_set_shared_repository(the_repository, saved);
149149
if (mkdir(argv[0], 0777) < 0)
150150
die_errno(_("cannot mkdir %s"), argv[0]);
151151
mkdir_tried = 1;
@@ -175,7 +175,7 @@ int cmd_init_db(int argc,
175175
}
176176

177177
if (init_shared_repository != -1)
178-
set_shared_repository(init_shared_repository);
178+
repo_settings_set_shared_repository(the_repository, init_shared_repository);
179179

180180
/*
181181
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR

0 commit comments

Comments
 (0)