]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add the field objects.format
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Thu, 4 Sep 2025 13:40:17 +0000 (10:40 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Sep 2025 18:36:40 +0000 (11:36 -0700)
The flag `--show-object-format` from git-rev-parse is used for
retrieving the object storage format. This way, it is used for
querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `objects.format` to the git-repo-info subcommand
containing that information.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-repo.adoc
builtin/repo.c
t/t1900-repo.sh

index 6f5ee882157c1657495a3397dd9f4af0374a0c88..209afd1b6152be5bfce3eea56ca5c8538e7cd657 100644 (file)
@@ -55,6 +55,9 @@ values that they return:
 `layout.shallow`::
        `true` if this is a shallow repository, otherwise `false`.
 
+`object.format`::
+       The object format (hash algorithm) used in the repository.
+
 `references.format`::
        The reference storage format. The valid values are:
 +
index dc9a2674694667f0743703178a1bf21654b72657..bbb0966f2d2284d146c0dad629cdbe019122f8d0 100644 (file)
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
        return 0;
 }
 
+static int get_object_format(struct repository *repo, struct strbuf *buf)
+{
+       strbuf_addstr(buf, repo->hash_algo->name);
+       return 0;
+}
+
 static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
        strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 static const struct field repo_info_fields[] = {
        { "layout.bare", get_layout_bare },
        { "layout.shallow", get_layout_shallow },
+       { "object.format", get_object_format },
        { "references.format", get_references_format },
 };
 
index ddf788d5a263181aeba81cf7892a56efa570cf77..2beba67889af25d3547a223e62f45037dba7f171 100755 (executable)
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
 test_repo_info 'shallow repository = true is retrieved correctly' \
        'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
 
+test_repo_info 'object.format = sha1 is retrieved correctly' \
+       'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
+
+test_repo_info 'object.format = sha256 is retrieved correctly' \
+       'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
+
 test_expect_success 'values returned in order requested' '
        cat >expect <<-\EOF &&
        layout.bare=false