Files
git/odb/source-files.h
Junio C Hamano 295bac407e Merge branch 'ps/odb-reload-alternates' into next
The object database files backend has been updated to reload
alternates when an object lookup fails on retry. This restores a lost
capability to find objects moved to a newly added alternate during a
concurrent repository rewrite, with caching and deduplication
optimizations to avoid performance regressions.

* ps/odb-reload-alternates:
  odb/source-files: only reload alternates when the file has changed
  odb/source-files: avoid stat'ing already-known alternates
  odb/source-files: simplify directory duplication detection
  odb/source-files: reload alternates on retry
  odb/source-files: always load alternates via primary object directory
  odb/source-files: rename alternates-related functions
2026-11-03 07:33:35 -08:00

110 lines
3.2 KiB
C

#ifndef ODB_SOURCE_FILES_H
#define ODB_SOURCE_FILES_H
#include "odb/source.h"
#include "statinfo.h"
#include "strmap.h"
struct odb_source_loose;
struct odb_source_packed;
/*
* A single object directory that encapsulates access to both the loose and
* packed backend. This can either be the primary or an alternate object
* directory.
*/
struct odb_files_dir {
/* Absolute path to the object directory. */
char *abspath;
/* List of alternate object directories. */
struct odb_files_dir *next;
/* The two sources derived from this object directory. */
struct odb_source_loose *loose;
struct odb_source_packed *packed;
/*
* Whether this is the local object directory of the owning
* repository. Directories added via alternates are not local.
*/
bool local;
};
struct odb_files_dir *odb_files_dir_new(struct object_database *odb,
const char *path, bool local);
void odb_files_dir_free(struct odb_files_dir *dir);
/*
* The files object database source uses a combination of loose objects and
* packfiles. It is the default backend used by Git to store objects.
*/
struct odb_source_files {
struct odb_source base;
/*
* List of all object directories; the main directory is first (and
* cannot be NULL after initialization). Subsequent directories are
* alternates.
*/
struct odb_files_dir *dirs;
struct odb_files_dir **dirs_tail;
/*
* Set of directory paths that have already been linked into this
* source. This set is used to detect the case where the same directory
* is registered multiple times.
*/
struct strset dir_paths;
/*
* Whether directory paths shall be compared case-insensitively, as
* determined by "core.ignoreCase".
*/
int dir_paths_icase;
/* Stat data of the "info/alternates" file. */
struct stat_validity alternates_validity;
};
/* Allocate and initialize a new object source. */
struct odb_source_files *odb_source_files_new(struct object_database *odb,
const char *payload,
enum odb_new_flags flags);
/*
* Optimize the files object database source by repacking loose objects and
* packfiles as needed. Returns 0 on success, a negative error code otherwise.
*/
int odb_source_files_optimize(struct odb_source *source,
const struct odb_optimize_options *opts);
/*
* Check whether optimization of the files object database source is required
* given the provided options. Returns true if optimization should be
* performed, false otherwise.
*/
bool odb_source_files_optimize_required(struct odb_source *source,
const struct odb_optimize_options *opts);
/*
* Cast the given object database source to the files backend. This will cause
* a BUG in case the source doesn't use this backend.
*/
static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
{
if (source->type != ODB_SOURCE_FILES)
BUG("trying to downcast source of type '%s' to '%s'",
odb_source_type_to_name(source->type),
odb_source_type_to_name(ODB_SOURCE_FILES));
return container_of(source, struct odb_source_files, base);
}
/*
* Find "files" directory by its object directory path. Returns a `NULL`
* pointer in case the object directory could not be found.
*/
struct odb_files_dir *odb_source_files_find_dir(struct object_database *odb, const char *obj_dir);
#endif