[PATCH v4 19/21] refs: add register_ref_storage_backends()
From: David Turner <hidden>
Date: 2016-06-15 23:08:07
Subsystem:
the rest · Maintainer:
Linus Torvalds
This new function will register all known ref storage backends... once there are any other than the default. For now, it's a no-op. Signed-off-by: David Turner <redacted> --- builtin/init-db.c | 3 +++ config.c | 25 +++++++++++++++++++++++++ refs.c | 8 ++++++++ refs.h | 2 ++ 4 files changed, 38 insertions(+)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index d331ce8..4209b67 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c@@ -226,6 +226,7 @@ static int create_default_files(const char *template_path) if (strcmp(ref_storage_backend, "files")) { git_config_set("extensions.refStorage", ref_storage_backend); git_config_set("core.repositoryformatversion", ref_storage_backend); + register_ref_storage_backends(); if (set_ref_storage_backend(ref_storage_backend)) die(_("Unknown ref storage backend %s"), ref_storage_backend);
@@ -503,6 +504,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0); + register_ref_storage_backends(); + if (requested_ref_storage_backend && !ref_storage_backend_exists(requested_ref_storage_backend)) die(_("Unknown ref storage backend %s"),
diff --git a/config.c b/config.c
index b95ac3a..b9ef223 100644
--- a/config.c
+++ b/config.c@@ -11,6 +11,7 @@ #include "strbuf.h" #include "quote.h" #include "hashmap.h" +#include "refs.h" #include "string-list.h" #include "utf8.h"
@@ -1207,6 +1208,30 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) } if (repo_config && !access_or_die(repo_config, R_OK, 0)) { + char *storage = NULL; + + /* + * make sure we always read the ref storage config + * from the extensions section on startup + */ + ret += git_config_from_file(ref_storage_backend_config, + repo_config, &storage); + + register_ref_storage_backends(); + if (!storage) + storage = xstrdup(""); + + if ((!*storage) || + (!strcmp(storage, "files"))) { + /* default backend, nothing to do */ + free(storage); + } else { + ref_storage_backend = storage; + if (set_ref_storage_backend(ref_storage_backend)) + die(_("Unknown ref storage backend %s"), + ref_storage_backend); + } + ret += git_config_from_file(fn, repo_config, data); found += 1; }
diff --git a/refs.c b/refs.c
index 715a492..e50cca0 100644
--- a/refs.c
+++ b/refs.c@@ -1554,3 +1554,11 @@ done: string_list_clear(&affected_refnames, 0); return ret; } + +void register_ref_storage_backends(void) { + /* + * No need to register the files backend; it's registered by + * default. Add register_ref_storage_backend(ptr-to-backend) + * entries below when you add a new backend. + */ +}
diff --git a/refs.h b/refs.h
index 680a535..81aab6b 100644
--- a/refs.h
+++ b/refs.h@@ -525,4 +525,6 @@ int ref_storage_backend_exists(const char *name); void register_ref_storage_backend(struct ref_storage_be *be); +void register_ref_storage_backends(void); + #endif /* REFS_H */
--
2.4.2.749.g730654d-twtrsrc