[PATCH 3/5] setup: allow speciyfing payloads with default storage formats
While the "git init --ref-storage-format=" switch allows the user to specify a payload that gets passed to the backend, this isn't possible when specifying a default via "init.defaultRefStorageFormat" or via `GIT_DEFAULT_REF_STORAGE_FORMAT`. The same restriction also applies to the object storage format, which needlessly restricts the flexibility and usefulness of these mechanism.
Extend the logic to allow specifying a payload.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
setup.c | 24 +++++++++++++++++++-----
t/t0001-init.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 5 deletions(-)
Show changes to 2 files +70 −5
setup.c, t/t0001-init.sh
diff --git a/setup.c b/setup.c
index 186815c7801..cedc031c54f 100644
--- a/setup.c
+++ b/setup.c
@@ -2797,7 +2797,9 @@ static void separate_git_dir(struct repository *repo,
struct default_format_config {
int hash;
enum ref_storage_format ref_storage_format;
+ char *ref_storage_payload;
enum object_storage_format object_storage_format;
+ char *object_storage_payload;
};
static int read_default_format_config(const char *key, const char *value,
@@ -2823,9 +2825,12 @@ static int read_default_format_config(const char *key, const char *value,
ret = git_config_string(&str, key, value);
if (ret)
goto out;
- cfg->ref_storage_format = ref_storage_format_by_name(str);
+
+ FREE_AND_NULL(cfg->ref_storage_payload);
+ cfg->ref_storage_format = ref_storage_format_by_uri(str, &cfg->ref_storage_payload);
if (cfg->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
warning(_("unknown ref storage format '%s'"), str);
+
goto out;
}
@@ -2833,9 +2838,12 @@ static int read_default_format_config(const char *key, const char *value,
ret = git_config_string(&str, key, value);
if (ret)
goto out;
- cfg->object_storage_format = object_storage_format_by_name(str);
+
+ FREE_AND_NULL(cfg->object_storage_payload);
+ cfg->object_storage_format = object_storage_format_by_uri(str, &cfg->object_storage_payload);
if (cfg->object_storage_format == OBJECT_STORAGE_FORMAT_UNKNOWN)
warning(_("unknown object storage format '%s'"), str);
+
goto out;
}
@@ -2947,17 +2955,19 @@ static void repository_format_configure(struct repository_format *repo_fmt,
ref_storage_format = repo_fmt->ref_storage_format;
ref_storage_payload = xstrdup_or_null(repo_fmt->ref_storage_payload);
} else if ((env = getenv("GIT_DEFAULT_REF_STORAGE_FORMAT"))) {
- ref_storage_format = ref_storage_format_by_name(env);
+ ref_storage_format = ref_storage_format_by_uri(env, &ref_storage_payload);
if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
die(_("unknown ref storage format specified via %s: '%s'"),
"GIT_DEFAULT_REF_STORAGE_FORMAT", env);
} else if ((env = getenv("GIT_DEFAULT_REF_FORMAT"))) {
- ref_storage_format = ref_storage_format_by_name(env);
+ ref_storage_format = ref_storage_format_by_uri(env, &ref_storage_payload);
if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
die(_("unknown ref storage format specified via %s: '%s'"),
"GIT_DEFAULT_REF_FORMAT", env);
} else if (cfg.ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN) {
ref_storage_format = cfg.ref_storage_format;
+ ref_storage_payload = cfg.ref_storage_payload;
+ cfg.ref_storage_payload = NULL;
} else {
ref_storage_format = REF_STORAGE_FORMAT_DEFAULT;
}
@@ -2995,12 +3005,14 @@ static void repository_format_configure(struct repository_format *repo_fmt,
object_storage_format = repo_fmt->object_storage_format;
object_storage_payload = xstrdup_or_null(repo_fmt->object_storage_payload);
} else if ((env = getenv("GIT_DEFAULT_OBJECT_STORAGE_FORMAT"))) {
- object_storage_format = object_storage_format_by_name(env);
+ object_storage_format = object_storage_format_by_uri(env, &object_storage_payload);
if (object_storage_format == OBJECT_STORAGE_FORMAT_UNKNOWN)
die(_("unknown object storage format specified via %s: '%s'"),
"GIT_DEFAULT_OBJECT_STORAGE_FORMAT", env);
} else if (cfg.object_storage_format != OBJECT_STORAGE_FORMAT_UNKNOWN) {
object_storage_format = cfg.object_storage_format;
+ object_storage_payload = cfg.object_storage_payload;
+ cfg.object_storage_payload = NULL;
} else {
object_storage_format = OBJECT_STORAGE_FORMAT_FILES;
}
@@ -3024,10 +3036,12 @@ static void repository_format_configure(struct repository_format *repo_fmt,
die(_("attempt to reinitialize repository with different object storage payload"));
}
+ free(cfg.ref_storage_payload);
free(repo_fmt->ref_storage_payload);
repo_fmt->ref_storage_format = ref_storage_format;
repo_fmt->ref_storage_payload = ref_storage_payload;
+ free(cfg.object_storage_payload);
free(repo_fmt->object_storage_payload);
repo_fmt->object_storage_format = object_storage_format;
repo_fmt->object_storage_payload = object_storage_payload;
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 735ab9d8475..09b7258bf10 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -745,6 +745,33 @@ do
'
done
+test_expect_success 'initializing repository with init.defaultRefStorageFormat and payload' '
+ test_when_finished "rm -rf repo refdir" &&
+
+ BACKEND="files://$(pwd)/refdir" &&
+ test_config_global init.defaultRefStorageFormat "$BACKEND" &&
+ (
+ sane_unset GIT_DEFAULT_REF_STORAGE_FORMAT &&
+ git init repo
+ ) &&
+ test_path_is_file refdir/HEAD &&
+ test_path_is_dir refdir/refs &&
+ git -C repo config get extensions.refstorage >actual &&
+ echo "$BACKEND" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'initializing repository with GIT_DEFAULT_REF_STORAGE_FORMAT and payload' '
+ test_when_finished "rm -rf repo refdir" &&
+ BACKEND="files://$(pwd)/refdir" &&
+ GIT_DEFAULT_REF_STORAGE_FORMAT="$BACKEND" git init repo &&
+ test_path_is_file refdir/HEAD &&
+ test_path_is_dir refdir/refs &&
+ git -C repo config get extensions.refstorage >actual &&
+ echo "$BACKEND" >expect &&
+ test_cmp expect actual
+'
+
test_expect_success "--ref-storage-format= overrides GIT_DEFAULT_REF_STORAGE_FOMAT" '
test_when_finished "rm -rf refformat" &&
GIT_DEFAULT_REF_STORAGE_FORMAT=files git init --ref-storage-format=reftable refformat &&
@@ -1064,6 +1091,30 @@ test_expect_success 'init with init.defaultObjectStorageFormat' '
test_cmp expect actual
'
+test_expect_success 'init with init.defaultObjectStorageFormat and payload' '
+ test_when_finished "rm -rf repo objdir" &&
+ BACKEND="files://$(pwd)/objdir" &&
+ test_config_global init.defaultObjectStorageFormat "$BACKEND" &&
+ (
+ sane_unset GIT_DEFAULT_OBJECT_STORAGE_FORMAT &&
+ git init repo
+ ) &&
+ test_path_is_dir objdir/pack &&
+ git -C repo config get extensions.objectstorage >actual &&
+ echo "$BACKEND" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'init with GIT_DEFAULT_OBJECT_STORAGE_FORMAT and payload' '
+ test_when_finished "rm -rf repo objdir" &&
+ BACKEND="files://$(pwd)/objdir" &&
+ GIT_DEFAULT_OBJECT_STORAGE_FORMAT="$BACKEND" git init repo &&
+ test_path_is_dir objdir/pack &&
+ git -C repo config get extensions.objectstorage >actual &&
+ echo "$BACKEND" >expect &&
+ test_cmp expect actual
+'
+
test_expect_success MINGW 'core.hidedotfiles = false' '
git config --global core.hidedotfiles false &&
rm -rf newdir &&
--
2.56.0.500.g5d06dc02cd.dirty