summaryrefslogtreecommitdiff
path: root/promisor-remote.c
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2019-06-25 13:40:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-25 21:05:37 (GMT)
commit48de315817281e49a5e9000d40550b5257b437c6 (patch)
treef699fb7857982856bf049c687bc06f40b12fb5bc /promisor-remote.c
parent2e860675b6572cf476e99888134a5b307fd7eb62 (diff)
downloadgit-48de315817281e49a5e9000d40550b5257b437c6.zip
git-48de315817281e49a5e9000d40550b5257b437c6.tar.gz
git-48de315817281e49a5e9000d40550b5257b437c6.tar.bz2
Add initial support for many promisor remotes
The promisor-remote.{c,h} files will contain functions to manage many promisor remotes. We expect that there will not be a lot of promisor remotes, so it is ok to use a simple linked list to manage them. Helped-by: Jeff King <peff@peff.net> Helped-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'promisor-remote.c')
-rw-r--r--promisor-remote.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/promisor-remote.c b/promisor-remote.c
new file mode 100644
index 0000000..c249b80
--- /dev/null
+++ b/promisor-remote.c
@@ -0,0 +1,92 @@
+#include "cache.h"
+#include "promisor-remote.h"
+#include "config.h"
+
+static struct promisor_remote *promisors;
+static struct promisor_remote **promisors_tail = &promisors;
+
+static struct promisor_remote *promisor_remote_new(const char *remote_name)
+{
+ struct promisor_remote *r;
+
+ if (*remote_name == '/') {
+ warning(_("promisor remote name cannot begin with '/': %s"),
+ remote_name);
+ return NULL;
+ }
+
+ FLEX_ALLOC_STR(r, name, remote_name);
+
+ *promisors_tail = r;
+ promisors_tail = &r->next;
+
+ return r;
+}
+
+static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
+ struct promisor_remote **previous)
+{
+ struct promisor_remote *r, *p;
+
+ for (p = NULL, r = promisors; r; p = r, r = r->next)
+ if (!strcmp(r->name, remote_name)) {
+ if (previous)
+ *previous = p;
+ return r;
+ }
+
+ return NULL;
+}
+
+static int promisor_remote_config(const char *var, const char *value, void *data)
+{
+ const char *name;
+ int namelen;
+ const char *subkey;
+
+ if (parse_config_key(var, "remote", &name, &namelen, &subkey) < 0)
+ return 0;
+
+ if (!strcmp(subkey, "promisor")) {
+ char *remote_name;
+
+ if (!git_config_bool(var, value))
+ return 0;
+
+ remote_name = xmemdupz(name, namelen);
+
+ if (!promisor_remote_lookup(remote_name, NULL))
+ promisor_remote_new(remote_name);
+
+ free(remote_name);
+ return 0;
+ }
+
+ return 0;
+}
+
+static void promisor_remote_init(void)
+{
+ static int initialized;
+
+ if (initialized)
+ return;
+ initialized = 1;
+
+ git_config(promisor_remote_config, NULL);
+}
+
+struct promisor_remote *promisor_remote_find(const char *remote_name)
+{
+ promisor_remote_init();
+
+ if (!remote_name)
+ return promisors;
+
+ return promisor_remote_lookup(remote_name, NULL);
+}
+
+int has_promisor_remote(void)
+{
+ return !!promisor_remote_find(NULL);
+}