tmp-objdir: manage quarantine as an object directory

When creating a quarantine directory via the "tmp-objdir" subsystem we
create a new "files" backend that new objects part of the transaction
can be written to. In a future commit though we'll move handling of
alternates into the "files" backend, and as part of that it will no
longer be possible for us to have multiple sources attached to a single
object database.

In a preceding commit, we have prepared the "files" backend to be able
to handle multiple object directories. We don't use that mechanism for
alternates yet, but will start doing so in a subsequent commit. But with
that infrastructure ready we can already migrate tmp-objdirs over to use
this new mechanism.

Adapt the subsystem so we create a `struct odb_files_dir` instead of a
new "files" source.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-10-08 10:35:58 +02:00 committed by Junio C Hamano
parent f80a79e233
commit 622a625abb
3 changed files with 33 additions and 23 deletions

View File

@ -488,7 +488,7 @@ struct odb_transaction_files {
enum odb_transaction_flags flags;

struct tmp_objdir *objdir;
struct odb_source *quarantine;
struct odb_files_dir *quarantine;
struct transaction_packfile packfile;
const char *prefix;

@ -1443,7 +1443,7 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
return -1;
}

odb_source_prepare(transaction->quarantine,
odb_source_prepare(&transaction->quarantine->packed->base,
ODB_PREPARE_FLUSH_CACHES);
}


View File

@ -12,13 +12,17 @@
#include "quote.h"
#include "odb.h"
#include "odb/source.h"
#include "odb/source-files.h"
#include "odb/source-loose.h"
#include "odb/source-packed.h"
#include "repository.h"

struct tmp_objdir {
struct repository *repo;
struct strbuf path;
struct strvec env;
struct odb_source *prev_source;
struct odb_files_dir *temp_dir;
struct odb_files_dir *orig_dir;
int will_destroy;
};

@ -57,18 +61,19 @@ static void tmp_objdir_reparent(const char *old_cwd,
*/
static void tmp_objdir_restore_source(struct tmp_objdir *t)
{
struct odb_source *cur_source = t->repo->objects->sources;
struct odb_source_files *files = odb_source_files_downcast(t->repo->objects->sources);
struct odb_files_dir *cur_dir = files->dirs;

if (strcmp(t->path.buf, cur_source->path))
if (t->temp_dir != files->dirs)
BUG("expected %s as primary object store; found %s",
t->path.buf, cur_source->path);
t->temp_dir->abspath, cur_dir->abspath);

if (cur_source->next != t->prev_source)
if (t->temp_dir->next != t->orig_dir)
BUG("we expect the old primary object store to be the first alternate");

t->repo->disable_ref_updates = false;
t->repo->objects->sources = t->prev_source;
odb_source_free(cur_source);
files->dirs = t->orig_dir;
odb_files_dir_free(cur_dir);
}

int tmp_objdir_destroy(struct tmp_objdir *t)
@ -81,7 +86,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
if (t == the_tmp_objdir)
the_tmp_objdir = NULL;

if (t->prev_source)
if (t->orig_dir)
tmp_objdir_restore_source(t);

err = remove_dir_recursively(&t->path, 0);
@ -315,11 +320,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
if (!t)
return 0;

if (t->prev_source) {
if (t->repo->objects->sources->will_destroy)
if (t->orig_dir) {
if (t->will_destroy)
BUG("migrating an ODB that was marked for destruction");
tmp_objdir_restore_source(t);
t->prev_source = NULL;
t->orig_dir = NULL;
}

strbuf_addbuf(&src, &t->path);
@ -341,10 +346,12 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
return t->env.v;
}

struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
int will_destroy)
struct odb_files_dir *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
int will_destroy)
{
if (t->prev_source)
struct odb_source_files *files = odb_source_files_downcast(t->repo->objects->sources);

if (t->temp_dir)
BUG("the primary object database is already replaced");
t->will_destroy = will_destroy;

@ -353,11 +360,14 @@ struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
* alternate. Disable ref updates while a temporary source is active,
* since the objects in the database may roll back.
*/
t->prev_source = t->repo->objects->sources;
t->repo->objects->sources = odb_source_new(t->repo->objects, t->path.buf, false);
t->repo->objects->sources->next = t->prev_source;
t->repo->objects->sources->will_destroy = will_destroy;
t->temp_dir = odb_files_dir_new(t->repo->objects, t->path.buf, false);
t->temp_dir->loose->base.will_destroy = will_destroy;
t->temp_dir->packed->base.will_destroy = will_destroy;
t->temp_dir->next = files->dirs;

t->orig_dir = files->dirs;
files->dirs = t->temp_dir;
t->repo->disable_ref_updates = true;

return t->repo->objects->sources;
return t->temp_dir;
}

View File

@ -61,7 +61,7 @@ void tmp_objdir_discard_objects(struct tmp_objdir *);
* If will_destroy is nonzero, the object directory may not be migrated. Returns
* the newly installed primary source.
*/
struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *,
int will_destroy);
struct odb_files_dir *tmp_objdir_replace_primary_odb(struct tmp_objdir *,
int will_destroy);

#endif /* TMP_OBJDIR_H */