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

[PATCH/RFC 5/7] fetch: add sparse-prefix option

From
RRRobin Ruede <r.ruede@gmail.com>
Date
Jul 28, 2016, 16:02 UTC
Message-ID
<20160728160226.24018-6-r.ruede@gmail.com>
In-Reply-To
<20160728160226.24018-1-r.ruede@gmail.com>

also pass sparse-prefix option from fetch to rev-list while checking connectivity

Signed-off-by: Robin Ruede <r.ruede@gmail.com>
---
 builtin/fetch.c | 19 ++++++++++++++-----
 connected.c     |  7 ++++++-
 transport.c     |  4 ++++
 transport.h     |  4 ++++
 4 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index acd0cf1..b48537f 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -41,6 +41,7 @@ static int tags = TAGS_DEFAULT, unshallow, update_shallow;
 static int max_children = -1;
 static enum transport_family family;
 static const char *depth;
+static const char *sparse_prefix;
 static const char *upload_pack;
 static struct strbuf default_rla = STRBUF_INIT;
 static struct transport *gtransport;
@@ -117,6 +118,8 @@ static struct option builtin_fetch_options[] = {
 	OPT_BOOL(0, "progress", &progress, N_("force progress reporting")),
 	OPT_STRING(0, "depth", &depth, N_("depth"),
 		   N_("deepen history of shallow clone")),
+	OPT_STRING(0, "sparse-prefix", &sparse_prefix, N_("path-prefix"),
+		   N_("only fetch blobs for the specified path-prefix")),
 	{ OPTION_SET_INT, 0, "unshallow", &unshallow, NULL,
 		   N_("convert to a complete repository"),
 		   PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1 },
@@ -706,9 +709,11 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
 	return 0;
 }
 
-static int store_updated_refs(const char *raw_url, const char *remote_name,
+static int store_updated_refs(struct transport *transport,
 		struct ref *ref_map)
 {
+	const char *raw_url = transport->url;
+	const char *remote_name = transport->remote->name;
 	FILE *fp;
 	struct commit *commit;
 	int url_len, i, rc = 0;
@@ -729,7 +734,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 		url = xstrdup("foreign");
 
 	rm = ref_map;
-	if (check_everything_connected(iterate_ref_map, 0, &rm)) {
+	if (check_everything_connected_with_transport(iterate_ref_map, 0, &rm,
+				transport)) {
 		rc = error(_("%s did not send all necessary objects\n"), url);
 		goto abort;
 	}
@@ -885,9 +891,7 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
 	if (ret)
 		ret = transport_fetch_refs(transport, ref_map);
 	if (!ret)
-		ret |= store_updated_refs(transport->url,
-				transport->remote->name,
-				ref_map);
+		ret |= store_updated_refs(transport, ref_map);
 	transport_unlock_pack(transport);
 	return ret;
 }
@@ -993,6 +997,11 @@ static struct transport *prepare_transport(struct remote *remote)
 		set_option(transport, TRANS_OPT_KEEP, "yes");
 	if (depth)
 		set_option(transport, TRANS_OPT_DEPTH, depth);
+	if (sparse_prefix) {
+		if(sparse_prefix[0] != '/')
+			die(N_("sparse prefix must start with /"));
+		set_option(transport, TRANS_OPT_SPARSE_PREFIX, sparse_prefix);
+	}
 	if (update_shallow)
 		set_option(transport, TRANS_OPT_UPDATE_SHALLOW, "yes");
 	return transport;
diff --git a/connected.c b/connected.c
index bf1b12e..1534c5c 100644
--- a/connected.c
+++ b/connected.c
@@ -26,7 +26,7 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
 					   const char *shallow_file)
 {
 	struct child_process rev_list = CHILD_PROCESS_INIT;
-	const char *argv[9];
+	const char *argv[11];
 	char commit[41];
 	unsigned char sha1[20];
 	int err = 0, ac = 0;
@@ -56,6 +56,11 @@ static int check_everything_connected_real(sha1_iterate_fn fn,
 	argv[ac++] = "--stdin";
 	argv[ac++] = "--not";
 	argv[ac++] = "--all";
+	if(transport && transport->smart_options && 
+			transport->smart_options->sparse_prefix) {
+		argv[ac++] = "--sparse-prefix";
+		argv[ac++] = transport->smart_options->sparse_prefix;
+	}
 	if (quiet)
 		argv[ac++] = "--quiet";
 	argv[ac] = NULL;
diff --git a/transport.c b/transport.c
index b233e3e..ce7e2e1 100644
--- a/transport.c
+++ b/transport.c
@@ -141,6 +141,9 @@ static int set_git_option(struct git_transport_options *opts,
 	} else if (!strcmp(name, TRANS_OPT_UPDATE_SHALLOW)) {
 		opts->update_shallow = !!value;
 		return 0;
+	} else if (!strcmp(name, TRANS_OPT_SPARSE_PREFIX)) {
+		opts->sparse_prefix = value;
+		return 0;
 	} else if (!strcmp(name, TRANS_OPT_DEPTH)) {
 		if (!value)
 			opts->depth = 0;
@@ -211,6 +214,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	args.quiet = (transport->verbose < 0);
 	args.no_progress = !transport->progress;
 	args.depth = data->options.depth;
+	args.sparse_prefix = data->options.sparse_prefix;
 	args.check_self_contained_and_connected =
 		data->options.check_self_contained_and_connected;
 	args.cloning = transport->cloning;
diff --git a/transport.h b/transport.h
index c681408..abee186 100644
--- a/transport.h
+++ b/transport.h
@@ -15,6 +15,7 @@ struct git_transport_options {
 	int depth;
 	const char *uploadpack;
 	const char *receivepack;
+	const char *sparse_prefix;
 	struct push_cas_option *cas;
 };
 
@@ -179,6 +180,9 @@ int transport_restrict_protocols(void);
 /* Limit the depth of the fetch if not null */
 #define TRANS_OPT_DEPTH "depth"
 
+/* Only fetch blobs whose referenced path begins with this if not null */
+#define TRANS_OPT_SPARSE_PREFIX "sparse-prefix"
+
 /* Aggressively fetch annotated tags if possible */
 #define TRANS_OPT_FOLLOWTAGS "followtags"
 
-- 
2.9.1.283.g3ca5b4c.dirty
Previous: Robin RuedeNext: Robin Ruede
Message 5 of 12 in “Add possibility to clone specific subdirectories”
  1. 0/7 Add possibility to clone specific subdirectoriesRobin Ruede, Jul 28, 2016
  2. 1/7 list-objects: add sparse-prefix option to rev_infoRobin Ruede, Jul 28, 2016
  3. 2/7 pack-objects: add sparse-prefixRobin Ruede, Jul 28, 2016
  4. 3/7 Skip checking integrity of files ignored by sparseRobin Ruede, Jul 28, 2016
  5. 5/7 fetch: add sparse-prefix optionRobin Ruede, Jul 28, 2016
  6. 6/7 clone: add sparse-prefix optionRobin Ruede, Jul 28, 2016
  7. 4/7 fetch-pack: add sparse prefix to smart protocolRobin Ruede, Jul 28, 2016
  8. 7/7 remote-curl: add sparse prefixRobin Ruede, Jul 28, 2016
  9. Duy NguyenJul 28, 2016
  10. Duy NguyenJul 28, 2016
  11. Junio C HamanoJul 28, 2016
  12. Duy NguyenJul 29, 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.