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

[PATCH 1/2] Resumable clone: create git-prime-clone (Draft)

From
KWKevin Wern <kevin.m.wern@gmail.com>
Date
May 19, 2016, 05:07 UTC
Message-ID
<1463634450-28265-2-git-send-email-kevin.m.wern@gmail.com>
In-Reply-To
<1463634450-28265-1-git-send-email-kevin.m.wern@gmail.com>

Create a bare-bones version of git-prime-clone, which returns the location of an alternate resource specified by the server that the client should fetch and build before returning to perform an incremental fetch.

At this point, no validation is performed of the file's existence, the
file's validity as a fully connected archive, or its correspondence
to the specified resource type in .git/config.
---
 Makefile      |  1 +
 prime-clone.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)
 create mode 100644 prime-clone.c
diff --git a/Makefile b/Makefile
index 3f03366..34febdc 100644
--- a/Makefile
+++ b/Makefile
@@ -579,6 +579,7 @@ PROGRAM_OBJS += sh-i18n--envsubst.o
 PROGRAM_OBJS += shell.o
 PROGRAM_OBJS += show-index.o
 PROGRAM_OBJS += upload-pack.o
+PROGRAM_OBJS += prime-clone.o
 PROGRAM_OBJS += remote-testsvn.o
 
 # Binary suffix, set to .exe for Windows builds
diff --git a/prime-clone.c b/prime-clone.c
new file mode 100644
index 0000000..74fd8d4
--- /dev/null
+++ b/prime-clone.c
@@ -0,0 +1,87 @@
+#include "cache.h"
+#include "refs.h"
+
+#define PRIME_CLONE_ENABLED 1
+
+static const char prime_clone_usage[] = "git prime-clone [--strict] <dir>";
+
+static unsigned int enabled;
+static const char *url = "\0";
+static const char *filetype = "\0";
+
+static void prime_clone(void)
+{
+	if (enabled)
+	{
+		if (strlen(url) != 0 && strlen(filetype) != 0) {
+			packet_write(1, "url %s\n", url);
+			packet_write(1, "filetype %s\n", filetype);
+		}
+		else {
+			packet_write(1, "prime-clone not properly configured\n");
+		}
+	}
+	else {
+		packet_write(1, "prime-clone not enabled\n");
+	}
+	packet_flush(1);
+}
+
+static int prime_clone_config(const char *var, const char *value, void *unused)
+{
+	if (!strcmp("primeclone.url",var)) {
+		return git_config_pathname(&url, var, value);
+	}
+	if (!strcmp("primeclone.enabled",var)) {
+		if (git_config_bool(var, value))
+			enabled = PRIME_CLONE_ENABLED;
+		else
+			enabled = ~PRIME_CLONE_ENABLED;
+	}
+	if (!strcmp("primeclone.filetype",var)) {
+		return git_config_string(&filetype, var, value);
+	}
+	return parse_hide_refs_config(var, value, "primeclone");
+}
+
+int main(int argc, char **argv)
+{
+	char *dir;
+	int i;
+	int strict = 0;
+
+	git_setup_gettext();
+
+	packet_trace_identity("prime-clone");
+	git_extract_argv0_path(argv[0]);
+	check_replace_refs = 0;
+
+	for (i = 1; i < argc; i++) {
+		char *arg = argv[i];
+
+		if (arg[0] != '-')
+			break;
+		if (!strcmp(arg, "--strict")) {
+			strict = 1;
+			continue;
+		}
+		if (!strcmp(arg, "--")) {
+			i++;
+			break;
+		}
+	}
+
+	if (i != argc-1)
+		usage(prime_clone_usage);
+
+	setup_path();
+
+	dir = argv[i];
+
+	if (!enter_repo(dir, strict))
+		die("'%s' does not appear to be a git repository", dir);
+
+	git_config(prime_clone_config, NULL);
+	prime_clone();
+	return 0;
+}
-- 
1.9.1
Previous: Kevin WernNext: Kevin Wern
Message 2 of 3 in “git-prime-clone”
  1. 0/2 git-prime-cloneKevin Wern, May 19, 2016
  2. 1/2 Resumable clone: create git-prime-clone (Draft)Kevin Wern, May 19, 2016
  3. 2/2 Resumable clone: add endpoints for prime clone (Draft)Kevin Wern, May 19, 2016

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.