diff mbox series

[v5,05/16] promisor-remote: add promisor_remote_reinit()

Message ID 20190409161116.30256-6-chriscool@tuxfamily.org (mailing list archive)
State New, archived
Headers show
Series Many promisor remotes | expand

Commit Message

Christian Couder April 9, 2019, 4:11 p.m. UTC
From: Christian Couder <christian.couder@gmail.com>

We will need to reinitialize the promisor remote configuration
as we will make some changes to it in a later commit.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 promisor-remote.c | 22 ++++++++++++++++++++--
 promisor-remote.h |  1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/promisor-remote.c b/promisor-remote.c
index 289f1dd074..46271eb3e3 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -67,10 +67,10 @@  static int promisor_remote_config(const char *var, const char *value, void *data
 	return 0;
 }
 
+static int initialized;
+
 static void promisor_remote_init(void)
 {
-	static int initialized;
-
 	if (initialized)
 		return;
 	initialized = 1;
@@ -78,6 +78,24 @@  static void promisor_remote_init(void)
 	git_config(promisor_remote_config, NULL);
 }
 
+static void promisor_remote_clear(void)
+{
+	while (promisors) {
+		struct promisor_remote *r = promisors;
+		promisors = promisors->next;
+		free(r);
+	}
+
+	promisors_tail = &promisors;
+}
+
+void promisor_remote_reinit(void)
+{
+	initialized = 0;
+	promisor_remote_clear();
+	promisor_remote_init();
+}
+
 struct promisor_remote *promisor_remote_find(const char *remote_name)
 {
 	promisor_remote_init();
diff --git a/promisor-remote.h b/promisor-remote.h
index 92650cfd4c..ff69963907 100644
--- a/promisor-remote.h
+++ b/promisor-remote.h
@@ -12,6 +12,7 @@  struct promisor_remote {
 	const char name[FLEX_ARRAY];
 };
 
+extern void promisor_remote_reinit(void);
 extern struct promisor_remote *promisor_remote_find(const char *remote_name);
 extern int has_promisor_remote(void);
 extern int promisor_remote_get_direct(const struct object_id *oids, int oid_nr);