Skip to content

Commit a3673f4

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

20 files changed

+43
-39
lines changed

builtin/commit-graph.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "builtin.h"
22
#include "commit.h"
33
#include "config.h"
4-
#include "environment.h"
54
#include "gettext.h"
65
#include "hex.h"
76
#include "parse-options.h"
@@ -95,7 +94,7 @@ static int graph_verify(int argc, const char **argv, const char *prefix)
9594
usage_with_options(builtin_commit_graph_verify_usage, options);
9695

9796
if (!opts.obj_dir)
98-
opts.obj_dir = get_object_directory();
97+
opts.obj_dir = repo_get_object_directory(the_repository);
9998
if (opts.shallow)
10099
flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
101100
if (opts.progress)
@@ -275,7 +274,7 @@ static int graph_write(int argc, const char **argv, const char *prefix)
275274
if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
276275
die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
277276
if (!opts.obj_dir)
278-
opts.obj_dir = get_object_directory();
277+
opts.obj_dir = repo_get_object_directory(the_repository);
279278
if (opts.append)
280279
flags |= COMMIT_GRAPH_WRITE_APPEND;
281280
if (opts.split)

builtin/count-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "builtin.h"
88
#include "config.h"
99
#include "dir.h"
10-
#include "environment.h"
1110
#include "gettext.h"
1211
#include "path.h"
1312
#include "repository.h"
@@ -116,7 +115,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
116115
report_linked_checkout_garbage(the_repository);
117116
}
118117

119-
for_each_loose_file_in_objdir(get_object_directory(),
118+
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
120119
count_loose, count_cruft, NULL, NULL);
121120

122121
if (verbose) {

builtin/multi-pack-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "builtin.h"
22
#include "abspath.h"
33
#include "config.h"
4-
#include "environment.h"
54
#include "gettext.h"
65
#include "parse-options.h"
76
#include "midx.h"
87
#include "strbuf.h"
98
#include "trace2.h"
109
#include "object-store-ll.h"
1110
#include "replace-object.h"
11+
#include "repository.h"
1212

1313
#define BUILTIN_MIDX_WRITE_USAGE \
1414
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
@@ -63,7 +63,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,
6363
char **value = opt->value;
6464
free(*value);
6565
if (unset)
66-
*value = xstrdup(get_object_directory());
66+
*value = xstrdup(repo_get_object_directory(the_repository));
6767
else
6868
*value = real_pathdup(arg, 1);
6969
return 0;

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3940,7 +3940,7 @@ static int add_loose_object(const struct object_id *oid, const char *path,
39403940
*/
39413941
static void add_unreachable_loose_objects(void)
39423942
{
3943-
for_each_loose_file_in_objdir(get_object_directory(),
3943+
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
39443944
add_loose_object,
39453945
NULL, NULL, NULL);
39463946
}

builtin/prune.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
193193
revs.exclude_promisor_objects = 1;
194194
}
195195

196-
for_each_loose_file_in_objdir(get_object_directory(), prune_object,
197-
prune_cruft, prune_subdir, &revs);
196+
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
197+
prune_object, prune_cruft, prune_subdir, &revs);
198198

199199
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
200-
remove_temporary_files(get_object_directory());
201-
s = mkpathdup("%s/pack", get_object_directory());
200+
remove_temporary_files(repo_get_object_directory(the_repository));
201+
s = mkpathdup("%s/pack", repo_get_object_directory(the_repository));
202202
remove_temporary_files(s);
203203
free(s);
204204

builtin/repack.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12401240
if (write_midx && write_bitmaps) {
12411241
struct strbuf path = STRBUF_INIT;
12421242

1243-
strbuf_addf(&path, "%s/%s_XXXXXX", get_object_directory(),
1243+
strbuf_addf(&path, "%s/%s_XXXXXX", repo_get_object_directory(the_repository),
12441244
"bitmap-ref-tips");
12451245

12461246
refs_snapshot = xmks_tempfile(path.buf);
@@ -1249,7 +1249,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
12491249
strbuf_release(&path);
12501250
}
12511251

1252-
packdir = mkpathdup("%s/pack", get_object_directory());
1252+
packdir = mkpathdup("%s/pack", repo_get_object_directory(the_repository));
12531253
packtmp_name = xstrfmt(".tmp-%d-pack", (int)getpid());
12541254
packtmp = mkpathdup("%s/%s", packdir, packtmp_name);
12551255

@@ -1519,7 +1519,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
15191519
unsigned flags = 0;
15201520
if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
15211521
flags |= MIDX_WRITE_INCREMENTAL;
1522-
write_midx_file(get_object_directory(), NULL, NULL, flags);
1522+
write_midx_file(repo_get_object_directory(the_repository),
1523+
NULL, NULL, flags);
15231524
}
15241525

15251526
cleanup:

bulk-checkin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
7575
close(fd);
7676
}
7777

78-
strbuf_addf(&packname, "%s/pack/pack-%s.", get_object_directory(),
78+
strbuf_addf(&packname, "%s/pack/pack-%s.", repo_get_object_directory(the_repository),
7979
hash_to_hex(hash));
8080
finish_tmp_packfile(&packname, state->pack_tmp_name,
8181
state->written, state->nr_written,
@@ -113,7 +113,7 @@ static void flush_batch_fsync(void)
113113
* to ensure that the data in each new object file is durable before
114114
* the final name is visible.
115115
*/
116-
strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", get_object_directory());
116+
strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", repo_get_object_directory(the_repository));
117117
temp = xmks_tempfile(temp_path.buf);
118118
fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
119119
delete_tempfile(&temp);

environment.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ const char *get_git_work_tree(void)
273273
return the_repository->worktree;
274274
}
275275

276-
const char *get_object_directory(void)
277-
{
278-
if (!the_repository->objects->odb)
279-
BUG("git environment hasn't been setup");
280-
return the_repository->objects->odb->path;
281-
}
282-
283276
int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
284277
{
285278
int fd;

environment.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ int have_git_dir(void);
106106
extern int is_bare_repository_cfg;
107107
int is_bare_repository(void);
108108
extern char *git_work_tree_cfg;
109-
const char *get_object_directory(void);
110109
char *get_index_file(void);
111110
char *get_graft_file(struct repository *r);
112111
void set_git_dir(const char *path, int make_realpath);

fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18391839

18401840
string_list_append_nodup(pack_lockfiles,
18411841
xstrfmt("%s/pack/pack-%s.keep",
1842-
get_object_directory(),
1842+
repo_get_object_directory(the_repository),
18431843
packname));
18441844
}
18451845
string_list_clear(&packfile_uris, 0);

0 commit comments

Comments
 (0)