git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 04/13] Add initial support for many promisor remotes

From
Christian Couder <christian.couder@gmail.com>
Date
Jan 22, 2019, 14:42 UTC
Message-ID
<20190122144212.15119-5-chriscool@tuxfamily.org>
In-Reply-To
<20190122144212.15119-1-chriscool@tuxfamily.org>
From: Christian Couder <christian.couder@gmail.com>

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>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 Makefile          |   1 +
 promisor-remote.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++
 promisor-remote.h |  17 ++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 promisor-remote.c
 create mode 100644 promisor-remote.h
diff --git a/Makefile b/Makefile
index 1a44c811aa..565a5fbb4e 100644
--- a/Makefile
+++ b/Makefile
@@ -949,6 +949,7 @@ LIB_OBJS += preload-index.o
 LIB_OBJS += pretty.o
 LIB_OBJS += prio-queue.o
 LIB_OBJS += progress.o
+LIB_OBJS += promisor-remote.o
 LIB_OBJS += prompt.o
 LIB_OBJS += protocol.o
 LIB_OBJS += quote.o
diff --git a/promisor-remote.c b/promisor-remote.c
new file mode 100644
index 0000000000..d2f574651e
--- /dev/null
+++ b/promisor-remote.c
@@ -0,0 +1,100 @@
+#include "cache.h"
+#include "promisor-remote.h"
+#include "config.h"
+
+static struct promisor_remote *promisors;
+static struct promisor_remote **promisors_tail = &promisors;
+
+struct promisor_remote *promisor_remote_new(const char *remote_name)
+{
+	struct promisor_remote *o;
+
+	o = xcalloc(1, sizeof(*o));
+	o->remote_name = xstrdup(remote_name);
+
+	*promisors_tail = o;
+	promisors_tail = &o->next;
+
+	return o;
+}
+
+static struct promisor_remote *promisor_remote_look_up(const char *remote_name,
+						       struct promisor_remote **previous)
+{
+	struct promisor_remote *o, *p;
+
+	for (p = NULL, o = promisors; o; p = o, o = o->next)
+		if (o->remote_name && !strcmp(o->remote_name, remote_name)) {
+			if (previous)
+				*previous = p;
+			return o;
+		}
+
+	return NULL;
+}
+
+static void promisor_remote_move_to_tail(struct promisor_remote *o,
+					 struct promisor_remote *previous)
+{
+	if (previous)
+		previous->next = o->next;
+	else
+		promisors = o->next ? o->next : o;
+	o->next = NULL;
+	*promisors_tail = o;
+	promisors_tail = &o->next;
+}
+
+static int promisor_remote_config(const char *var, const char *value, void *data)
+{
+	struct promisor_remote *o;
+	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_look_up(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_look_up(remote_name, NULL);
+}
+
+int has_promisor_remote(void)
+{
+	return !!promisor_remote_find(NULL);
+}
diff --git a/promisor-remote.h b/promisor-remote.h
new file mode 100644
index 0000000000..bfbf7c0f21
--- /dev/null
+++ b/promisor-remote.h
@@ -0,0 +1,17 @@
+#ifndef PROMISOR_REMOTE_H
+#define PROMISOR_REMOTE_H
+
+/*
+ * Promisor remote linked list
+ * Its information come from remote.XXX config entries.
+ */
+struct promisor_remote {
+	const char *remote_name;
+	struct promisor_remote *next;
+};
+
+extern struct promisor_remote *promisor_remote_new(const char *remote_name);
+extern struct promisor_remote *promisor_remote_find(const char *remote_name);
+extern int has_promisor_remote(void);
+
+#endif /* PROMISOR_REMOTE_H */
-- 
2.20.1.322.gd6b9ae60d4
Previous: Christian CouderNext: Christian Couder
Message 8 of 14 in “Many promisor remotes”
  1. 00/13 Many promisor remotesChristian Couder, Jan 22, 2019
  2. 01/13 fetch: fix extensions.partialclone name in error messageChristian Couder, Jan 22, 2019
  3. 02/13 partial-clone: add missing 'is' in docChristian Couder, Jan 22, 2019
  4. 03/13 fetch-object: make functions return an error codeChristian Couder, Jan 22, 2019
  5. 06/13 promisor-remote: add promisor_remote_reinit()Christian Couder, Jan 22, 2019
  6. 07/13 promisor-remote: use repository_format_partial_cloneChristian Couder, Jan 22, 2019
  7. 05/13 promisor-remote: implement promisors_get_direct()Christian Couder, Jan 22, 2019
  8. 04/13 Add initial support for many promisor remotesChristian Couder, Jan 22, 2019
  9. 11/13 t0410: test fetching from many promisor remotesChristian Couder, Jan 22, 2019
  10. 13/13 remote: add promisor and partial clone config to the docChristian Couder, Jan 22, 2019
  11. 09/13 promisor-remote: parse remote.*.partialclonefilterChristian Couder, Jan 22, 2019
  12. 10/13 builtin/fetch: remove unique promisor remote limitationChristian Couder, Jan 22, 2019
  13. 08/13 Use promisor_remote_get_direct() and has_promisor_remote()Christian Couder, Jan 22, 2019
  14. 12/13 partial-clone: add multiple remotes in the docChristian Couder, Jan 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.