Files
git/odb/source-loose.h
Patrick Steinhardt ead691927b odb/source-loose: start converting to a proper struct odb_source
Start converting `struct odb_source_loose` into a proper pluggable
`struct odb_source` by embedding the base struct and assigning it the
new `ODB_SOURCE_LOOSE` type. Furthermore, wire up lifecycle management
of this source by implementing the `free` callback and taking ownership
of the chdir notifications.

Note that the loose source is not yet functional as a standalone `struct
odb_source`, as it's missing all of the callback implementations. These
will be wired up in subsequent commits.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-06-01 18:47:17 +09:00

50 lines
1.4 KiB
C

#ifndef ODB_SOURCE_LOOSE_H
#define ODB_SOURCE_LOOSE_H
#include "odb/source.h"
struct odb_source_files;
struct object_database;
struct oidtree;
/*
* An object database source that stores its objects in loose format, one
* file per object. This source is part of the files source.
*/
struct odb_source_loose {
struct odb_source base;
struct odb_source_files *files;
/*
* Used to store the results of readdir(3) calls when we are OK
* sacrificing accuracy due to races for speed. That includes
* object existence with OBJECT_INFO_QUICK, as well as
* our search for unique abbreviated hashes. Don't use it for tasks
* requiring greater accuracy!
*
* Be sure to call odb_load_loose_cache() before using.
*/
uint32_t subdir_seen[8]; /* 256 bits */
struct oidtree *cache;
/* Map between object IDs for loose objects. */
struct loose_object_map *map;
};
struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files);
/*
* Cast the given object database source to the loose backend. This will cause
* a BUG in case the source doesn't use this backend.
*/
static inline struct odb_source_loose *odb_source_loose_downcast(struct odb_source *source)
{
if (source->type != ODB_SOURCE_LOOSE)
BUG("trying to downcast source of type '%d' to loose", source->type);
return container_of(source, struct odb_source_loose, base);
}
void odb_source_loose_clear_cache(struct odb_source_loose *loose);
#endif