mirror of
https://github.com/git/git.git
synced 2026-02-27 10:25:07 +00:00
odb: split struct odb_source into separate header
Subsequent commits will expand the `struct odb_source` to become a generic interface for accessing an object database source. As part of these refactorings we'll add a set of function pointers that will significantly expand the structure overall. Prepare for this by splitting out the `struct odb_source` into a separate header. This keeps the high-level object database interface detached from the low-level object database sources. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b1af291b4a
commit
cfcfdf6592
1
Makefile
1
Makefile
@@ -1214,6 +1214,7 @@ LIB_OBJS += object-file.o
|
||||
LIB_OBJS += object-name.o
|
||||
LIB_OBJS += object.o
|
||||
LIB_OBJS += odb.o
|
||||
LIB_OBJS += odb/source.o
|
||||
LIB_OBJS += odb/streaming.o
|
||||
LIB_OBJS += oid-array.o
|
||||
LIB_OBJS += oidmap.o
|
||||
|
||||
@@ -397,6 +397,7 @@ libgit_sources = [
|
||||
'object-name.c',
|
||||
'object.c',
|
||||
'odb.c',
|
||||
'odb/source.c',
|
||||
'odb/streaming.c',
|
||||
'oid-array.c',
|
||||
'oidmap.c',
|
||||
|
||||
25
odb.c
25
odb.c
@@ -217,23 +217,6 @@ static void odb_source_read_alternates(struct odb_source *source,
|
||||
free(path);
|
||||
}
|
||||
|
||||
|
||||
static struct odb_source *odb_source_new(struct object_database *odb,
|
||||
const char *path,
|
||||
bool local)
|
||||
{
|
||||
struct odb_source *source;
|
||||
|
||||
CALLOC_ARRAY(source, 1);
|
||||
source->odb = odb;
|
||||
source->local = local;
|
||||
source->path = xstrdup(path);
|
||||
source->loose = odb_source_loose_new(source);
|
||||
source->packfiles = packfile_store_new(source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
static struct odb_source *odb_add_alternate_recursively(struct object_database *odb,
|
||||
const char *source,
|
||||
int depth)
|
||||
@@ -373,14 +356,6 @@ struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
|
||||
return source->next;
|
||||
}
|
||||
|
||||
static void odb_source_free(struct odb_source *source)
|
||||
{
|
||||
free(source->path);
|
||||
odb_source_loose_free(source->loose);
|
||||
packfile_store_free(source->packfiles);
|
||||
free(source);
|
||||
}
|
||||
|
||||
void odb_restore_primary_source(struct object_database *odb,
|
||||
struct odb_source *restore_source,
|
||||
const char *old_path)
|
||||
|
||||
45
odb.h
45
odb.h
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "object.h"
|
||||
#include "odb/source.h"
|
||||
#include "oidset.h"
|
||||
#include "oidmap.h"
|
||||
#include "string-list.h"
|
||||
@@ -30,50 +31,6 @@ extern int fetch_if_missing;
|
||||
*/
|
||||
char *compute_alternate_path(const char *path, struct strbuf *err);
|
||||
|
||||
/*
|
||||
* The source is the part of the object database that stores the actual
|
||||
* objects. It thus encapsulates the logic to read and write the specific
|
||||
* on-disk format. An object database can have multiple sources:
|
||||
*
|
||||
* - The primary source, which is typically located in "$GIT_DIR/objects".
|
||||
* This is where new objects are usually written to.
|
||||
*
|
||||
* - Alternate sources, which are configured via "objects/info/alternates" or
|
||||
* via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
|
||||
* alternate sources are only used to read objects.
|
||||
*/
|
||||
struct odb_source {
|
||||
struct odb_source *next;
|
||||
|
||||
/* Object database that owns this object source. */
|
||||
struct object_database *odb;
|
||||
|
||||
/* Private state for loose objects. */
|
||||
struct odb_source_loose *loose;
|
||||
|
||||
/* Should only be accessed directly by packfile.c and midx.c. */
|
||||
struct packfile_store *packfiles;
|
||||
|
||||
/*
|
||||
* Figure out whether this is the local source of the owning
|
||||
* repository, which would typically be its ".git/objects" directory.
|
||||
* This local object directory is usually where objects would be
|
||||
* written to.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
char *path;
|
||||
};
|
||||
|
||||
struct packed_git;
|
||||
struct packfile_store;
|
||||
struct cached_object_entry;
|
||||
|
||||
28
odb/source.c
Normal file
28
odb/source.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "git-compat-util.h"
|
||||
#include "object-file.h"
|
||||
#include "odb/source.h"
|
||||
#include "packfile.h"
|
||||
|
||||
struct odb_source *odb_source_new(struct object_database *odb,
|
||||
const char *path,
|
||||
bool local)
|
||||
{
|
||||
struct odb_source *source;
|
||||
|
||||
CALLOC_ARRAY(source, 1);
|
||||
source->odb = odb;
|
||||
source->local = local;
|
||||
source->path = xstrdup(path);
|
||||
source->loose = odb_source_loose_new(source);
|
||||
source->packfiles = packfile_store_new(source);
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
void odb_source_free(struct odb_source *source)
|
||||
{
|
||||
free(source->path);
|
||||
odb_source_loose_free(source->loose);
|
||||
packfile_store_free(source->packfiles);
|
||||
free(source);
|
||||
}
|
||||
60
odb/source.h
Normal file
60
odb/source.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef ODB_SOURCE_H
|
||||
#define ODB_SOURCE_H
|
||||
|
||||
/*
|
||||
* The source is the part of the object database that stores the actual
|
||||
* objects. It thus encapsulates the logic to read and write the specific
|
||||
* on-disk format. An object database can have multiple sources:
|
||||
*
|
||||
* - The primary source, which is typically located in "$GIT_DIR/objects".
|
||||
* This is where new objects are usually written to.
|
||||
*
|
||||
* - Alternate sources, which are configured via "objects/info/alternates" or
|
||||
* via the GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable. These
|
||||
* alternate sources are only used to read objects.
|
||||
*/
|
||||
struct odb_source {
|
||||
struct odb_source *next;
|
||||
|
||||
/* Object database that owns this object source. */
|
||||
struct object_database *odb;
|
||||
|
||||
/* Private state for loose objects. */
|
||||
struct odb_source_loose *loose;
|
||||
|
||||
/* Should only be accessed directly by packfile.c and midx.c. */
|
||||
struct packfile_store *packfiles;
|
||||
|
||||
/*
|
||||
* Figure out whether this is the local source of the owning
|
||||
* repository, which would typically be its ".git/objects" directory.
|
||||
* This local object directory is usually where objects would be
|
||||
* written to.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
char *path;
|
||||
};
|
||||
|
||||
/*
|
||||
* Allocate and initialize a new source for the given object database located
|
||||
* at `path`. `local` indicates whether or not the source is the local and thus
|
||||
* primary object source of the object database.
|
||||
*/
|
||||
struct odb_source *odb_source_new(struct object_database *odb,
|
||||
const char *path,
|
||||
bool local);
|
||||
|
||||
/* Free the object database source, releasing all associated resources. */
|
||||
void odb_source_free(struct odb_source *source);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user