]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb: move computation of normalized objdir into `alt_odb_usable()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 11 Dec 2025 09:30:12 +0000 (10:30 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Dec 2025 09:39:35 +0000 (18:39 +0900)
The function `alt_odb_usable()` receives as input the object database,
the path it's supposed to determine usability for as well as the
normalized path of the main object directory of the repository. The last
part is derived by the function's caller from the object database. As we
already pass the object database to `alt_odb_usable()` it is redundant
information.

Drop the extra parameter and compute the normalized object directory in
the function itself.

While at it, rename the function to `odb_is_source_usable()` to align it
with modern terminology.

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

diff --git a/odb.c b/odb.c
index 699bdbffd1e7a3010329ade5c3ef395d013f6f71..e314f86c3b843ddee6804b5d03a9089538b7bc74 100644 (file)
--- a/odb.c
+++ b/odb.c
@@ -89,17 +89,20 @@ int odb_mkstemp(struct object_database *odb,
 /*
  * Return non-zero iff the path is usable as an alternate object database.
  */
-static int alt_odb_usable(struct object_database *o, const char *path,
-                         const char *normalized_objdir)
+static bool odb_is_source_usable(struct object_database *o, const char *path)
 {
        int r;
+       struct strbuf normalized_objdir = STRBUF_INIT;
+       bool usable = false;
+
+       strbuf_realpath(&normalized_objdir, o->sources->path, 1);
 
        /* Detect cases where alternate disappeared */
        if (!is_directory(path)) {
                error(_("object directory %s does not exist; "
                        "check .git/objects/info/alternates"),
                      path);
-               return 0;
+               goto out;
        }
 
        /*
@@ -116,13 +119,17 @@ static int alt_odb_usable(struct object_database *o, const char *path,
                kh_value(o->source_by_path, p) = o->sources;
        }
 
-       if (fspatheq(path, normalized_objdir))
-               return 0;
+       if (fspatheq(path, normalized_objdir.buf))
+               goto out;
 
        if (kh_get_odb_path_map(o->source_by_path, path) < kh_end(o->source_by_path))
-               return 0;
+               goto out;
+
+       usable = true;
 
-       return 1;
+out:
+       strbuf_release(&normalized_objdir);
+       return usable;
 }
 
 /*
@@ -164,13 +171,10 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
                                                        int depth)
 {
        struct odb_source *alternate = NULL;
-       struct strbuf tmp = STRBUF_INIT;
        khiter_t pos;
        int ret;
 
-       strbuf_realpath(&tmp, odb->sources->path, 1);
-
-       if (!alt_odb_usable(odb, source, tmp.buf))
+       if (!odb_is_source_usable(odb, source))
                goto error;
 
        alternate = odb_source_new(odb, source, false);
@@ -188,7 +192,6 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
        read_info_alternates(odb, alternate->path, depth + 1);
 
  error:
-       strbuf_release(&tmp);
        return alternate;
 }