promisor-remote: parse remote.*.partialclonefilter
This makes it possible to specify a different partial clone filter for each promisor remote. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									b14ed5adaf
								
							
						
					
					
						commit
						fa3d1b63e8
					
				|  | @ -1491,7 +1491,7 @@ static inline void fetch_one_setup_partial(struct remote *remote) | ||||||
| 	 * the config. | 	 * the config. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (!filter_options.choice) | 	if (!filter_options.choice) | ||||||
| 		partial_clone_get_default_filter_spec(&filter_options); | 		partial_clone_get_default_filter_spec(&filter_options, remote->name); | ||||||
| 	return; | 	return; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -30,6 +30,9 @@ static int gently_parse_list_objects_filter( | ||||||
| { | { | ||||||
| 	const char *v0; | 	const char *v0; | ||||||
|  |  | ||||||
|  | 	if (!arg) | ||||||
|  | 		return 0; | ||||||
|  |  | ||||||
| 	if (filter_options->choice) { | 	if (filter_options->choice) { | ||||||
| 		if (errbuf) { | 		if (errbuf) { | ||||||
| 			strbuf_addstr( | 			strbuf_addstr( | ||||||
|  | @ -148,6 +151,7 @@ void partial_clone_register( | ||||||
| 	const struct list_objects_filter_options *filter_options) | 	const struct list_objects_filter_options *filter_options) | ||||||
| { | { | ||||||
| 	char *cfg_name; | 	char *cfg_name; | ||||||
|  | 	char *filter_name; | ||||||
|  |  | ||||||
| 	/* Check if it is already registered */ | 	/* Check if it is already registered */ | ||||||
| 	if (!promisor_remote_find(remote)) { | 	if (!promisor_remote_find(remote)) { | ||||||
|  | @ -162,27 +166,26 @@ void partial_clone_register( | ||||||
| 	/* | 	/* | ||||||
| 	 * Record the initial filter-spec in the config as | 	 * Record the initial filter-spec in the config as | ||||||
| 	 * the default for subsequent fetches from this remote. | 	 * the default for subsequent fetches from this remote. | ||||||
| 	 * |  | ||||||
| 	 * TODO: record it into remote.<name>.partialclonefilter |  | ||||||
| 	 */ | 	 */ | ||||||
| 	core_partial_clone_filter_default = | 	filter_name = xstrfmt("remote.%s.partialclonefilter", remote); | ||||||
| 		xstrdup(filter_options->filter_spec); | 	git_config_set(filter_name, filter_options->filter_spec); | ||||||
| 	git_config_set("core.partialclonefilter", | 	free(filter_name); | ||||||
| 		       core_partial_clone_filter_default); |  | ||||||
|  |  | ||||||
| 	/* Make sure the config info are reset */ | 	/* Make sure the config info are reset */ | ||||||
| 	promisor_remote_reinit(); | 	promisor_remote_reinit(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void partial_clone_get_default_filter_spec( | void partial_clone_get_default_filter_spec( | ||||||
| 	struct list_objects_filter_options *filter_options) | 	struct list_objects_filter_options *filter_options, | ||||||
|  | 	const char *remote) | ||||||
| { | { | ||||||
|  | 	struct promisor_remote *promisor = promisor_remote_find(remote); | ||||||
|  |  | ||||||
| 	/* | 	/* | ||||||
| 	 * Parse default value, but silently ignore it if it is invalid. | 	 * Parse default value, but silently ignore it if it is invalid. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (!core_partial_clone_filter_default) | 	if (promisor) | ||||||
| 		return; | 		gently_parse_list_objects_filter(filter_options, | ||||||
| 	gently_parse_list_objects_filter(filter_options, | 						 promisor->partial_clone_filter, | ||||||
| 					 core_partial_clone_filter_default, | 						 NULL); | ||||||
| 					 NULL); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -87,6 +87,7 @@ void partial_clone_register( | ||||||
| 	const char *remote, | 	const char *remote, | ||||||
| 	const struct list_objects_filter_options *filter_options); | 	const struct list_objects_filter_options *filter_options); | ||||||
| void partial_clone_get_default_filter_spec( | void partial_clone_get_default_filter_spec( | ||||||
| 	struct list_objects_filter_options *filter_options); | 	struct list_objects_filter_options *filter_options, | ||||||
|  | 	const char *remote); | ||||||
|  |  | ||||||
| #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ | #endif /* LIST_OBJECTS_FILTER_OPTIONS_H */ | ||||||
|  |  | ||||||
|  | @ -75,6 +75,21 @@ static int promisor_remote_config(const char *var, const char *value, void *data | ||||||
| 		free(remote_name); | 		free(remote_name); | ||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  | 	if (!strcmp(subkey, "partialclonefilter")) { | ||||||
|  | 		struct promisor_remote *r; | ||||||
|  | 		char *remote_name = xmemdupz(name, namelen); | ||||||
|  |  | ||||||
|  | 		r = promisor_remote_lookup(remote_name, NULL); | ||||||
|  | 		if (!r) | ||||||
|  | 			r = promisor_remote_new(remote_name); | ||||||
|  |  | ||||||
|  | 		free(remote_name); | ||||||
|  |  | ||||||
|  | 		if (!r) | ||||||
|  | 			return 0; | ||||||
|  |  | ||||||
|  | 		return git_config_string(&r->partial_clone_filter, var, value); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -5,10 +5,13 @@ struct object_id; | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Promisor remote linked list |  * Promisor remote linked list | ||||||
|  * Its information come from remote.XXX config entries. |  * | ||||||
|  |  * Information in its fields come from remote.XXX config entries or | ||||||
|  |  * from extensions.partialclone or core.partialclonefilter. | ||||||
|  */ |  */ | ||||||
| struct promisor_remote { | struct promisor_remote { | ||||||
| 	struct promisor_remote *next; | 	struct promisor_remote *next; | ||||||
|  | 	const char *partial_clone_filter; | ||||||
| 	const char name[FLEX_ARRAY]; | 	const char name[FLEX_ARRAY]; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ promise_and_delete () { | ||||||
| test_expect_success 'extensions.partialclone without filter' ' | test_expect_success 'extensions.partialclone without filter' ' | ||||||
| 	test_create_repo server && | 	test_create_repo server && | ||||||
| 	git clone --filter="blob:none" "file://$(pwd)/server" client && | 	git clone --filter="blob:none" "file://$(pwd)/server" client && | ||||||
| 	git -C client config --unset core.partialclonefilter && | 	git -C client config --unset remote.origin.partialclonefilter && | ||||||
| 	git -C client fetch origin | 	git -C client fetch origin | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -655,6 +655,7 @@ partial_clone () { | ||||||
|  |  | ||||||
| 	# Ensure that unneeded blobs are not inadvertently fetched. | 	# Ensure that unneeded blobs are not inadvertently fetched. | ||||||
| 	test_config -C client remote.origin.promisor "false" && | 	test_config -C client remote.origin.promisor "false" && | ||||||
|  | 	git -C client config --unset remote.origin.partialclonefilter && | ||||||
| 	test_must_fail git -C client cat-file -e "$HASH1" && | 	test_must_fail git -C client cat-file -e "$HASH1" && | ||||||
|  |  | ||||||
| 	# But this blob was fetched, because clone performs an initial checkout | 	# But this blob was fetched, because clone performs an initial checkout | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ test_expect_success 'do partial clone 1' ' | ||||||
| 	test_cmp expect_1.oids observed.oids && | 	test_cmp expect_1.oids observed.oids && | ||||||
| 	test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" && | 	test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" && | ||||||
| 	test "$(git -C pc1 config --local remote.origin.promisor)" = "true" && | 	test "$(git -C pc1 config --local remote.origin.promisor)" = "true" && | ||||||
| 	test "$(git -C pc1 config --local core.partialclonefilter)" = "blob:none" | 	test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none" | ||||||
| ' | ' | ||||||
|  |  | ||||||
| # checkout master to force dynamic object fetch of blobs at HEAD. | # checkout master to force dynamic object fetch of blobs at HEAD. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Christian Couder
						Christian Couder