Skip to content

Commit efadafd

Browse files
mjcheethamdscho
authored andcommitted
scalar: add --ref-format option to scalar clone
Add the `--ref-format` option to the `scalar clone` command. This will allow users to opt-in to creating a Scalar repository using alternative ref storage backends, such as reftable. Example: scalar clone --ref-format reftable $URL Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 8124d81 commit efadafd

2 files changed

Lines changed: 51 additions & 5 deletions

File tree

‎scalar.c‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ static int cmd_clone(int argc, const char **argv)
784784
const char *cache_server_url = NULL, *local_cache_root = NULL;
785785
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
786786
int gvfs_protocol = -1;
787+
const char *ref_format = NULL;
787788

788789
struct option clone_options[] = {
789790
OPT_STRING('b', "branch", &branch, N_("<branch>"),
@@ -807,18 +808,22 @@ static int cmd_clone(int argc, const char **argv)
807808
OPT_STRING(0, "local-cache-path", &local_cache_root,
808809
N_("<path>"),
809810
N_("override the path for the local Scalar cache")),
811+
OPT_STRING(0, "ref-format", &ref_format, N_("format"),
812+
N_("specify the reference format to use")),
810813
OPT_HIDDEN_BOOL(0, "no-fetch-commits-and-trees",
811814
&dummy, N_("no longer used")),
812815
OPT_END(),
813816
};
814817
const char * const clone_usage[] = {
815818
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
816-
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] <url> [<enlistment>]"),
819+
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
820+
"\t<url> [<enlistment>]"),
817821
NULL
818822
};
819823
const char *url;
820824
char *enlistment = NULL, *dir = NULL;
821825
struct strbuf buf = STRBUF_INIT;
826+
struct strvec init_argv = STRVEC_INIT;
822827
int res;
823828

824829
argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0);
@@ -866,16 +871,26 @@ static int cmd_clone(int argc, const char **argv)
866871
if (!local_cache_root)
867872
die(_("could not determine local cache root"));
868873

869-
strbuf_reset(&buf);
874+
strvec_clear(&init_argv);
875+
strvec_pushf(&init_argv, "-c");
870876
if (branch)
871-
strbuf_addf(&buf, "init.defaultBranch=%s", branch);
877+
strvec_pushf(&init_argv, "init.defaultBranch=%s", branch);
872878
else {
873879
char *b = repo_default_branch_name(the_repository, 1);
874-
strbuf_addf(&buf, "init.defaultBranch=%s", b);
880+
strvec_pushf(&init_argv, "init.defaultBranch=%s", b);
875881
free(b);
876882
}
877883

878-
if ((res = run_git("-c", buf.buf, "init", "--", dir, NULL)))
884+
strvec_push(&init_argv, "init");
885+
886+
if (ref_format) {
887+
strvec_push(&init_argv, "--ref-format");
888+
strvec_push(&init_argv, ref_format);
889+
}
890+
891+
strvec_push(&init_argv, "--");
892+
strvec_push(&init_argv, dir);
893+
if ((res = run_git_argv(&init_argv)))
879894
goto cleanup;
880895

881896
if (chdir(dir) < 0) {
@@ -1025,6 +1040,7 @@ static int cmd_clone(int argc, const char **argv)
10251040
free(enlistment);
10261041
free(dir);
10271042
strbuf_release(&buf);
1043+
strvec_clear(&init_argv);
10281044
free(default_cache_server_url);
10291045
free(local_cache_root_abs);
10301046
return res;

‎t/t9211-scalar-clone.sh‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,34 @@ test_expect_success '`scalar clone --no-src`' '
201201
test_cmp with without
202202
'
203203

204+
test_expect_success '`scalar clone --ref-format`' '
205+
scalar clone "file://$(pwd)/to-clone" refs-default &&
206+
scalar clone --ref-format files "file://$(pwd)/to-clone" refs-files &&
207+
scalar clone --ref-format reftable "file://$(pwd)/to-clone" refs-reftable &&
208+
209+
test_path_is_dir refs-default/src &&
210+
test_path_is_dir refs-files/src &&
211+
test_path_is_dir refs-reftable/src &&
212+
213+
(
214+
cd refs-default/src &&
215+
case test_detect_ref_format in
216+
files)
217+
test_must_fail git config --local extensions.refstorage
218+
;;
219+
reftable)
220+
test_cmp_config reftable extensions.refstorage
221+
;;
222+
esac
223+
) &&
224+
(
225+
cd refs-files/src &&
226+
test_must_fail git config --local extensions.refstorage
227+
) &&
228+
(
229+
cd refs-reftable/src &&
230+
test_cmp_config reftable extensions.refstorage
231+
)
232+
'
233+
204234
test_done

0 commit comments

Comments
 (0)