odb/source: make `will_destroy` an implementation detail

The `struct odb_source::will_destroy` flag tracks whether a source is
part of a transaction that we know we'll destruct anyway. If so, the
backend can optimize for that particular case, for example by not
flushing any data to disk.

While the intent is sensible, it assumes that transactions are backed by
a separate source that's being linked into the object database. But that
may or may not be true, as backends may have significantly better ways
to achieve the same. So the assumption doesn't make much sense in the
first place, as we're now tracking backend-specific details on the
generic `struct odb_source` level.

Move the field from the generic source into the "loose" source, as this
is the only source that ever makes use of it anyway.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-10-08 10:36:00 +02:00 committed by Junio C Hamano
parent a26ff4e576
commit 6066be88b4
4 changed files with 5 additions and 9 deletions

View File

@ -599,7 +599,7 @@ static int odb_source_loose_freshen_object(struct odb_source *source,
static void close_loose_object(struct odb_source_loose *loose,
int fd, const char *filename)
{
if (loose->base.will_destroy)
if (loose->will_destroy)
goto out;

if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))

View File

@ -28,6 +28,9 @@ struct odb_source_loose {

/* Map between object IDs for loose objects. */
struct loose_object_map *map;

/* Whether this is a source that will never be committed to disk. */
int will_destroy;
};

struct odb_source_loose *odb_source_loose_new(struct object_database *odb,

View File

@ -81,11 +81,6 @@ struct odb_source {
*/
bool local;

/*
* This object store is ephemeral, so there is no need to fsync.
*/
int will_destroy;

/*
* Path to the source. If this is a relative path, it is relative to
* the current working directory.

View File

@ -14,7 +14,6 @@
#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 {
@ -213,8 +212,7 @@ struct tmp_objdir *tmp_objdir_create(struct repository *r,
* since the objects in the database may roll back.
*/
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->loose->will_destroy = will_destroy;
t->temp_dir->next = files->dirs;

t->orig_dir = files->dirs;