summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2016-02-24 17:58:59 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-25 16:01:04 -0800
commit66d9fb67f5b68c9300779e8ec08c8ecc85b862ad (patch)
tree0c2f5be2b99d459db65753463db61a5447bcd1e3
parent3e83052914883f055226c5ed604135fb4cc70c9d (diff)
downloadgit-66d9fb67f5b68c9300779e8ec08c8ecc85b862ad.tar.gz
refs: register ref storage backends
Add new function register_ref_storage_backends(). This new function registers all known ref storage backends... once there are any other than the default. For now, it just registers the files backend. Call the function before calling set_ref_storage_backend. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/init-db.c3
-rw-r--r--refs.c22
-rw-r--r--refs.h2
3 files changed, 23 insertions, 4 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 753cb1c7ee..ddb4c6c702 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -220,6 +220,7 @@ static int create_default_files(const char *template_path)
requested_ref_storage_backend);
}
+ register_ref_storage_backends();
if (requested_ref_storage_backend)
ref_storage_backend = requested_ref_storage_backend;
if (strcmp(ref_storage_backend, "files")) {
@@ -502,6 +503,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/refs.c b/refs.c
index 24be63c4e6..0e681c9670 100644
--- a/refs.c
+++ b/refs.c
@@ -14,14 +14,11 @@ static const char split_transaction_fail_warning[] = N_(
"transaction succeeded, but then the update to the per-worktree refs "
"failed. Your repository may be in an inconsistent state.");
-/*
- * We always have a files backend and it is the default.
- */
static struct ref_storage_be *the_refs_backend = &refs_be_files;
/*
* List of all available backends
*/
-static struct ref_storage_be *refs_backends = &refs_be_files;
+static struct ref_storage_be *refs_backends;
const char *ref_storage_backend = "files";
@@ -49,6 +46,23 @@ int ref_storage_backend_exists(const char *name)
return 0;
}
+void register_ref_storage_backend(struct ref_storage_be *be)
+{
+ be->next = refs_backends;
+ refs_backends = be;
+}
+
+void register_ref_storage_backends(void)
+{
+ if (refs_backends)
+ return;
+ /*
+ * Add register_ref_storage_backend(ptr-to-backend)
+ * entries below when you add a new backend.
+ */
+ register_ref_storage_backend(&refs_be_files);
+}
+
/*
* How to handle various characters in refnames:
* 0: An acceptable character for refs
diff --git a/refs.h b/refs.h
index 456e7296dc..9cc3a37e33 100644
--- a/refs.h
+++ b/refs.h
@@ -522,4 +522,6 @@ int set_ref_storage_backend(const char *name);
int ref_storage_backend_exists(const char *name);
+void register_ref_storage_backends(void);
+
#endif /* REFS_H */