Skip to content

Commit 318efb9

Browse files
pks-tgitster
authored andcommitted
refs: convert ref storage format to an enum
The ref storage format is tracked as a simple unsigned integer, which makes it harder than necessary to discover what that integer actually is or where its values are defined. Convert the ref storage format to instead be an enum. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a83f7f5 commit 318efb9

File tree

8 files changed

+29
-22
lines changed

8 files changed

+29
-22
lines changed

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
970970
int submodule_progress;
971971
int filter_submodules = 0;
972972
int hash_algo;
973-
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
973+
enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
974974
const int do_not_override_repo_unix_permissions = -1;
975975
const char *template_dir;
976976
char *template_dir_dup = NULL;

builtin/init-db.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
8181
const char *ref_format = NULL;
8282
const char *initial_branch = NULL;
8383
int hash_algo = GIT_HASH_UNKNOWN;
84-
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
84+
enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
8585
int init_shared_repository = -1;
8686
const struct option init_db_options[] = {
8787
OPT_STRING(0, "template", &template_dir, N_("template-directory"),

refs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ static const struct ref_storage_be *refs_backends[] = {
3737
[REF_STORAGE_FORMAT_REFTABLE] = &refs_be_reftable,
3838
};
3939

40-
static const struct ref_storage_be *find_ref_storage_backend(unsigned int ref_storage_format)
40+
static const struct ref_storage_be *find_ref_storage_backend(
41+
enum ref_storage_format ref_storage_format)
4142
{
4243
if (ref_storage_format < ARRAY_SIZE(refs_backends))
4344
return refs_backends[ref_storage_format];
4445
return NULL;
4546
}
4647

47-
unsigned int ref_storage_format_by_name(const char *name)
48+
enum ref_storage_format ref_storage_format_by_name(const char *name)
4849
{
4950
for (unsigned int i = 0; i < ARRAY_SIZE(refs_backends); i++)
5051
if (refs_backends[i] && !strcmp(refs_backends[i]->name, name))
5152
return i;
5253
return REF_STORAGE_FORMAT_UNKNOWN;
5354
}
5455

55-
const char *ref_storage_format_to_name(unsigned int ref_storage_format)
56+
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format)
5657
{
5758
const struct ref_storage_be *be = find_ref_storage_backend(ref_storage_format);
5859
if (!be)

refs.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ struct string_list;
1111
struct string_list_item;
1212
struct worktree;
1313

14-
unsigned int ref_storage_format_by_name(const char *name);
15-
const char *ref_storage_format_to_name(unsigned int ref_storage_format);
14+
enum ref_storage_format {
15+
REF_STORAGE_FORMAT_UNKNOWN,
16+
REF_STORAGE_FORMAT_FILES,
17+
REF_STORAGE_FORMAT_REFTABLE,
18+
};
19+
20+
enum ref_storage_format ref_storage_format_by_name(const char *name);
21+
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format);
1622

1723
/*
1824
* Resolve a reference, recursively following symbolic refererences.

repository.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ void repo_set_compat_hash_algo(struct repository *repo, int algo)
124124
repo_read_loose_object_map(repo);
125125
}
126126

127-
void repo_set_ref_storage_format(struct repository *repo, unsigned int format)
127+
void repo_set_ref_storage_format(struct repository *repo,
128+
enum ref_storage_format format)
128129
{
129130
repo->ref_storage_format = format;
130131
}

repository.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef REPOSITORY_H
22
#define REPOSITORY_H
33

4+
#include "refs.h"
45
#include "strmap.h"
56

67
struct config_set;
@@ -26,10 +27,6 @@ enum fetch_negotiation_setting {
2627
FETCH_NEGOTIATION_NOOP,
2728
};
2829

29-
#define REF_STORAGE_FORMAT_UNKNOWN 0
30-
#define REF_STORAGE_FORMAT_FILES 1
31-
#define REF_STORAGE_FORMAT_REFTABLE 2
32-
3330
struct repo_settings {
3431
int initialized;
3532

@@ -181,7 +178,7 @@ struct repository {
181178
const struct git_hash_algo *compat_hash_algo;
182179

183180
/* Repository's reference storage format, as serialized on disk. */
184-
unsigned int ref_storage_format;
181+
enum ref_storage_format ref_storage_format;
185182

186183
/* A unique-id for tracing purposes. */
187184
int trace2_repo_id;
@@ -220,7 +217,8 @@ void repo_set_gitdir(struct repository *repo, const char *root,
220217
void repo_set_worktree(struct repository *repo, const char *path);
221218
void repo_set_hash_algo(struct repository *repo, int algo);
222219
void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
223-
void repo_set_ref_storage_format(struct repository *repo, unsigned int format);
220+
void repo_set_ref_storage_format(struct repository *repo,
221+
enum ref_storage_format format);
224222
void initialize_repository(struct repository *repo);
225223
RESULT_MUST_BE_USED
226224
int repo_init(struct repository *r, const char *gitdir, const char *worktree);

setup.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
19971997
}
19981998

19991999
void initialize_repository_version(int hash_algo,
2000-
unsigned int ref_storage_format,
2000+
enum ref_storage_format ref_storage_format,
20012001
int reinit)
20022002
{
20032003
char repo_version_string[10];
@@ -2044,7 +2044,7 @@ static int is_reinit(void)
20442044
return ret;
20452045
}
20462046

2047-
void create_reference_database(unsigned int ref_storage_format,
2047+
void create_reference_database(enum ref_storage_format ref_storage_format,
20482048
const char *initial_branch, int quiet)
20492049
{
20502050
struct strbuf err = STRBUF_INIT;
@@ -2243,7 +2243,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
22432243
}
22442244

22452245
static void validate_ref_storage_format(struct repository_format *repo_fmt,
2246-
unsigned int format)
2246+
enum ref_storage_format format)
22472247
{
22482248
const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
22492249

@@ -2263,7 +2263,7 @@ static void validate_ref_storage_format(struct repository_format *repo_fmt,
22632263

22642264
int init_db(const char *git_dir, const char *real_git_dir,
22652265
const char *template_dir, int hash,
2266-
unsigned int ref_storage_format,
2266+
enum ref_storage_format ref_storage_format,
22672267
const char *initial_branch,
22682268
int init_shared_repository, unsigned int flags)
22692269
{

setup.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SETUP_H
22
#define SETUP_H
33

4+
#include "refs.h"
45
#include "string-list.h"
56

67
int is_inside_git_dir(void);
@@ -128,7 +129,7 @@ struct repository_format {
128129
int is_bare;
129130
int hash_algo;
130131
int compat_hash_algo;
131-
unsigned int ref_storage_format;
132+
enum ref_storage_format ref_storage_format;
132133
int sparse_index;
133134
char *work_tree;
134135
struct string_list unknown_extensions;
@@ -192,13 +193,13 @@ const char *get_template_dir(const char *option_template);
192193

193194
int init_db(const char *git_dir, const char *real_git_dir,
194195
const char *template_dir, int hash_algo,
195-
unsigned int ref_storage_format,
196+
enum ref_storage_format ref_storage_format,
196197
const char *initial_branch, int init_shared_repository,
197198
unsigned int flags);
198199
void initialize_repository_version(int hash_algo,
199-
unsigned int ref_storage_format,
200+
enum ref_storage_format ref_storage_format,
200201
int reinit);
201-
void create_reference_database(unsigned int ref_storage_format,
202+
void create_reference_database(enum ref_storage_format ref_storage_format,
202203
const char *initial_branch, int quiet);
203204

204205
/*

0 commit comments

Comments
 (0)