Skip to content

Commit 727c71a

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b81093a commit 727c71a

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
22392239
strvec_push(&child.args, alt_shallow_file);
22402240
}
22412241

2242-
tmp_objdir = tmp_objdir_create("incoming");
2242+
tmp_objdir = tmp_objdir_create(the_repository, "incoming");
22432243
if (!tmp_objdir) {
22442244
if (err_fd > 0)
22452245
close(err_fd);

bulk-checkin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void prepare_loose_object_bulk_checkin(void)
333333
if (!odb_transaction_nesting || bulk_fsync_objdir)
334334
return;
335335

336-
bulk_fsync_objdir = tmp_objdir_create("bulk-fsync");
336+
bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
337337
if (bulk_fsync_objdir)
338338
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
339339
}

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ static int do_remerge_diff(struct rev_info *opt,
10421042
* into the alternative object store list as the primary.
10431043
*/
10441044
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");
10461046
if (!opt->remerge_objdir)
10471047
return error(_("unable to create temporary object directory"));
10481048
tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);

tmp-objdir.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "tmp-objdir.h"
53
#include "abspath.h"
@@ -16,6 +14,7 @@
1614
#include "repository.h"
1715

1816
struct tmp_objdir {
17+
struct repository *repo;
1918
struct strbuf path;
2019
struct strvec env;
2120
struct object_directory *prev_odb;
@@ -116,7 +115,8 @@ static int setup_tmp_objdir(const char *root)
116115
return ret;
117116
}
118117

119-
struct tmp_objdir *tmp_objdir_create(const char *prefix)
118+
struct tmp_objdir *tmp_objdir_create(struct repository *r,
119+
const char *prefix)
120120
{
121121
static int installed_handlers;
122122
struct tmp_objdir *t;
@@ -125,6 +125,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
125125
BUG("only one tmp_objdir can be used at a time");
126126

127127
t = xcalloc(1, sizeof(*t));
128+
t->repo = r;
128129
strbuf_init(&t->path, 0);
129130
strvec_init(&t->env);
130131

@@ -134,7 +135,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
134135
* them.
135136
*/
136137
strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
137-
repo_get_object_directory(the_repository), prefix);
138+
repo_get_object_directory(r), prefix);
138139

139140
if (!mkdtemp(t->path.buf)) {
140141
/* free, not destroy, as we never touched the filesystem */
@@ -154,7 +155,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
154155
}
155156

156157
env_append(&t->env, ALTERNATE_DB_ENVIRONMENT,
157-
absolute_path(repo_get_object_directory(the_repository)));
158+
absolute_path(repo_get_object_directory(r)));
158159
env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf));
159160
env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT,
160161
absolute_path(t->path.buf));
@@ -273,14 +274,14 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
273274
return 0;
274275

275276
if (t->prev_odb) {
276-
if (the_repository->objects->odb->will_destroy)
277+
if (t->repo->objects->odb->will_destroy)
277278
BUG("migrating an ODB that was marked for destruction");
278279
restore_primary_odb(t->prev_odb, t->path.buf);
279280
t->prev_odb = NULL;
280281
}
281282

282283
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));
284285

285286
ret = migrate_paths(&src, &dst, 0);
286287

tmp-objdir.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Example:
1212
*
1313
* 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");
1515
* strvec_push(&child.args, cmd);
1616
* strvec_pushv(&child.env, tmp_objdir_env(t));
1717
* if (!run_command(&child)) && !tmp_objdir_migrate(t))
@@ -21,13 +21,14 @@
2121
*
2222
*/
2323

24+
struct repository;
2425
struct tmp_objdir;
2526

2627
/*
2728
* Create a new temporary object directory with the specified prefix;
2829
* returns NULL on failure.
2930
*/
30-
struct tmp_objdir *tmp_objdir_create(const char *prefix);
31+
struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix);
3132

3233
/*
3334
* Return a list of environment strings, suitable for use with

0 commit comments

Comments
 (0)