]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: convert ref storage format to an enum
authorPatrick Steinhardt <ps@pks.im>
Thu, 6 Jun 2024 05:29:01 +0000 (07:29 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Jun 2024 16:04:31 +0000 (09:04 -0700)
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>
builtin/clone.c
builtin/init-db.c
refs.c
refs.h
repository.c
repository.h
setup.c
setup.h

index 1e07524c53204a4e67b9ce83475b3bddbb5bf3fb..e808e02017872fa3b8c64d50eb8c096789eb5f49 100644 (file)
@@ -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;
index 0170469b849e5e5ad52cf8586f4540088b0edd61..582dcf20f862fb87a967bcdbb121199007a42b1c 100644 (file)
@@ -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"),
diff --git a/refs.c b/refs.c
index 31032588e0efe293df33cecdcb0ba9b89d90197f..e6db85a165941a948ff9430386dec3a90b5243de 100644 (file)
--- a/refs.c
+++ b/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)
diff --git a/refs.h b/refs.h
index fe7f0db35e66c0a7d3029885e2dab7267902b275..a7afa9bede3ab0428e9f39b8fb51e14dddfdd4b4 100644 (file)
--- a/refs.h
+++ b/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.
index d29b0304fbd32ecfb6d8f63060cc5e1577f3db0d..166863f852153aaa972641b8f6645c75c6b810de 100644 (file)
@@ -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;
 }
index 4bd896900554bb589c6ebf08534653ca18894329..a35cd77c356f0106a4ff0bc1b5c3329d393b2b00 100644 (file)
@@ -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);
diff --git a/setup.c b/setup.c
index 8c84ec9d4b157ccf6afdff9e402581dc6d057f89..b49ee3e95ff6daa4560ef047d122573b6b457973 100644 (file)
--- a/setup.c
+++ b/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)
 {
diff --git a/setup.h b/setup.h
index b3fd3bf45a8e173721aa62f157f0c105a60b3fbd..cd8dbc249762db3e12f21e8eaddbe52bf45573d0 100644 (file)
--- a/setup.h
+++ b/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);
 
 /*