mirror of
https://github.com/git/git.git
synced 2024-09-08 03:50:44 +02:00
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a83f7f51e1
commit
318efb966b
@ -970,7 +970,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
|
||||
int submodule_progress;
|
||||
int filter_submodules = 0;
|
||||
int hash_algo;
|
||||
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
|
||||
enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
|
||||
const int do_not_override_repo_unix_permissions = -1;
|
||||
const char *template_dir;
|
||||
char *template_dir_dup = NULL;
|
||||
|
@ -81,7 +81,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
|
||||
const char *ref_format = NULL;
|
||||
const char *initial_branch = NULL;
|
||||
int hash_algo = GIT_HASH_UNKNOWN;
|
||||
unsigned int ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
|
||||
enum ref_storage_format ref_storage_format = REF_STORAGE_FORMAT_UNKNOWN;
|
||||
int init_shared_repository = -1;
|
||||
const struct option init_db_options[] = {
|
||||
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
|
||||
|
7
refs.c
7
refs.c
@ -37,14 +37,15 @@ static const struct ref_storage_be *refs_backends[] = {
|
||||
[REF_STORAGE_FORMAT_REFTABLE] = &refs_be_reftable,
|
||||
};
|
||||
|
||||
static const struct ref_storage_be *find_ref_storage_backend(unsigned int ref_storage_format)
|
||||
static const struct ref_storage_be *find_ref_storage_backend(
|
||||
enum ref_storage_format ref_storage_format)
|
||||
{
|
||||
if (ref_storage_format < ARRAY_SIZE(refs_backends))
|
||||
return refs_backends[ref_storage_format];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int ref_storage_format_by_name(const char *name)
|
||||
enum ref_storage_format ref_storage_format_by_name(const char *name)
|
||||
{
|
||||
for (unsigned int i = 0; i < ARRAY_SIZE(refs_backends); i++)
|
||||
if (refs_backends[i] && !strcmp(refs_backends[i]->name, name))
|
||||
@ -52,7 +53,7 @@ unsigned int ref_storage_format_by_name(const char *name)
|
||||
return REF_STORAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
|
||||
const char *ref_storage_format_to_name(unsigned int ref_storage_format)
|
||||
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format)
|
||||
{
|
||||
const struct ref_storage_be *be = find_ref_storage_backend(ref_storage_format);
|
||||
if (!be)
|
||||
|
10
refs.h
10
refs.h
@ -11,8 +11,14 @@ struct string_list;
|
||||
struct string_list_item;
|
||||
struct worktree;
|
||||
|
||||
unsigned int ref_storage_format_by_name(const char *name);
|
||||
const char *ref_storage_format_to_name(unsigned int ref_storage_format);
|
||||
enum ref_storage_format {
|
||||
REF_STORAGE_FORMAT_UNKNOWN,
|
||||
REF_STORAGE_FORMAT_FILES,
|
||||
REF_STORAGE_FORMAT_REFTABLE,
|
||||
};
|
||||
|
||||
enum ref_storage_format ref_storage_format_by_name(const char *name);
|
||||
const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_format);
|
||||
|
||||
/*
|
||||
* Resolve a reference, recursively following symbolic refererences.
|
||||
|
@ -124,7 +124,8 @@ void repo_set_compat_hash_algo(struct repository *repo, int algo)
|
||||
repo_read_loose_object_map(repo);
|
||||
}
|
||||
|
||||
void repo_set_ref_storage_format(struct repository *repo, unsigned int format)
|
||||
void repo_set_ref_storage_format(struct repository *repo,
|
||||
enum ref_storage_format format)
|
||||
{
|
||||
repo->ref_storage_format = format;
|
||||
}
|
||||
|
10
repository.h
10
repository.h
@ -1,6 +1,7 @@
|
||||
#ifndef REPOSITORY_H
|
||||
#define REPOSITORY_H
|
||||
|
||||
#include "refs.h"
|
||||
#include "strmap.h"
|
||||
|
||||
struct config_set;
|
||||
@ -26,10 +27,6 @@ enum fetch_negotiation_setting {
|
||||
FETCH_NEGOTIATION_NOOP,
|
||||
};
|
||||
|
||||
#define REF_STORAGE_FORMAT_UNKNOWN 0
|
||||
#define REF_STORAGE_FORMAT_FILES 1
|
||||
#define REF_STORAGE_FORMAT_REFTABLE 2
|
||||
|
||||
struct repo_settings {
|
||||
int initialized;
|
||||
|
||||
@ -181,7 +178,7 @@ struct repository {
|
||||
const struct git_hash_algo *compat_hash_algo;
|
||||
|
||||
/* Repository's reference storage format, as serialized on disk. */
|
||||
unsigned int ref_storage_format;
|
||||
enum ref_storage_format ref_storage_format;
|
||||
|
||||
/* A unique-id for tracing purposes. */
|
||||
int trace2_repo_id;
|
||||
@ -220,7 +217,8 @@ void repo_set_gitdir(struct repository *repo, const char *root,
|
||||
void repo_set_worktree(struct repository *repo, const char *path);
|
||||
void repo_set_hash_algo(struct repository *repo, int algo);
|
||||
void repo_set_compat_hash_algo(struct repository *repo, int compat_algo);
|
||||
void repo_set_ref_storage_format(struct repository *repo, unsigned int format);
|
||||
void repo_set_ref_storage_format(struct repository *repo,
|
||||
enum ref_storage_format format);
|
||||
void initialize_repository(struct repository *repo);
|
||||
RESULT_MUST_BE_USED
|
||||
int repo_init(struct repository *r, const char *gitdir, const char *worktree);
|
||||
|
8
setup.c
8
setup.c
@ -1997,7 +1997,7 @@ static int needs_work_tree_config(const char *git_dir, const char *work_tree)
|
||||
}
|
||||
|
||||
void initialize_repository_version(int hash_algo,
|
||||
unsigned int ref_storage_format,
|
||||
enum ref_storage_format ref_storage_format,
|
||||
int reinit)
|
||||
{
|
||||
char repo_version_string[10];
|
||||
@ -2044,7 +2044,7 @@ static int is_reinit(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void create_reference_database(unsigned int ref_storage_format,
|
||||
void create_reference_database(enum ref_storage_format ref_storage_format,
|
||||
const char *initial_branch, int quiet)
|
||||
{
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
@ -2243,7 +2243,7 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash
|
||||
}
|
||||
|
||||
static void validate_ref_storage_format(struct repository_format *repo_fmt,
|
||||
unsigned int format)
|
||||
enum ref_storage_format format)
|
||||
{
|
||||
const char *name = getenv("GIT_DEFAULT_REF_FORMAT");
|
||||
|
||||
@ -2263,7 +2263,7 @@ static void validate_ref_storage_format(struct repository_format *repo_fmt,
|
||||
|
||||
int init_db(const char *git_dir, const char *real_git_dir,
|
||||
const char *template_dir, int hash,
|
||||
unsigned int ref_storage_format,
|
||||
enum ref_storage_format ref_storage_format,
|
||||
const char *initial_branch,
|
||||
int init_shared_repository, unsigned int flags)
|
||||
{
|
||||
|
9
setup.h
9
setup.h
@ -1,6 +1,7 @@
|
||||
#ifndef SETUP_H
|
||||
#define SETUP_H
|
||||
|
||||
#include "refs.h"
|
||||
#include "string-list.h"
|
||||
|
||||
int is_inside_git_dir(void);
|
||||
@ -128,7 +129,7 @@ struct repository_format {
|
||||
int is_bare;
|
||||
int hash_algo;
|
||||
int compat_hash_algo;
|
||||
unsigned int ref_storage_format;
|
||||
enum ref_storage_format ref_storage_format;
|
||||
int sparse_index;
|
||||
char *work_tree;
|
||||
struct string_list unknown_extensions;
|
||||
@ -192,13 +193,13 @@ const char *get_template_dir(const char *option_template);
|
||||
|
||||
int init_db(const char *git_dir, const char *real_git_dir,
|
||||
const char *template_dir, int hash_algo,
|
||||
unsigned int ref_storage_format,
|
||||
enum ref_storage_format ref_storage_format,
|
||||
const char *initial_branch, int init_shared_repository,
|
||||
unsigned int flags);
|
||||
void initialize_repository_version(int hash_algo,
|
||||
unsigned int ref_storage_format,
|
||||
enum ref_storage_format ref_storage_format,
|
||||
int reinit);
|
||||
void create_reference_database(unsigned int ref_storage_format,
|
||||
void create_reference_database(enum ref_storage_format ref_storage_format,
|
||||
const char *initial_branch, int quiet);
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user