summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-07-01 14:22:14 +0200
committerJunio C Hamano <gitster@pobox.com>2025-07-01 14:46:34 -0700
commita1e2581a1e9ca2a85ae0a018ba5fb8fe5db3c322 (patch)
tree8443c60b4d56d958eef875e53afa3a33c9643d37 /object-file.c
parent1ace06644926bcf1f05e291e8a9476c977c25eeb (diff)
object-store: rename `object_directory` to `odb_source`
The `object_directory` structure is used as an access point for a single object directory like ".git/objects". While the structure isn't yet fully self-contained, the intent is for it to eventually contain all information required to access objects in one specific location. While the name "object directory" is a good fit for now, this will change over time as we continue with the agenda to make pluggable object databases a thing. Eventually, objects may not be accessed via any kind of directory at all anymore, but they could instead be backed by any kind of durable storage mechanism. While it seems quite far-fetched for now, it is thinkable that eventually this might even be some form of a database, for example. As such, the current name of this structure will become worse over time as we evolve into the direction of pluggable ODBs. Immediate next steps will start to carve out proper self-contained object directories, which requires us to pass in these object directories as parameters. Based on our modern naming schema this means that those functions should then be named after their subsystem, which means that we would start to bake the current name into the codebase more and more. Let's preempt this by renaming the structure. There have been a couple alternatives that were discussed: - `odb_backend` was discarded because it led to the association that one object database has a single backend, but the model is that one alternate has one backend. Furthermore, "backend" is more about the actual backing implementation and less about the high-level concept. - `odb_alternate` was discarded because it is a bit of a stretch to also call the main object directory an "alternate". Instead, pick `odb_source` as the new name. It makes it sufficiently clear that there can be multiple sources and does not cause confusion when mixed with the already-existing "alternate" terminology. In the future, this change allows us to easily introduce for example a `odb_files_source` and other format-specific implementations. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/object-file.c b/object-file.c
index 1ac04c2891..6bad1d3dd1 100644
--- a/object-file.c
+++ b/object-file.c
@@ -55,12 +55,12 @@ static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
}
}
-const char *odb_loose_path(struct object_directory *odb,
+const char *odb_loose_path(struct odb_source *source,
struct strbuf *buf,
const struct object_id *oid)
{
strbuf_reset(buf);
- strbuf_addstr(buf, odb->path);
+ strbuf_addstr(buf, source->path);
strbuf_addch(buf, '/');
fill_loose_path(buf, oid);
return buf->buf;
@@ -88,27 +88,27 @@ int check_and_freshen_file(const char *fn, int freshen)
return 1;
}
-static int check_and_freshen_odb(struct object_directory *odb,
+static int check_and_freshen_odb(struct odb_source *source,
const struct object_id *oid,
int freshen)
{
static struct strbuf path = STRBUF_INIT;
- odb_loose_path(odb, &path, oid);
+ odb_loose_path(source, &path, oid);
return check_and_freshen_file(path.buf, freshen);
}
static int check_and_freshen_local(const struct object_id *oid, int freshen)
{
- return check_and_freshen_odb(the_repository->objects->odb, oid, freshen);
+ return check_and_freshen_odb(the_repository->objects->sources, oid, freshen);
}
static int check_and_freshen_nonlocal(const struct object_id *oid, int freshen)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb->next; odb; odb = odb->next) {
- if (check_and_freshen_odb(odb, oid, freshen))
+ for (source = the_repository->objects->sources->next; source; source = source->next) {
+ if (check_and_freshen_odb(source, oid, freshen))
return 1;
}
return 0;
@@ -202,12 +202,12 @@ int stream_object_signature(struct repository *r, const struct object_id *oid)
static int stat_loose_object(struct repository *r, const struct object_id *oid,
struct stat *st, const char **path)
{
- struct object_directory *odb;
+ struct odb_source *source;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
if (!lstat(*path, st))
return 0;
}
@@ -223,13 +223,13 @@ static int open_loose_object(struct repository *r,
const struct object_id *oid, const char **path)
{
int fd;
- struct object_directory *odb;
+ struct odb_source *source;
int most_interesting_errno = ENOENT;
static struct strbuf buf = STRBUF_INIT;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- *path = odb_loose_path(odb, &buf, oid);
+ for (source = r->objects->sources; source; source = source->next) {
+ *path = odb_loose_path(source, &buf, oid);
fd = git_open(*path);
if (fd >= 0)
return fd;
@@ -244,11 +244,11 @@ static int open_loose_object(struct repository *r,
static int quick_has_loose(struct repository *r,
const struct object_id *oid)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(r);
- for (odb = r->objects->odb; odb; odb = odb->next) {
- if (oidtree_contains(odb_loose_cache(odb, oid), oid))
+ for (source = r->objects->sources; source; source = source->next) {
+ if (oidtree_contains(odb_loose_cache(source, oid), oid))
return 1;
}
return 0;
@@ -694,7 +694,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
/* Finalize a file on disk, and close it. */
static void close_loose_object(int fd, const char *filename)
{
- if (the_repository->objects->odb->will_destroy)
+ if (the_repository->objects->sources->will_destroy)
goto out;
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
@@ -876,7 +876,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
prepare_loose_object_bulk_checkin();
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
fd = start_loose_object_common(&tmp_file, filename.buf, flags,
&stream, compressed, sizeof(compressed),
@@ -1023,7 +1023,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
goto cleanup;
}
- odb_loose_path(the_repository->objects->odb, &filename, oid);
+ odb_loose_path(the_repository->objects->sources, &filename, oid);
/* We finally know the object path, and create the missing dir. */
dirlen = directory_size(filename.buf);
@@ -1437,11 +1437,11 @@ int for_each_loose_file_in_objdir(const char *path,
int for_each_loose_object(each_loose_object_fn cb, void *data,
enum for_each_object_flags flags)
{
- struct object_directory *odb;
+ struct odb_source *source;
prepare_alt_odb(the_repository);
- for (odb = the_repository->objects->odb; odb; odb = odb->next) {
- int r = for_each_loose_file_in_objdir(odb->path, cb, NULL,
+ for (source = the_repository->objects->sources; source; source = source->next) {
+ int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
NULL, data);
if (r)
return r;
@@ -1461,43 +1461,43 @@ static int append_loose_object(const struct object_id *oid,
return 0;
}
-struct oidtree *odb_loose_cache(struct object_directory *odb,
- const struct object_id *oid)
+struct oidtree *odb_loose_cache(struct odb_source *source,
+ const struct object_id *oid)
{
int subdir_nr = oid->hash[0];
struct strbuf buf = STRBUF_INIT;
- size_t word_bits = bitsizeof(odb->loose_objects_subdir_seen[0]);
+ size_t word_bits = bitsizeof(source->loose_objects_subdir_seen[0]);
size_t word_index = subdir_nr / word_bits;
size_t mask = (size_t)1u << (subdir_nr % word_bits);
uint32_t *bitmap;
if (subdir_nr < 0 ||
- subdir_nr >= bitsizeof(odb->loose_objects_subdir_seen))
+ subdir_nr >= bitsizeof(source->loose_objects_subdir_seen))
BUG("subdir_nr out of range");
- bitmap = &odb->loose_objects_subdir_seen[word_index];
+ bitmap = &source->loose_objects_subdir_seen[word_index];
if (*bitmap & mask)
- return odb->loose_objects_cache;
- if (!odb->loose_objects_cache) {
- ALLOC_ARRAY(odb->loose_objects_cache, 1);
- oidtree_init(odb->loose_objects_cache);
+ return source->loose_objects_cache;
+ if (!source->loose_objects_cache) {
+ ALLOC_ARRAY(source->loose_objects_cache, 1);
+ oidtree_init(source->loose_objects_cache);
}
- strbuf_addstr(&buf, odb->path);
+ strbuf_addstr(&buf, source->path);
for_each_file_in_obj_subdir(subdir_nr, &buf,
append_loose_object,
NULL, NULL,
- odb->loose_objects_cache);
+ source->loose_objects_cache);
*bitmap |= mask;
strbuf_release(&buf);
- return odb->loose_objects_cache;
+ return source->loose_objects_cache;
}
-void odb_clear_loose_cache(struct object_directory *odb)
+void odb_clear_loose_cache(struct odb_source *source)
{
- oidtree_clear(odb->loose_objects_cache);
- FREE_AND_NULL(odb->loose_objects_cache);
- memset(&odb->loose_objects_subdir_seen, 0,
- sizeof(odb->loose_objects_subdir_seen));
+ oidtree_clear(source->loose_objects_cache);
+ FREE_AND_NULL(source->loose_objects_cache);
+ memset(&source->loose_objects_subdir_seen, 0,
+ sizeof(source->loose_objects_subdir_seen));
}
static int check_stream_oid(git_zstream *stream,