From 5e058b54ee195aa05355f2c1a335fbc7d212dfdd Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 29 Jul 2025 09:25:20 +0200 Subject: [PATCH] tests/clar: introduce `cl_repo_has_ref_format()` Introduce a function that reads the "refStorage" extension so that we can easily figure out whether a specific repository uses the "files" or any other reference format. While we don't support other formats yet, we are about to add support for the "reftable" format. --- deps/clar/clar_libgit2.c | 20 ++++++++++++++++++++ deps/clar/clar_libgit2.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/deps/clar/clar_libgit2.c b/deps/clar/clar_libgit2.c index c4a2dfc7e..afea57f25 100644 --- a/deps/clar/clar_libgit2.c +++ b/deps/clar/clar_libgit2.c @@ -504,6 +504,26 @@ void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value git_config_free(config); } +int cl_repo_has_ref_format(git_repository *repo, const char *format) +{ + const char *configured_format; + git_config *config; + int result; + + cl_git_pass(git_repository_config_snapshot(&config, repo)); + result = git_config_get_string(&configured_format, config, + "extensions.refStorage"); + if (result < 0 && result != GIT_ENOTFOUND) + cl_fail("cannot read extensions.refStorage"); + if (result < 0) + configured_format = "files"; + + result = !strcmp(configured_format, format); + + git_config_free(config); + return result; +} + /* this is essentially the code from git__unescape modified slightly */ static size_t strip_cr_from_buf(char *start, size_t len) { diff --git a/deps/clar/clar_libgit2.h b/deps/clar/clar_libgit2.h index c6cad6835..90fe4679b 100644 --- a/deps/clar/clar_libgit2.h +++ b/deps/clar/clar_libgit2.h @@ -254,6 +254,8 @@ int cl_repo_get_int(git_repository *repo, const char *cfg); void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value); +int cl_repo_has_ref_format(git_repository *repo, const char *format); + /* * set up a fake "home" directory -- automatically configures cleanup * function to restore the home directory, although you can call it