git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wern <kevin.m.wern@gmail.com>
To: git@vger.kernel.org
Cc: Kevin Wern <kevin.m.wern@gmail.com>
Subject: [PATCH 1/2] Resumable clone: create git-prime-clone (Draft)
Date: Wed, 18 May 2016 22:07:29 -0700	[thread overview]
Message-ID: <1463634450-28265-2-git-send-email-kevin.m.wern@gmail.com> (raw)
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

  reply	other threads:[~2016-05-19  5:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-19  5:07 [PATCH 0/2] git-prime-clone Kevin Wern
2016-05-19  5:07 ` Kevin Wern [this message]
2016-05-19  5:07 ` [PATCH 2/2] Resumable clone: add endpoints for prime clone (Draft) Kevin Wern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463634450-28265-2-git-send-email-kevin.m.wern@gmail.com \
    --to=kevin.m.wern@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).