repository: add index_state to struct repo
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
		 Brandon Williams
					Brandon Williams
				
			
				
					committed by
					
						 Junio C Hamano
						Junio C Hamano
					
				
			
			
				
	
			
			
			 Junio C Hamano
						Junio C Hamano
					
				
			
						parent
						
							3b256228a6
						
					
				
				
					commit
					639e30b5b2
				
			
							
								
								
									
										16
									
								
								repository.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								repository.c
									
									
									
									
									
								
							| @ -163,4 +163,20 @@ void repo_clear(struct repository *repo) | |||||||
| 		free(repo->config); | 		free(repo->config); | ||||||
| 		repo->config = NULL; | 		repo->config = NULL; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if (repo->index) { | ||||||
|  | 		discard_index(repo->index); | ||||||
|  | 		free(repo->index); | ||||||
|  | 		repo->index = NULL; | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int repo_read_index(struct repository *repo) | ||||||
|  | { | ||||||
|  | 	if (!repo->index) | ||||||
|  | 		repo->index = xcalloc(1, sizeof(*repo->index)); | ||||||
|  | 	else | ||||||
|  | 		discard_index(repo->index); | ||||||
|  |  | ||||||
|  | 	return read_index_from(repo->index, repo->index_file); | ||||||
| } | } | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ | |||||||
| #define REPOSITORY_H | #define REPOSITORY_H | ||||||
|  |  | ||||||
| struct config_set; | struct config_set; | ||||||
|  | struct index_state; | ||||||
|  |  | ||||||
| struct repository { | struct repository { | ||||||
| 	/* Environment */ | 	/* Environment */ | ||||||
| @ -49,6 +50,12 @@ struct repository { | |||||||
| 	 */ | 	 */ | ||||||
| 	struct config_set *config; | 	struct config_set *config; | ||||||
|  |  | ||||||
|  | 	/* | ||||||
|  | 	 * Repository's in-memory index. | ||||||
|  | 	 * 'repo_read_index()' can be used to populate 'index'. | ||||||
|  | 	 */ | ||||||
|  | 	struct index_state *index; | ||||||
|  |  | ||||||
| 	/* Configurations */ | 	/* Configurations */ | ||||||
| 	/* | 	/* | ||||||
| 	 * Bit used during initialization to indicate if repository state (like | 	 * Bit used during initialization to indicate if repository state (like | ||||||
| @ -71,4 +78,6 @@ extern void repo_set_worktree(struct repository *repo, const char *path); | |||||||
| extern int repo_init(struct repository *repo, const char *gitdir, const char *worktree); | extern int repo_init(struct repository *repo, const char *gitdir, const char *worktree); | ||||||
| extern void repo_clear(struct repository *repo); | extern void repo_clear(struct repository *repo); | ||||||
|  |  | ||||||
|  | extern int repo_read_index(struct repository *repo); | ||||||
|  |  | ||||||
| #endif /* REPOSITORY_H */ | #endif /* REPOSITORY_H */ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user