Skip to content

Commit 32c6fc3

Browse files
committed
Merge branch 'ps/refstorage-extension'
Introduce a new extension "refstorage" so that we can mark a repository that uses a non-default ref backend, like reftable. * ps/refstorage-extension: t9500: write "extensions.refstorage" into config builtin/clone: introduce `--ref-format=` value flag builtin/init: introduce `--ref-format=` value flag builtin/rev-parse: introduce `--show-ref-format` flag t: introduce GIT_TEST_DEFAULT_REF_FORMAT envvar setup: introduce GIT_DEFAULT_REF_FORMAT envvar setup: introduce "extensions.refStorage" extension setup: set repository's formats on init setup: start tracking ref storage format refs: refactor logic to look up storage backends worktree: skip reading HEAD when repairing worktrees t: introduce DEFAULT_REPO_FORMAT prereq
2 parents 481d69d + 1b22340 commit 32c6fc3

29 files changed

+335
-35
lines changed

Documentation/config/extensions.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ Note that this setting should only be set by linkgit:git-init[1] or
77
linkgit:git-clone[1]. Trying to change it after initialization will not
88
work and will produce hard-to-diagnose issues.
99

10+
extensions.refStorage::
11+
Specify the ref storage format to use. The acceptable values are:
12+
+
13+
include::../ref-storage-format.txt[]
14+
+
15+
It is an error to specify this key unless `core.repositoryFormatVersion` is 1.
16+
+
17+
Note that this setting should only be set by linkgit:git-init[1] or
18+
linkgit:git-clone[1]. Trying to change it after initialization will not
19+
work and will produce hard-to-diagnose issues.
20+
1021
extensions.worktreeConfig::
1122
If enabled, then worktrees will load config settings from the
1223
`$GIT_DIR/config.worktree` file in addition to the

Documentation/git-clone.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,12 @@ or `--mirror` is given)
311311
The result is Git repository can be separated from working
312312
tree.
313313

314+
--ref-format=<ref-format::
315+
316+
Specify the given ref storage format for the repository. The valid values are:
317+
+
318+
include::ref-storage-format.txt[]
319+
314320
-j <n>::
315321
--jobs <n>::
316322
The number of submodules fetched at the same time.

Documentation/git-init.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SYNOPSIS
1111
[verse]
1212
'git init' [-q | --quiet] [--bare] [--template=<template-directory>]
1313
[--separate-git-dir <git-dir>] [--object-format=<format>]
14+
[--ref-format=<format>]
1415
[-b <branch-name> | --initial-branch=<branch-name>]
1516
[--shared[=<permissions>]] [<directory>]
1617

@@ -57,6 +58,12 @@ values are 'sha1' and (if enabled) 'sha256'. 'sha1' is the default.
5758
+
5859
include::object-format-disclaimer.txt[]
5960

61+
--ref-format=<format>::
62+
63+
Specify the given ref storage format for the repository. The valid values are:
64+
+
65+
include::ref-storage-format.txt[]
66+
6067
--template=<template-directory>::
6168

6269
Specify the directory from which templates will be used. (See the "TEMPLATE

Documentation/git-rev-parse.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ The following options are unaffected by `--path-format`:
307307
input, multiple algorithms may be printed, space-separated.
308308
If not specified, the default is "storage".
309309

310+
--show-ref-format::
311+
Show the reference storage format used for the repository.
312+
310313

311314
Other Options
312315
~~~~~~~~~~~~~

Documentation/git.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ double-quotes and respecting backslash escapes. E.g., the value
556556
is always used. The default is "sha1".
557557
See `--object-format` in linkgit:git-init[1].
558558

559+
`GIT_DEFAULT_REF_FORMAT`::
560+
If this variable is set, the default reference backend format for new
561+
repositories will be set to this value. The default is "files".
562+
See `--ref-format` in linkgit:git-init[1].
563+
559564
Git Commits
560565
~~~~~~~~~~~
561566
`GIT_AUTHOR_NAME`::

Documentation/ref-storage-format.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `files` for loose files with packed-refs. This is the default.

Documentation/technical/repository-version.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ If set, by default "git config" reads from both "config" and
100100
multiple working directory mode, "config" file is shared while
101101
"config.worktree" is per-working directory (i.e., it's in
102102
GIT_COMMON_DIR/worktrees/<id>/config.worktree)
103+
104+
==== `refStorage`
105+
106+
Specifies the file format for the ref database. The only valid value
107+
is `files` (loose references with a packed-refs file).

builtin/clone.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static char *remote_name = NULL;
7171
static char *option_branch = NULL;
7272
static struct string_list option_not = STRING_LIST_INIT_NODUP;
7373
static const char *real_git_dir;
74+
static const char *ref_format;
7475
static char *option_upload_pack = "git-upload-pack";
7576
static int option_verbosity;
7677
static int option_progress = -1;
@@ -156,6 +157,8 @@ static struct option builtin_clone_options[] = {
156157
N_("any cloned submodules will be shallow")),
157158
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
158159
N_("separate git dir from working tree")),
160+
OPT_STRING(0, "ref-format", &ref_format, N_("format"),
161+
N_("specify the reference format to use")),
159162
OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
160163
N_("set config inside the new repository")),
161164
OPT_STRING_LIST(0, "server-option", &server_options,
@@ -931,6 +934,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
931934
int submodule_progress;
932935
int filter_submodules = 0;
933936
int hash_algo;
937+
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
934938
const int do_not_override_repo_unix_permissions = -1;
935939

936940
struct transport_ls_refs_options transport_ls_refs_options =
@@ -956,6 +960,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
956960
if (option_single_branch == -1)
957961
option_single_branch = deepen ? 1 : 0;
958962

963+
if (ref_format) {
964+
ref_storage_format = ref_storage_format_by_name(ref_format);
965+
if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
966+
die(_("unknown ref storage format '%s'"), ref_format);
967+
}
968+
959969
if (option_mirror)
960970
option_bare = 1;
961971

@@ -1106,7 +1116,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11061116
* repository, and reference backends may persist that information into
11071117
* their on-disk data structures.
11081118
*/
1109-
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL,
1119+
init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN,
1120+
ref_storage_format, NULL,
11101121
do_not_override_repo_unix_permissions, INIT_DB_QUIET | INIT_DB_SKIP_REFDB);
11111122

