Skip to content

Commit 4081d45

Browse files
committed
Merge branch 'ps/refstorage-extension' into ps/prompt-parse-HEAD-futureproof
* 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 a26002b + 1b22340 commit 4081d45

29 files changed

+334
-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
@@ -72,6 +72,7 @@ static char *remote_name = NULL;
7272
static char *option_branch = NULL;
7373
static struct string_list option_not = STRING_LIST_INIT_NODUP;
7474
static const char *real_git_dir;
75+
static const char *ref_format;
7576
static char *option_upload_pack = "git-upload-pack";
7677
static int option_verbosity;
7778
static int option_progress = -1;
@@ -157,6 +158,8 @@ static struct option builtin_clone_options[] = {
157158
N_("any cloned submodules will be shallow")),
158159
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
159160
N_("separate git dir from working tree")),
161+
OPT_STRING(0, "ref-format", &ref_format, N_("format"),
162+
N_("specify the reference format to use")),
160163
OPT_STRING_LIST('c', "config", &option_config, N_("key=value"),
161164
N_("set config inside the new repository")),
162165
OPT_STRING_LIST(0, "server-option", &server_options,
@@ -932,6 +935,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
932935
int submodule_progress;
933936
int filter_submodules = 0;
934937
int hash_algo;
938+
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
935939
const int do_not_override_repo_unix_permissions = -1;
936940

937941
struct transport_ls_refs_options transport_ls_refs_options =
@@ -957,6 +961,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
957961
if (option_single_branch == -1)
958962
option_single_branch = deepen ? 1 : 0;
959963

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

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

11131124
if (real_git_dir) {
@@ -1290,9 +1301,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12901301
* ours to the same thing.
12911302
*/
12921303
hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
1293-
initialize_repository_version(hash_algo, 1);
1304+
initialize_repository_version(hash_algo, the_repository->ref_storage_format, 1);
12941305
repo_set_hash_algo(the_repository, hash_algo);
1295-
create_reference_database(NULL, 1);
1306+
create_reference_database(the_repository->ref_storage_format, NULL, 1);
12961307

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

builtin/init-db.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "object-file.h"
1212
#include "parse-options.h"
1313
#include "path.h"
14+
#include "refs.h"
1415
#include "setup.h"
1516
#include "strbuf.h"
1617

@@ -57,6 +58,7 @@ static int shared_callback(const struct option *opt, const char *arg, int unset)
5758
static const char *const init_db_usage[] = {
5859
N_("git init [-q | --quiet] [--bare] [--template=<template-directory>]\n"
5960
" [--separate-git-dir <git-dir>] [--object-format=<format>]\n"
61+
" [--ref-format=<format>]\n"
6062
" [-b <branch-name> | --initial-branch=<branch-name>]\n"
6163
" [--shared[=<permissions>]] [<directory>]"),
6264
NULL
@@ -76,8 +78,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
7678
const char *template_dir = NULL;
7779
unsigned int flags = 0;
7880
const char *object_format = NULL;
81+
const char *ref_format = NULL;
7982
const char *initial_branch = NULL;
8083
int hash_algo = GIT_HASH_UNKNOWN;
84+
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
8185
int init_shared_repository = -1;
8286
const struct option init_db_options[] = {
8387
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
@@ -95,6 +99,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
9599
N_("override the name of the initial branch")),
96100
OPT_STRING(0, "object-format", &object_format, N_("hash"),
97101
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")),
98104
OPT_END()
99105
};
100106

@@ -158,6 +164,12 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
158164
die(_("unknown hash algorithm '%s'"), object_format);
159165
}
160166

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+
161173
if (init_shared_repository != -1)
162174
set_shared_repository(init_shared_repository);
163175

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

237249
flags |= INIT_DB_EXIST_OK;
238250
return init_db(git_dir, real_git_dir, template_dir, hash_algo,
239-
initial_branch, init_shared_repository, flags);
251+
ref_storage_format, initial_branch,
252+
init_shared_repository, flags);
240253
}

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)