tmp-objdir: stop using `the_repository`
Stop using `the_repository` in the "tmp-objdir" subsystem by passing in the repostiroy when creating a new temporary object directory. While we could trivially update the caller to pass in the hash algorithm used by the index itself, we instead pass in `the_hash_algo`. This is mostly done to stay consistent with the rest of the code in that file, which isn't prepared to handle arbitrary repositories, either. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 17, 2024 at 07:43 UTC
727c71a1121c2067223aad8d187409c9822a3f8d
5 files changed
+14
-12
builtin/receive-pack.c
+1
-1
@@ -2239,7 +2239,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
2239
strvec_push(&child.args, alt_shallow_file);
2240
}
2241
2242
- tmp_objdir = tmp_objdir_create("incoming");
2242
+ tmp_objdir = tmp_objdir_create(the_repository, "incoming");
2243
if (!tmp_objdir) {
2244
if (err_fd > 0)
2245
close(err_fd);
bulk-checkin.c
+1
-1
@@ -333,7 +333,7 @@ void prepare_loose_object_bulk_checkin(void)
333
if (!odb_transaction_nesting || bulk_fsync_objdir)
334
return;
335
336
- bulk_fsync_objdir = tmp_objdir_create("bulk-fsync");
336
+ bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
337
if (bulk_fsync_objdir)
338
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
339
}
log-tree.c
+1
-1
@@ -1042,7 +1042,7 @@ static int do_remerge_diff(struct rev_info *opt,
1042
* into the alternative object store list as the primary.
1043
*/
1044
if (opt->remerge_diff && !opt->remerge_objdir) {
1045
- opt->remerge_objdir = tmp_objdir_create("remerge-diff");
1045
+ opt->remerge_objdir = tmp_objdir_create(the_repository, "remerge-diff");
1046
if (!opt->remerge_objdir)
1047
return error(_("unable to create temporary object directory"));
1048
tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);
tmp-objdir.c
+8
-7
@@ -1,5 +1,3 @@
1
-#define USE_THE_REPOSITORY_VARIABLE
2
-
1
#include "git-compat-util.h"
2
#include "tmp-objdir.h"
3
#include "abspath.h"
@@ -16,6 +14,7 @@
14
#include "repository.h"
15
16
struct tmp_objdir {
17
+ struct repository *repo;
18
struct strbuf path;
19
struct strvec env;
20
struct object_directory *prev_odb;
@@ -116,7 +115,8 @@ static int setup_tmp_objdir(const char *root)
115
return ret;
116
}
117
119
-struct tmp_objdir *tmp_objdir_create(const char *prefix)
118
+struct tmp_objdir *tmp_objdir_create(struct repository *r,
119
+ const char *prefix)
120
{
121
static int installed_handlers;
122
struct tmp_objdir *t;
@@ -125,6 +125,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
125
BUG("only one tmp_objdir can be used at a time");
126
127
t = xcalloc(1, sizeof(*t));
128
+ t->repo = r;
129
strbuf_init(&t->path, 0);
130
strvec_init(&t->env);
131
@@ -134,7 +135,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
135
* them.
136
*/
137
strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
137
- repo_get_object_directory(the_repository), prefix);
138
+ repo_get_object_directory(r), prefix);
139
140
if (!mkdtemp(t->path.buf)) {
141
/* free, not destroy, as we never touched the filesystem */
@@ -154,7 +155,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
155
}
156
157
env_append(&t->env, ALTERNATE_DB_ENVIRONMENT,
157
- absolute_path(repo_get_object_directory(the_repository)));
158
+ absolute_path(repo_get_object_directory(r)));
159
env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf));
160
env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT,
161
absolute_path(t->path.buf));
@@ -273,14 +274,14 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
274
return 0;
275
276
if (t->prev_odb) {
276
- if (the_repository->objects->odb->will_destroy)
277
+ if (t->repo->objects->odb->will_destroy)
278
BUG("migrating an ODB that was marked for destruction");
279
restore_primary_odb(t->prev_odb, t->path.buf);
280
t->prev_odb = NULL;
281
}
282
283
strbuf_addbuf(&src, &t->path);
283
- strbuf_addstr(&dst, repo_get_object_directory(the_repository));
284
+ strbuf_addstr(&dst, repo_get_object_directory(t->repo));
285
286
ret = migrate_paths(&src, &dst, 0);
287
tmp-objdir.h
+3
-2
@@ -11,7 +11,7 @@
11
* Example:
12
*
13
* struct child_process child = CHILD_PROCESS_INIT;
14
- * struct tmp_objdir *t = tmp_objdir_create("incoming");
14
+ * struct tmp_objdir *t = tmp_objdir_create(repo, "incoming");
15
* strvec_push(&child.args, cmd);
16
* strvec_pushv(&child.env, tmp_objdir_env(t));
17
* if (!run_command(&child)) && !tmp_objdir_migrate(t))
@@ -21,13 +21,14 @@
21
*
22
*/
23
24
+struct repository;
25
struct tmp_objdir;
26
27
/*
28
* Create a new temporary object directory with the specified prefix;
29
* returns NULL on failure.
30
*/
30
-struct tmp_objdir *tmp_objdir_create(const char *prefix);
31
+struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix);
32
33
/*
34
* Return a list of environment strings, suitable for use with