]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: store locality in object database sources
authorPatrick Steinhardt <ps@pks.im>
Mon, 11 Aug 2025 13:46:41 +0000 (15:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Aug 2025 16:22:21 +0000 (09:22 -0700)
Object database sources are classified either as:

  - Local, which means that the source is the repository's primary
    source. This is typically ".git/objects".

  - Non-local, which is everything else. Most importantly this includes
    alternates and quarantine directories.

This locality is often computed ad-hoc by checking whether a given
object source is the first one. This works, but it is quite roundabout.

Refactor the code so that we store locality when creating the sources in
the first place. This makes it both more accessible and robust.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
midx.h
odb.c
odb.h
packfile.c
repository.c

diff --git a/midx.c b/midx.c
index 7d407682e60a6f4adbd9f760f37c73a59a2712a4..b9ca0915a67f10f25728a3335bf3e6a52841f447 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -723,7 +723,7 @@ int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id)
        return 0;
 }
 
-int prepare_multi_pack_index_one(struct odb_source *source, int local)
+int prepare_multi_pack_index_one(struct odb_source *source)
 {
        struct repository *r = source->odb->repo;
 
@@ -734,7 +734,8 @@ int prepare_multi_pack_index_one(struct odb_source *source, int local)
        if (source->midx)
                return 1;
 
-       source->midx = load_multi_pack_index(r, source->path, local);
+       source->midx = load_multi_pack_index(r, source->path,
+                                            source->local);
 
        return !!source->midx;
 }
diff --git a/midx.h b/midx.h
index 076382de8acd26c25c179c03b01994daa15bd711..28c426a8232997d12fec3f5bc91cd7220b90c5ad 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -122,7 +122,7 @@ int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pa
 int midx_contains_pack(struct multi_pack_index *m,
                       const char *idx_or_pack_name);
 int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
-int prepare_multi_pack_index_one(struct odb_source *source, int local);
+int prepare_multi_pack_index_one(struct odb_source *source);
 
 /*
  * Variant of write_midx_file which writes a MIDX containing only the packs
diff --git a/odb.c b/odb.c
index 1f48a0448e398ac8577b4867a356269f65f673ea..1761a50840ddf80a69c610708daec037cea15502 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -176,6 +176,7 @@ static int link_alt_odb_entry(struct object_database *odb,
 
        CALLOC_ARRAY(alternate, 1);
        alternate->odb = odb;
+       alternate->local = false;
        /* pathbuf.buf is already in r->objects->source_by_path */
        alternate->path = strbuf_detach(&pathbuf, NULL);
 
diff --git a/odb.h b/odb.h
index 09177bf430dc38591a619baf864c0aff2eac0de6..f9300439bab3af3191c878e945181fae9b9a8447 100644 (file)
--- a/odb.h
+++ b/odb.h
@@ -63,6 +63,14 @@ struct odb_source {
         */
        struct multi_pack_index *midx;
 
+       /*
+        * 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 is a temporary object store created by the tmp_objdir
         * facility. Disable ref updates since the objects in the store
index 5d73932f50ce6854d695e92d049c6a6c0a1421a7..a38544b87bf2f1168e3fcfbb1c8109df1779b5f0 100644 (file)
@@ -935,14 +935,14 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
                report_garbage(PACKDIR_FILE_GARBAGE, full_name);
 }
 
-static void prepare_packed_git_one(struct odb_source *source, int local)
+static void prepare_packed_git_one(struct odb_source *source)
 {
        struct string_list garbage = STRING_LIST_INIT_DUP;
        struct prepare_pack_data data = {
                .m = source->midx,
                .r = source->odb->repo,
                .garbage = &garbage,
-               .local = local,
+               .local = source->local,
        };
 
        for_each_file_in_pack_dir(source->path, prepare_pack, &data);
@@ -1037,9 +1037,8 @@ static void prepare_packed_git(struct repository *r)
 
        odb_prepare_alternates(r->objects);
        for (source = r->objects->sources; source; source = source->next) {
-               int local = (source == r->objects->sources);
-               prepare_multi_pack_index_one(source, local);
-               prepare_packed_git_one(source, local);
+               prepare_multi_pack_index_one(source);
+               prepare_packed_git_one(source);
        }
        rearrange_packed_git(r);
 
index ecd691181fc97d59241a53765d898300b1f9cf99..97f0578381d894f6bbd417d3ad025937f40d812f 100644 (file)
@@ -168,6 +168,7 @@ void repo_set_gitdir(struct repository *repo,
        if (!repo->objects->sources) {
                CALLOC_ARRAY(repo->objects->sources, 1);
                repo->objects->sources->odb = repo->objects;
+               repo->objects->sources->local = true;
                repo->objects->sources_tail = &repo->objects->sources->next;
        }
        expand_base_dir(&repo->objects->sources->path, o->object_dir,