11121123
if (real_git_dir) {
@@ -1289,9 +1300,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12891300
* ours to the same thing.
12901301
*/
12911302
hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
1292-
initialize_repository_version(hash_algo, 1);
1303+
initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
12931304
repo_set_hash_algo(the_repository, hash_algo);
1294-
create_reference_database(NULL, 1);
1305+
create_reference_database(the_repository->ref_storage_format, NULL, 1);
12951306

12961307
/*
12971308
* Before fetching from the remote, download and install bundle

builtin/init-db.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "object-file.h"
1111
#include "parse-options.h"
1212
#include "path.h"
13+
#include "refs.h"
14+
#include "repository.h"
1315
#include "setup.h"
1416
#include "strbuf.h"
1517

@@ -56,6 +58,7 @@ static int shared_callback(const struct option *opt, const char *arg, int unset)
5658
static const char *const init_db_usage[] = {
5759
N_("git init [-q | --quiet] [--bare] [--template=<template-directory>]\n"
5860
" [--separate-git-dir <git-dir>] [--object-format=<format>]\n"
61+
" [--ref-format=<format>]\n"
5962
" [-b <branch-name> | --initial-branch=<branch-name>]\n"
6063
" [--shared[=<permissions>]] [<directory>]"),
6164
NULL
@@ -75,8 +78,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
7578
const char *template_dir = NULL;
7679
unsigned int flags = 0;
7780
const char *object_format = NULL;
81+
const char *ref_format = NULL;
7882
const char *initial_branch = NULL;
7983
int hash_algo = GIT_HASH_UNKNOWN;
84+
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
8085
int init_shared_repository = -1;
8186
const struct option init_db_options[] = {
8287
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
@@ -94,6 +99,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
9499
N_("override the name of the initial branch")),
95100
OPT_STRING(0, "object-format", &object_format, N_("hash"),
96101
N_("specify the hash algorithm to use")),
102+
OPT_STRING(0, "ref-format", &ref_format, N_("format"),
103+
N_("specify the reference format to use")),
97104
OPT_END()
98105
};
99106

@@ -157,6 +164,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
157164
die(_("unknown hash algorithm '%s'"), object_format);
158165
}
159166

167+
if (ref_format) {
168+
ref_storage_format = ref_storage_format_by_name(ref_format);
169+
if (ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
170+
die(_("unknown ref storage format '%s'"), ref_format);
171+
}
172+
160173
if (init_shared_repository != -1)
161174
set_shared_repository(init_shared_repository);
162175

@@ -235,5 +248,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
235248

236249
flags |= INIT_DB_EXIST_OK;
237250
return init_db(git_dir, real_git_dir, template_dir, hash_algo,
238-
initial_branch, init_shared_repository, flags);
251+
ref_storage_format, initial_branch,
252+
init_shared_repository, flags);
239253
}

builtin/rev-parse.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,10 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
10621062
puts(the_hash_algo->name);
10631063
continue;
10641064
}
1065+
if (!strcmp(arg, "--show-ref-format")) {
1066+
puts(ref_storage_format_to_name(the_repository->ref_storage_format));
1067+
continue;
1068+
}
10651069
if (!strcmp(arg, "--end-of-options")) {
10661070
seen_end_of_options = 1;
10671071
if (filter & (DO_FLAGS | DO_REVS))

0 commit comments

Comments
 (0)