Skip to content

Commit c2e3713

Browse files
lucasoshirogitster
authored andcommitted
repo: add the field objects.format
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 <[email protected]> Mentored-by: Patrick Steinhardt <[email protected]> Signed-off-by: Lucas Seiki Oshiro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a92f5ca commit c2e3713

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Documentation/git-repo.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ values that they return:
5555
`layout.shallow`::
5656
`true` if this is a shallow repository, otherwise `false`.
5757

58+
`object.format`::
59+
The object format (hash algorithm) used in the repository.
60+
5861
`references.format`::
5962
The reference storage format. The valid values are:
6063
+

builtin/repo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
3838
return 0;
3939
}
4040

41+
static int get_object_format(struct repository *repo, struct strbuf *buf)
42+
{
43+
strbuf_addstr(buf, repo->hash_algo->name);
44+
return 0;
45+
}
46+
4147
static int get_references_format(struct repository *repo, struct strbuf *buf)
4248
{
4349
strbuf_addstr(buf,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
4955
static const struct field repo_info_fields[] = {
5056
{ "layout.bare", get_layout_bare },
5157
{ "layout.shallow", get_layout_shallow },
58+
{ "object.format", get_object_format },
5259
{ "references.format", get_references_format },
5360
};
5461

t/t1900-repo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ test_expect_success 'setup remote' '
6363
test_repo_info 'shallow repository = true is retrieved correctly' \
6464
'git clone --depth 1 "file://$PWD/remote"' 'shallow' 'layout.shallow' 'true'
6565

66+
test_repo_info 'object.format = sha1 is retrieved correctly' \
67+
'git init --object-format=sha1' 'sha1' 'object.format' 'sha1'
68+
69+
test_repo_info 'object.format = sha256 is retrieved correctly' \
70+
'git init --object-format=sha256' 'sha256' 'object.format' 'sha256'
71+
6672
test_expect_success 'values returned in order requested' '
6773
cat >expect <<-\EOF &&
6874
layout.bare=false

0 commit comments

Comments
 (0)