[PATCH/RFC 4/7] fetch-pack: add sparse prefix to smart protocol

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For example

    git fetch-pack --sparse-prefix=/contrib/ origin HEAD

Should fetch a pack that is generated on the remote by

    echo HEAD | git pack-objects --revs --stdout --sparse-prefix=/contrib/

Signed-off-by: Robin Ruede <r.ruede@xxxxxxxxx>
---
 builtin/fetch-pack.c |  6 ++++++
 fetch-pack.c         |  4 ++++
 fetch-pack.h         |  1 +
 remote-curl.c        |  2 ++
 upload-pack.c        | 15 ++++++++++++++-
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index bfd0be4..7f10001 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -64,6 +64,12 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
 			args.uploadpack = arg + 14;
 			continue;
 		}
+		if (starts_with(arg, "--sparse-prefix=")) {
+			args.sparse_prefix = arg + 16;
+			if(args.sparse_prefix[0] != '/')
+				die(N_("sparse prefix must start with /"));
+			continue;
+		}
 		if (starts_with(arg, "--exec=")) {
 			args.uploadpack = arg + 7;
 			continue;
diff --git a/fetch-pack.c b/fetch-pack.c
index b501d5c..8571b02 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -326,6 +326,8 @@ static int find_common(struct fetch_pack_args *args,
 		return 1;
 	}
 
+	if(args->sparse_prefix)
+		packet_buf_write(&req_buf, "sparse-prefix %s", args->sparse_prefix);
 	if (is_repository_shallow())
 		write_shallow_commits(&req_buf, 1, NULL);
 	if (args->depth > 0)
@@ -811,6 +813,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 
 	if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
 		die("Server does not support shallow clients");
+	if (args->sparse_prefix && !server_supports("sparse-prefix"))
+		die("Server does not support sparse prefix");
 	if (server_supports("multi_ack_detailed")) {
 		if (args->verbose)
 			fprintf(stderr, "Server supports multi_ack_detailed\n");
diff --git a/fetch-pack.h b/fetch-pack.h
index bb7fd76..8f36ef4 100644
--- a/fetch-pack.h
+++ b/fetch-pack.h
@@ -8,6 +8,7 @@ struct sha1_array;
 
 struct fetch_pack_args {
 	const char *uploadpack;
+	const char *sparse_prefix;
 	int unpacklimit;
 	int depth;
 	unsigned quiet:1;
diff --git a/remote-curl.c b/remote-curl.c
index 6b83b77..e181e62 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -727,6 +727,8 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
 	ALLOC_ARRAY(targets, nr_heads);
 	if (options.depth)
 		die("dumb http transport does not support --depth");
+	if (options.sparse_prefix)
+		die("dumb http transport does not support --sparse-prefix");
 	for (i = 0; i < nr_heads; i++)
 		targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
 
diff --git a/upload-pack.c b/upload-pack.c
index d4cc414..56d8c1a 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -57,6 +57,7 @@ static int use_sideband;
 static int advertise_refs;
 static int stateless_rpc;
 static const char *pack_objects_hook;
+static char *sparse_prefix;
 
 static void reset_timeout(void)
 {
@@ -125,6 +126,12 @@ static void create_pack_file(void)
 		argv_array_push(&pack_objects.args, "--delta-base-offset");
 	if (use_include_tag)
 		argv_array_push(&pack_objects.args, "--include-tag");
+	if (sparse_prefix) {
+		argv_array_push(&pack_objects.args, "--sparse-prefix");
+		argv_array_push(&pack_objects.args, sparse_prefix);
+		free(sparse_prefix);
+		sparse_prefix = NULL;
+	}
 
 	pack_objects.in = -1;
 	pack_objects.out = -1;
@@ -582,6 +589,12 @@ static void receive_needs(void)
 				die("Invalid deepen: %s", line);
 			continue;
 		}
+		if (starts_with(line, "sparse-prefix ")) {
+			if(sparse_prefix)
+				die("Only single sparse-prefix is allowed");
+			sparse_prefix = xstrdup(line + 14);
+			continue;
+		}
 		if (!starts_with(line, "want ") ||
 		    get_sha1_hex(line+5, sha1_buf))
 			die("git upload-pack: protocol error, "
@@ -730,7 +743,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 {
 	static const char *capabilities = "multi_ack thin-pack side-band"
 		" side-band-64k ofs-delta shallow no-progress"
-		" include-tag multi_ack_detailed";
+		" include-tag multi_ack_detailed sparse-prefix";
 	const char *refname_nons = strip_namespace(refname);
 	struct object_id peeled;
 
-- 
2.9.1.283.g3ca5b4c.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]