1
0
mirror of https://github.com/git/git.git synced 2025-02-06 09:26:16 +00:00

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>
This commit is contained in:
Patrick Steinhardt 2024-12-17 07:43:58 +01:00 committed by Junio C Hamano
parent b81093aeae
commit 727c71a112
5 changed files with 14 additions and 12 deletions

View File

@ -2239,7 +2239,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
strvec_push(&child.args, alt_shallow_file);
}
tmp_objdir = tmp_objdir_create("incoming");
tmp_objdir = tmp_objdir_create(the_repository, "incoming");
if (!tmp_objdir) {
if (err_fd > 0)
close(err_fd);

View File

@ -333,7 +333,7 @@ void prepare_loose_object_bulk_checkin(void)
if (!odb_transaction_nesting || bulk_fsync_objdir)
return;
bulk_fsync_objdir = tmp_objdir_create("bulk-fsync");
bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
if (bulk_fsync_objdir)
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
}

View File

@ -1042,7 +1042,7 @@ static int do_remerge_diff(struct rev_info *opt,
* into the alternative object store list as the primary.
*/
if (opt->remerge_diff && !opt->remerge_objdir) {
opt->remerge_objdir = tmp_objdir_create("remerge-diff");
opt->remerge_objdir = tmp_objdir_create(the_repository, "remerge-diff");
if (!opt->remerge_objdir)
return error(_("unable to create temporary object directory"));
tmp_objdir_replace_primary_odb(opt->remerge_objdir, 1);

View File

@ -1,5 +1,3 @@
#define USE_THE_REPOSITORY_VARIABLE
#include "git-compat-util.h"
#include "tmp-objdir.h"
#include "abspath.h"
@ -16,6 +14,7 @@
#include "repository.h"
struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
struct object_directory *prev_odb;
@ -116,7 +115,8 @@ static int setup_tmp_objdir(const char *root)
return ret;
}
struct tmp_objdir *tmp_objdir_create(const char *prefix)
struct tmp_objdir *tmp_objdir_create(struct repository *r,
const char *prefix)
{
static int installed_handlers;
struct tmp_objdir *t;
@ -125,6 +125,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
BUG("only one tmp_objdir can be used at a time");
t = xcalloc(1, sizeof(*t));
t->repo = r;
strbuf_init(&t->path, 0);
strvec_init(&t->env);
@ -134,7 +135,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
* them.
*/
strbuf_addf(&t->path, "%s/tmp_objdir-%s-XXXXXX",
repo_get_object_directory(the_repository), prefix);
repo_get_object_directory(r), prefix);
if (!mkdtemp(t->path.buf)) {
/* free, not destroy, as we never touched the filesystem */
@ -154,7 +155,7 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
}
env_append(&t->env, ALTERNATE_DB_ENVIRONMENT,
absolute_path(repo_get_object_directory(the_repository)));
absolute_path(repo_get_object_directory(r)));
env_replace(&t->env, DB_ENVIRONMENT, absolute_path(t->path.buf));
env_replace(&t->env, GIT_QUARANTINE_ENVIRONMENT,
absolute_path(t->path.buf));
@ -273,14 +274,14 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
return 0;
if (t->prev_odb) {
if (the_repository->objects->odb->will_destroy)
if (t->repo->objects->odb->will_destroy)
BUG("migrating an ODB that was marked for destruction");
restore_primary_odb(t->prev_odb, t->path.buf);
t->prev_odb = NULL;
}
strbuf_addbuf(&src, &t->path);
strbuf_addstr(&dst, repo_get_object_directory(the_repository));
strbuf_addstr(&dst, repo_get_object_directory(t->repo));
ret = migrate_paths(&src, &dst, 0);

View File

@ -11,7 +11,7 @@
* Example:
*
* struct child_process child = CHILD_PROCESS_INIT;
* struct tmp_objdir *t = tmp_objdir_create("incoming");
* struct tmp_objdir *t = tmp_objdir_create(repo, "incoming");
* strvec_push(&child.args, cmd);
* strvec_pushv(&child.env, tmp_objdir_env(t));
* if (!run_command(&child)) && !tmp_objdir_migrate(t))
@ -21,13 +21,14 @@
*
*/
struct repository;
struct tmp_objdir;
/*
* Create a new temporary object directory with the specified prefix;
* returns NULL on failure.
*/
struct tmp_objdir *tmp_objdir_create(const char *prefix);
struct tmp_objdir *tmp_objdir_create(struct repository *r, const char *prefix);
/*
* Return a list of environment strings, suitable for use with