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.
This commit is contained in:
Patrick Steinhardt
2025-07-29 09:25:20 +02:00
parent 079379ee96
commit 5e058b54ee
2 changed files with 22 additions and 0 deletions

View File

@@ -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)
{

View File

@@ -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