submodule-config: pass repo upon blob config read
When reading the config of a submodule, if reading from a blob, read using an explicitly specified repository instead of by adding the submodule's ODB as an alternate and then reading an object from the_repository. This makes the "grep --recurse-submodules with submodules without .gitmodules in the working tree" test in t7814 work when GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB is true. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									0693806bf8
								
							
						
					
					
						commit
						e3e8bf046e
					
				
							
								
								
									
										20
									
								
								config.c
								
								
								
								
							
							
						
						
									
										20
									
								
								config.c
								
								
								
								
							|  | @ -1796,6 +1796,7 @@ int git_config_from_mem(config_fn_t fn, | |||
|  | ||||
| int git_config_from_blob_oid(config_fn_t fn, | ||||
| 			      const char *name, | ||||
| 			      struct repository *repo, | ||||
| 			      const struct object_id *oid, | ||||
| 			      void *data) | ||||
| { | ||||
|  | @ -1804,7 +1805,7 @@ int git_config_from_blob_oid(config_fn_t fn, | |||
| 	unsigned long size; | ||||
| 	int ret; | ||||
|  | ||||
| 	buf = read_object_file(oid, &type, &size); | ||||
| 	buf = repo_read_object_file(repo, oid, &type, &size); | ||||
| 	if (!buf) | ||||
| 		return error(_("unable to load config blob object '%s'"), name); | ||||
| 	if (type != OBJ_BLOB) { | ||||
|  | @ -1820,14 +1821,15 @@ int git_config_from_blob_oid(config_fn_t fn, | |||
| } | ||||
|  | ||||
| static int git_config_from_blob_ref(config_fn_t fn, | ||||
| 				    struct repository *repo, | ||||
| 				    const char *name, | ||||
| 				    void *data) | ||||
| { | ||||
| 	struct object_id oid; | ||||
|  | ||||
| 	if (get_oid(name, &oid) < 0) | ||||
| 	if (repo_get_oid(repo, name, &oid) < 0) | ||||
| 		return error(_("unable to resolve config blob '%s'"), name); | ||||
| 	return git_config_from_blob_oid(fn, name, &oid, data); | ||||
| 	return git_config_from_blob_oid(fn, name, repo, &oid, data); | ||||
| } | ||||
|  | ||||
| char *git_system_config(void) | ||||
|  | @ -1958,12 +1960,16 @@ int config_with_options(config_fn_t fn, void *data, | |||
| 	 * If we have a specific filename, use it. Otherwise, follow the | ||||
| 	 * regular lookup sequence. | ||||
| 	 */ | ||||
| 	if (config_source && config_source->use_stdin) | ||||
| 	if (config_source && config_source->use_stdin) { | ||||
| 		return git_config_from_stdin(fn, data); | ||||
| 	else if (config_source && config_source->file) | ||||
| 	} else if (config_source && config_source->file) { | ||||
| 		return git_config_from_file(fn, config_source->file, data); | ||||
| 	else if (config_source && config_source->blob) | ||||
| 		return git_config_from_blob_ref(fn, config_source->blob, data); | ||||
| 	} else if (config_source && config_source->blob) { | ||||
| 		struct repository *repo = config_source->repo ? | ||||
| 			config_source->repo : the_repository; | ||||
| 		return git_config_from_blob_ref(fn, repo, config_source->blob, | ||||
| 						data); | ||||
| 	} | ||||
|  | ||||
| 	return do_git_config_sequence(opts, fn, data); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										3
									
								
								config.h
								
								
								
								
							
							
						
						
									
										3
									
								
								config.h
								
								
								
								
							|  | @ -49,6 +49,8 @@ const char *config_scope_name(enum config_scope scope); | |||
| struct git_config_source { | ||||
| 	unsigned int use_stdin:1; | ||||
| 	const char *file; | ||||
| 	/* The repository if blob is not NULL; leave blank for the_repository */ | ||||
| 	struct repository *repo; | ||||
| 	const char *blob; | ||||
| 	enum config_scope scope; | ||||
| }; | ||||
|  | @ -136,6 +138,7 @@ int git_config_from_mem(config_fn_t fn, | |||
| 			const char *buf, size_t len, | ||||
| 			void *data, const struct config_options *opts); | ||||
| int git_config_from_blob_oid(config_fn_t fn, const char *name, | ||||
| 			     struct repository *repo, | ||||
| 			     const struct object_id *oid, void *data); | ||||
| void git_config_push_parameter(const char *text); | ||||
| void git_config_push_env(const char *spec); | ||||
|  |  | |||
|  | @ -649,9 +649,10 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void | |||
| 			config_source.file = file; | ||||
| 		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 || | ||||
| 			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) { | ||||
| 			config_source.repo = repo; | ||||
| 			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid)); | ||||
| 			if (repo != the_repository) | ||||
| 				add_to_alternates_memory(repo->objects->odb->path); | ||||
| 				add_submodule_odb_by_path(repo->objects->odb->path); | ||||
| 		} else { | ||||
| 			goto out; | ||||
| 		} | ||||
|  | @ -702,7 +703,7 @@ void gitmodules_config_oid(const struct object_id *commit_oid) | |||
|  | ||||
| 	if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) { | ||||
| 		git_config_from_blob_oid(gitmodules_cb, rev.buf, | ||||
| 					 &oid, the_repository); | ||||
| 					 the_repository, &oid, the_repository); | ||||
| 	} | ||||
| 	strbuf_release(&rev); | ||||
|  | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 Jonathan Tan
						Jonathan Tan