[PATCH v3 6/6] odb/source: drop `local` flag
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 15, 2026, 05:28 UTC
- Message-ID
- <20261015-pks-odb-files-alternates-cleanups-v3-6-bfc62fd780eb@pks.im>
- In-Reply-To
- <20261015-pks-odb-files-alternates-cleanups-v3-0-bfc62fd780eb@pks.im>
The `local` flag indicates whether a given `struct odb_source` is a local source or not, where "local" is defined as being the object directory that is directly attached to the current repository. But now that alternates are handled in the "files" backend, this property is not something that even makes sense anymore to have on the generic source.
In fact, we already have a partial replacement for this field in `struct odb_files_dir`. The only other site that requires it is the packed object database source, because it propagates the bit into the packfiles it is opening.
Drop the flag from `struct odb_source` and instead move it into the packed source.
Note that we stop considering the `local` bit when iterating through all loose objects with the `ODB_FOR_EACH_OBJECT_LOCAL_ONLY` flag. This is fine though, as we already handle the flag in the "files" backend itself, where we skip over any object directory that is not marked as local.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- midx.c | 2 +- odb/source-files.c | 4 ++-- odb/source-inmemory.c | 10 +++++++--- odb/source-loose.c | 7 ++----- odb/source-loose.h | 3 +-- odb/source-packed.c | 5 +++-- odb/source-packed.h | 7 +++++++ odb/source.c | 4 +--- odb/source.h | 13 +------------ repack.c | 2 +- 10 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/midx.c b/midx.c index dc0c728401..2d4feeeade 100644 --- a/midx.c +++ b/midx.c @@ -470,7 +470,7 @@ int prepare_midx_pack(struct multi_pack_index *m, strbuf_addf(&pack_name, "%s/pack/%s", packed->base.path, m->pack_names[pack_int_id]); p = packfile_store_load_pack(packed, - pack_name.buf, packed->base.local); + pack_name.buf, packed->local); strbuf_release(&pack_name); if (!p) { diff --git a/odb/source-files.c b/odb/source-files.c index 9788a5adf4..5b4277fbfd 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -33,7 +33,7 @@ struct odb_files_dir *odb_files_dir_new(struct object_database *odb, CALLOC_ARRAY(dir, 1); dir->abspath = absolute_pathdup(path); dir->local = local; - dir->loose = odb_source_loose_new(odb, path, local); + dir->loose = odb_source_loose_new(odb, path); dir->packed = odb_source_packed_new(odb, path, local); return dir; @@ -1265,7 +1265,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, object_dir = xstrfmt("%s/objects", odb->repo->commondir); CALLOC_ARRAY(files, 1); - odb_source_init(&files->base, odb, ODB_SOURCE_FILES, object_dir, true); + odb_source_init(&files->base, odb, ODB_SOURCE_FILES, object_dir); hashmap_init(&files->dirs_by_path, odb_files_dir_by_path_cmp, files, 0); files->dirs_paths_icase = -1; diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c index 868e723c81..75cf29fa9d 100644 --- a/odb/source-inmemory.c +++ b/odb/source-inmemory.c @@ -161,8 +161,12 @@ static int odb_source_inmemory_for_each_object(struct odb_source *source, }; struct object_id null_oid = { 0 }; - if ((opts->flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY) || - (opts->flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY && !source->local)) + /* + * In-memory objects are neither promisor objects nor do they live in + * the local object directory, so there is nothing to iterate over. + */ + if (opts->flags & (ODB_FOR_EACH_OBJECT_PROMISOR_ONLY | + ODB_FOR_EACH_OBJECT_LOCAL_ONLY)) return 0; if (!inmemory->objects) return 0; @@ -369,7 +373,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb) struct odb_source_inmemory *source; CALLOC_ARRAY(source, 1); - odb_source_init(&source->base, odb, ODB_SOURCE_INMEMORY, "source", false); + odb_source_init(&source->base, odb, ODB_SOURCE_INMEMORY, "source"); source->base.free = odb_source_inmemory_free; source->base.close = odb_source_inmemory_close; diff --git a/odb/source-loose.c b/odb/source-loose.c index 180ce7403f..50cb388c35 100644 --- a/odb/source-loose.c +++ b/odb/source-loose.c @@ -464,8 +464,6 @@ static int odb_source_loose_for_each_object(struct odb_source *source, /* There are no loose promisor objects, so we can return immediately. */ if ((opts->flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY)) return 0; - if ((opts->flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY) && !source->local) - return 0; if (opts->prefix) return oidtree_each(odb_source_loose_cache(loose, opts->prefix), @@ -1108,13 +1106,12 @@ static int odb_source_loose_fsck(struct odb_source *source, } struct odb_source_loose *odb_source_loose_new(struct object_database *odb, - const char *path, - bool local) + const char *path) { struct odb_source_loose *loose; CALLOC_ARRAY(loose, 1); - odb_source_init(&loose->base, odb, ODB_SOURCE_LOOSE, path, local); + odb_source_init(&loose->base, odb, ODB_SOURCE_LOOSE, path); loose->base.free = odb_source_loose_free; loose->base.close = odb_source_loose_close; diff --git a/odb/source-loose.h b/odb/source-loose.h index 7c7e845fe3..a6ae808662 100644 --- a/odb/source-loose.h +++ b/odb/source-loose.h @@ -34,8 +34,7 @@ struct odb_source_loose { }; struct odb_source_loose *odb_source_loose_new(struct object_database *odb, - const char *path, - bool local); + const char *path); /* * Cast the given object database source to the loose backend. This will cause diff --git a/odb/source-packed.c b/odb/source-packed.c index 48fe00c2bc..7fcbbb4fe9 100644 --- a/odb/source-packed.c +++ b/odb/source-packed.c @@ -740,7 +740,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len, midx_contains_pack(data->source->midx, file_name))) { char *trimmed_path = xstrndup(full_name, full_name_len); packfile_store_load_pack(data->source, - trimmed_path, data->source->base.local); + trimmed_path, data->source->local); free(trimmed_path); } @@ -988,8 +988,9 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb, struct odb_source_packed *packed; CALLOC_ARRAY(packed, 1); - odb_source_init(&packed->base, odb, ODB_SOURCE_PACKED, path, local); + odb_source_init(&packed->base, odb, ODB_SOURCE_PACKED, path); strmap_init(&packed->packs_by_path); + packed->local = local; packed->base.free = odb_source_packed_free; packed->base.close = odb_source_packed_close; diff --git a/odb/source-packed.h b/odb/source-packed.h index a0f6b5096d..e8a7b08fbb 100644 --- a/odb/source-packed.h +++ b/odb/source-packed.h @@ -41,6 +41,13 @@ struct odb_source_packed { */ struct strmap packs_by_path; + /* + * Whether this store is part of the local object directory of the + * owning repository. Packfiles loaded via this store inherit this + * flag via `pack_local`. Stores for alternates are not local. + */ + bool local; + /* * Whether packfiles have already been populated with this store's * packs. diff --git a/odb/source.c b/odb/source.c index b25ef14df8..4155fc22da 100644 --- a/odb/source.c +++ b/odb/source.c @@ -32,12 +32,10 @@ struct odb_source *odb_source_new(struct object_database *odb, void odb_source_init(struct odb_source *source, struct object_database *odb, enum odb_source_type type, - const char *path, - bool local) + const char *path) { source->odb = odb; source->type = type; - source->local = local; source->path = xstrdup(path); } diff --git a/odb/source.h b/odb/source.h index 0cfe762376..8b839caa39 100644 --- a/odb/source.h +++ b/odb/source.h @@ -58,14 +58,6 @@ struct odb_source { /* The type used by this source. */ enum odb_source_type type; - /* - * 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; - /* * Path to the source. If this is a relative path, it is relative to * the current working directory. @@ -304,8 +296,6 @@ struct odb_source *odb_source_new(struct object_database *odb, /* * Initialize the 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. * * This function is only supposed to be called by specific object source * implementations. @@ -313,8 +303,7 @@ struct odb_source *odb_source_new(struct object_database *odb, void odb_source_init(struct odb_source *source, struct object_database *odb, enum odb_source_type type, - const char *path, - bool local); + const char *path); /* * Free the object database source, releasing all associated resources and diff --git a/repack.c b/repack.c index 53c34197f3..4c6d1f507d 100644 --- a/repack.c +++ b/repack.c @@ -62,7 +62,7 @@ void repack_remove_redundant_pack(struct repository *repo, const char *dir_name, struct odb_source_files *files = odb_source_files_downcast(repo->objects->source); struct multi_pack_index *m = get_multi_pack_index(files->dirs->packed); strbuf_addf(&buf, "%s.pack", base_name); - if (m && files->base.local && midx_contains_pack(m, buf.buf)) { + if (m && files->dirs->local && midx_contains_pack(m, buf.buf)) { clear_midx_file(repo); if (!wrote_incremental_midx) clear_incremental_midx_files(repo, NULL);
-- 2.56.0.212.g129ede20d9.dirty