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>
Patrick Steinhardt committedJul 1, 2025 at 14:22 UTCa1e2581a1e9ca2a85ae0a018ba5fb8fe5db3c322
index e33ba946e4..50a09eb07e 100644--- a/builtin/gc.c+++ b/builtin/gc.c@@ -1018,7 +1018,7 @@ int cmd_gc(int argc, } if (the_repository->settings.gc_write_commit_graph == 1)- write_commit_graph_reachable(the_repository->objects->odb,+ write_commit_graph_reachable(the_repository->objects->sources, !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, NULL);@@ -1271,7 +1271,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED) if (loose_object_auto_limit < 0) return 1;- return for_each_loose_file_in_objdir(the_repository->objects->odb->path,+ return for_each_loose_file_in_objdir(the_repository->objects->sources->path, loose_object_count, NULL, NULL, &count); }@@ -1306,7 +1306,7 @@ static int pack_loose(struct maintenance_run_opts *opts) * Do not start pack-objects process * if there are no loose objects. */- if (!for_each_loose_file_in_objdir(r->objects->odb->path,+ if (!for_each_loose_file_in_objdir(r->objects->sources->path, bail_on_loose, NULL, NULL, NULL)) return 0;@@ -1318,7 +1318,7 @@ static int pack_loose(struct maintenance_run_opts *opts) strvec_push(&pack_proc.args, "--quiet"); else strvec_push(&pack_proc.args, "--no-quiet");- strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path);+ strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->sources->path); pack_proc.in = -1;@@ -1346,7 +1346,7 @@ static int pack_loose(struct maintenance_run_opts *opts) else if (data.batch_size > 0) data.batch_size--; /* Decrease for equality on limit. */- for_each_loose_file_in_objdir(r->objects->odb->path,+ for_each_loose_file_in_objdir(r->objects->sources->path, write_loose_object_to_stdin, NULL, NULL,@@ -1611,7 +1611,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts, int result = 0; struct lock_file lk; struct repository *r = the_repository;- char *lock_path = xstrfmt("%s/maintenance", r->objects->odb->path);+ char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path); if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) { /*@@ -3083,7 +3083,7 @@ static int update_background_schedule(const struct maintenance_start_opts *opts, unsigned int i; int result = 0; struct lock_file lk;- char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path);+ char *lock_path = xstrfmt("%s/schedule", the_repository->objects->sources->path); if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) { if (errno == EEXIST)
builtin/grep.c
+1-1
index 3ce574a605..76b1938bba 100644--- a/builtin/grep.c+++ b/builtin/grep.c@@ -505,7 +505,7 @@ static int grep_submodule(struct grep_opt *opt, * lazily registered as alternates when needed (and except in an * unexpected code interaction, it won't be needed). */- add_submodule_odb_by_path(subrepo->objects->odb->path);+ add_submodule_odb_by_path(subrepo->objects->sources->path); obj_read_unlock(); memcpy(&subopt, opt, sizeof(subopt));
index 53da2116dd..758bc6d0f2 100644--- a/builtin/submodule--helper.c+++ b/builtin/submodule--helper.c@@ -1582,7 +1582,7 @@ static const char alternate_error_advice[] = N_( ); static int add_possible_reference_from_superproject(- struct object_directory *odb, void *sas_cb)+ struct odb_source *alt_odb, void *sas_cb) { struct submodule_alternate_setup *sas = sas_cb; size_t len;@@ -1591,12 +1591,12 @@ static int add_possible_reference_from_superproject( * If the alternate object store is another repository, try the * standard layout with .git/(modules/<name>)+/objects */- if (strip_suffix(odb->path, "/objects", &len)) {+ if (strip_suffix(alt_odb->path, "/objects", &len)) { struct repository alternate; char *sm_alternate; struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT;- strbuf_add(&sb, odb->path, len);+ strbuf_add(&sb, alt_odb->path, len); if (repo_init(&alternate, sb.buf, NULL) < 0) die(_("could not get a repository handle for gitdir '%s'"),
bundle.c
+1-1
index b0a3fee2ef..2ce7525f90 100644--- a/bundle.c+++ b/bundle.c@@ -233,7 +233,7 @@ int verify_bundle(struct repository *r, .quiet = 1, };- if (!r || !r->objects || !r->objects->odb)+ if (!r || !r->objects || !r->objects->sources) return error(_("need a repository to verify a bundle")); for (i = 0; i < p->nr; i++) {
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,
object-file.h
+4-4
index 6f41142452..9a18859b2e 100644--- a/object-file.h+++ b/object-file.h@@ -24,23 +24,23 @@ enum { int index_fd(struct index_state *istate, struct object_id *oid, int fd, struct stat *st, enum object_type type, const char *path, unsigned flags); int index_path(struct index_state *istate, struct object_id *oid, const char *path, struct stat *st, unsigned flags);-struct object_directory;+struct odb_source; /* * Populate and return the loose object cache array corresponding to the * given object ID. */-struct oidtree *odb_loose_cache(struct object_directory *odb,+struct oidtree *odb_loose_cache(struct odb_source *source, const struct object_id *oid); /* Empty the loose object cache for the specified object directory. */-void odb_clear_loose_cache(struct object_directory *odb);+void odb_clear_loose_cache(struct odb_source *source); /* * Put in `buf` the name of the file in the local object database that * would be used to store a loose object with the specified 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);
index f4e8f99d90..5c04a1018f 100644--- a/object-store.c+++ b/object-store.c@@ -27,7 +27,7 @@ #include "write-or-die.h" KHASH_INIT(odb_path_map, const char * /* key: odb_path */,- struct object_directory *, 1, fspathhash, fspatheq)+ struct odb_source *, 1, fspathhash, fspatheq) /* * This is meant to hold a *small* number of objects that you would@@ -104,18 +104,18 @@ static int alt_odb_usable(struct object_database *o, * Prevent the common mistake of listing the same * thing twice, or object directory itself. */- if (!o->odb_by_path) {+ if (!o->source_by_path) { khiter_t p;- o->odb_by_path = kh_init_odb_path_map();- assert(!o->odb->next);- p = kh_put_odb_path_map(o->odb_by_path, o->odb->path, &r);+ o->source_by_path = kh_init_odb_path_map();+ assert(!o->sources->next);+ p = kh_put_odb_path_map(o->source_by_path, o->sources->path, &r); assert(r == 1); /* never used */- kh_value(o->odb_by_path, p) = o->odb;+ kh_value(o->source_by_path, p) = o->sources; } if (fspatheq(path->buf, normalized_objdir)) return 0;- *pos = kh_put_odb_path_map(o->odb_by_path, path->buf, &r);+ *pos = kh_put_odb_path_map(o->source_by_path, path->buf, &r); /* r: 0 = exists, 1 = never used, 2 = deleted */ return r == 0 ? 0 : 1; }@@ -124,7 +124,7 @@ static int alt_odb_usable(struct object_database *o, * Prepare alternate object database registry. * * The variable alt_odb_list points at the list of struct- * object_directory. The elements on this list come from+ * odb_source. The elements on this list come from * non-empty elements from colon separated ALTERNATE_DB_ENVIRONMENT * environment variable, and $GIT_OBJECT_DIRECTORY/info/alternates, * whose contents is similar to that environment variable but can be@@ -141,7 +141,7 @@ static void read_info_alternates(struct repository *r, static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry, const char *relative_base, int depth, const char *normalized_objdir) {- struct object_directory *ent;+ struct odb_source *alternate; struct strbuf pathbuf = STRBUF_INIT; struct strbuf tmp = STRBUF_INIT; khiter_t pos;@@ -170,19 +170,19 @@ static int link_alt_odb_entry(struct repository *r, const struct strbuf *entry, if (!alt_odb_usable(r->objects, &pathbuf, normalized_objdir, &pos)) goto error;- CALLOC_ARRAY(ent, 1);- /* pathbuf.buf is already in r->objects->odb_by_path */- ent->path = strbuf_detach(&pathbuf, NULL);+ CALLOC_ARRAY(alternate, 1);+ /* pathbuf.buf is already in r->objects->source_by_path */+ alternate->path = strbuf_detach(&pathbuf, NULL); /* add the alternate entry */- *r->objects->odb_tail = ent;- r->objects->odb_tail = &(ent->next);- ent->next = NULL;- assert(r->objects->odb_by_path);- kh_value(r->objects->odb_by_path, pos) = ent;+ *r->objects->sources_tail = alternate;+ r->objects->sources_tail = &(alternate->next);+ alternate->next = NULL;+ assert(r->objects->source_by_path);+ kh_value(r->objects->source_by_path, pos) = alternate; /* recursively add alternates */- read_info_alternates(r, ent->path, depth + 1);+ read_info_alternates(r, alternate->path, depth + 1); ret = 0; error: strbuf_release(&tmp);@@ -234,7 +234,7 @@ static void link_alt_odb_entries(struct repository *r, const char *alt, return; }- strbuf_realpath(&objdirbuf, r->objects->odb->path, 1);+ strbuf_realpath(&objdirbuf, r->objects->sources->path, 1); while (*alt) { alt = parse_alt_odb_entry(alt, sep, &entry);@@ -321,9 +321,9 @@ void add_to_alternates_memory(const char *reference) '\n', NULL, 0); }-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy)+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy) {- struct object_directory *new_odb;+ struct odb_source *source; /* * Make sure alternates are initialized, or else our entry may be@@ -335,41 +335,41 @@ struct object_directory *set_temporary_primary_odb(const char *dir, int will_des * Make a new primary odb and link the old primary ODB in as an * alternate */- new_odb = xcalloc(1, sizeof(*new_odb));- new_odb->path = xstrdup(dir);+ source = xcalloc(1, sizeof(*source));+ source->path = xstrdup(dir); /* * Disable ref updates while a temporary odb is active, since * the objects in the database may roll back. */- new_odb->disable_ref_updates = 1;- new_odb->will_destroy = will_destroy;- new_odb->next = the_repository->objects->odb;- the_repository->objects->odb = new_odb;- return new_odb->next;+ source->disable_ref_updates = 1;+ source->will_destroy = will_destroy;+ source->next = the_repository->objects->sources;+ the_repository->objects->sources = source;+ return source->next; }-static void free_object_directory(struct object_directory *odb)+static void free_object_directory(struct odb_source *source) {- free(odb->path);- odb_clear_loose_cache(odb);- loose_object_map_clear(&odb->loose_map);- free(odb);+ free(source->path);+ odb_clear_loose_cache(source);+ loose_object_map_clear(&source->loose_map);+ free(source); }-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path)+void restore_primary_odb(struct odb_source *restore_alt, const char *old_path) {- struct object_directory *cur_odb = the_repository->objects->odb;+ struct odb_source *cur_alt = the_repository->objects->sources;- if (strcmp(old_path, cur_odb->path))+ if (strcmp(old_path, cur_alt->path)) BUG("expected %s as primary object store; found %s",- old_path, cur_odb->path);+ old_path, cur_alt->path);- if (cur_odb->next != restore_odb)+ if (cur_alt->next != restore_alt) BUG("we expect the old primary object store to be the first alternate");- the_repository->objects->odb = restore_odb;- free_object_directory(cur_odb);+ the_repository->objects->sources = restore_alt;+ free_object_directory(cur_alt); } /*@@ -442,15 +442,15 @@ out: return ref_git; }-struct object_directory *find_odb(struct repository *r, const char *obj_dir)+struct odb_source *find_odb(struct repository *r, const char *obj_dir) {- struct object_directory *odb;+ struct odb_source *source; char *obj_dir_real = real_pathdup(obj_dir, 1); struct strbuf odb_path_real = STRBUF_INIT; prepare_alt_odb(r);- for (odb = r->objects->odb; odb; odb = odb->next) {- strbuf_realpath(&odb_path_real, odb->path, 1);+ for (source = r->objects->sources; source; source = source->next) {+ strbuf_realpath(&odb_path_real, source->path, 1); if (!strcmp(obj_dir_real, odb_path_real.buf)) break; }@@ -458,9 +458,9 @@ struct object_directory *find_odb(struct repository *r, const char *obj_dir) free(obj_dir_real); strbuf_release(&odb_path_real);- if (!odb)+ if (!source) die(_("could not find object directory matching %s"), obj_dir);- return odb;+ return source; } static void fill_alternate_refs_command(struct child_process *cmd,@@ -527,14 +527,14 @@ struct alternate_refs_data { void *data; };-static int refs_from_alternate_cb(struct object_directory *e,+static int refs_from_alternate_cb(struct odb_source *alternate, void *data) { struct strbuf path = STRBUF_INIT; size_t base_len; struct alternate_refs_data *cb = data;- if (!strbuf_realpath(&path, e->path, 0))+ if (!strbuf_realpath(&path, alternate->path, 0)) goto out; if (!strbuf_strip_suffix(&path, "/objects")) goto out;@@ -563,12 +563,12 @@ void for_each_alternate_ref(alternate_ref_fn fn, void *data) int foreach_alt_odb(alt_odb_fn fn, void *cb) {- struct object_directory *ent;+ struct odb_source *alternate; int r = 0; prepare_alt_odb(the_repository);- for (ent = the_repository->objects->odb->next; ent; ent = ent->next) {- r = fn(ent, cb);+ for (alternate = the_repository->objects->sources->next; alternate; alternate = alternate->next) {+ r = fn(alternate, cb); if (r) break; }@@ -582,14 +582,14 @@ void prepare_alt_odb(struct repository *r) link_alt_odb_entries(r, r->objects->alternate_db, PATH_SEP, NULL, 0);- read_info_alternates(r, r->objects->odb->path, 0);+ read_info_alternates(r, r->objects->sources->path, 0); r->objects->loaded_alternates = 1; } int has_alt_odb(struct repository *r) { prepare_alt_odb(r);- return !!r->objects->odb->next;+ return !!r->objects->sources->next; } int obj_read_use_lock = 0;@@ -963,15 +963,15 @@ struct object_database *odb_new(void) static void free_object_directories(struct object_database *o) {- while (o->odb) {- struct object_directory *next;+ while (o->sources) {+ struct odb_source *next;- next = o->odb->next;- free_object_directory(o->odb);- o->odb = next;+ next = o->sources->next;+ free_object_directory(o->sources);+ o->sources = next; }- kh_destroy_odb_path_map(o->odb_by_path);- o->odb_by_path = NULL;+ kh_destroy_odb_path_map(o->source_by_path);+ o->source_by_path = NULL; } void odb_clear(struct object_database *o)@@ -986,7 +986,7 @@ void odb_clear(struct object_database *o) o->commit_graph_attempted = 0; free_object_directories(o);- o->odb_tail = NULL;+ o->sources_tail = NULL; o->loaded_alternates = 0; for (size_t i = 0; i < o->cached_object_nr; i++)
object-store.h
+25-13
index a3be27d117..d199d757d7 100644--- a/object-store.h+++ b/object-store.h@@ -13,8 +13,20 @@ struct oidtree; struct strbuf; struct repository;-struct object_directory {- struct object_directory *next;+/*+ * 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; /* * Used to store the results of readdir(3) calls when we are OK@@ -44,8 +56,8 @@ struct object_directory { int will_destroy; /*- * Path to the alternative object store. If this is a relative path,- * it is relative to the current working directory.+ * Path to the source. If this is a relative path, it is relative to+ * the current working directory. */ char *path; };@@ -53,8 +65,8 @@ struct object_directory { void prepare_alt_odb(struct repository *r); int has_alt_odb(struct repository *r); char *compute_alternate_path(const char *path, struct strbuf *err);-struct object_directory *find_odb(struct repository *r, const char *obj_dir);-typedef int alt_odb_fn(struct object_directory *, void *);+struct odb_source *find_odb(struct repository *r, const char *obj_dir);+typedef int alt_odb_fn(struct odb_source *, void *); int foreach_alt_odb(alt_odb_fn, void*); typedef void alternate_ref_fn(const struct object_id *oid, void *); void for_each_alternate_ref(alternate_ref_fn, void *);@@ -76,12 +88,12 @@ void add_to_alternates_memory(const char *dir); * Replace the current writable object directory with the specified temporary * object directory; returns the former primary object directory. */-struct object_directory *set_temporary_primary_odb(const char *dir, int will_destroy);+struct odb_source *set_temporary_primary_odb(const char *dir, int will_destroy); /* * Restore a previous ODB replaced by set_temporary_main_odb. */-void restore_primary_odb(struct object_directory *restore_odb, const char *old_path);+void restore_primary_odb(struct odb_source *restore_alternate, const char *old_path); struct packed_git; struct multi_pack_index;@@ -89,7 +101,7 @@ struct cached_object_entry; /* * The object database encapsulates access to objects in a repository. It- * manages one or more backends that store the actual objects which are+ * manages one or more sources that store the actual objects which are * configured via alternates. */ struct object_database {@@ -98,16 +110,16 @@ struct object_database { * cannot be NULL after initialization). Subsequent directories are * alternates. */- struct object_directory *odb;- struct object_directory **odb_tail;- struct kh_odb_path_map *odb_by_path;+ struct odb_source *sources;+ struct odb_source **sources_tail;+ struct kh_odb_path_map *source_by_path; int loaded_alternates; /* * A list of alternate object directories loaded from the environment; * this should not generally need to be accessed directly, but will- * populate the "odb" list when prepare_alt_odb() is run.+ * populate the "sources" list when prepare_alt_odb() is run. */ char *alternate_db;