1#ifndef REPOSITORY_H 2#define REPOSITORY_H 3 4#include"path.h" 5 6struct config_set; 7struct git_hash_algo; 8struct index_state; 9struct lock_file; 10struct pathspec; 11struct raw_object_store; 12struct submodule_cache; 13 14enum untracked_cache_setting { 15 UNTRACKED_CACHE_UNSET = -1, 16 UNTRACKED_CACHE_REMOVE =0, 17 UNTRACKED_CACHE_KEEP =1, 18 UNTRACKED_CACHE_WRITE =2 19}; 20 21struct repo_settings { 22int initialized; 23 24int core_commit_graph; 25int gc_write_commit_graph; 26 27int index_version; 28enum untracked_cache_setting core_untracked_cache; 29 30int pack_use_sparse; 31}; 32 33struct repository { 34/* Environment */ 35/* 36 * Path to the git directory. 37 * Cannot be NULL after initialization. 38 */ 39char*gitdir; 40 41/* 42 * Path to the common git directory. 43 * Cannot be NULL after initialization. 44 */ 45char*commondir; 46 47/* 48 * Holds any information related to accessing the raw object content. 49 */ 50struct raw_object_store *objects; 51 52/* 53 * All objects in this repository that have been parsed. This structure 54 * owns all objects it references, so users of "struct object *" 55 * generally do not need to free them; instead, when a repository is no 56 * longer used, call parsed_object_pool_clear() on this structure, which 57 * is called by the repositories repo_clear on its desconstruction. 58 */ 59struct parsed_object_pool *parsed_objects; 60 61/* The store in which the refs are held. */ 62struct ref_store *refs; 63 64/* 65 * Contains path to often used file names. 66 */ 67struct path_cache cached_paths; 68 69/* 70 * Path to the repository's graft file. 71 * Cannot be NULL after initialization. 72 */ 73char*graft_file; 74 75/* 76 * Path to the current worktree's index file. 77 * Cannot be NULL after initialization. 78 */ 79char*index_file; 80 81/* 82 * Path to the working directory. 83 * A NULL value indicates that there is no working directory. 84 */ 85char*worktree; 86 87/* 88 * Path from the root of the top-level superproject down to this 89 * repository. This is only non-NULL if the repository is initialized 90 * as a submodule of another repository. 91 */ 92char*submodule_prefix; 93 94struct repo_settings settings; 95 96/* Subsystems */ 97/* 98 * Repository's config which contains key-value pairs from the usual 99 * set of config files (i.e. repo specific .git/config, user wide 100 * ~/.gitconfig, XDG config file and the global /etc/gitconfig) 101 */ 102struct config_set *config; 103 104/* Repository's submodule config as defined by '.gitmodules' */ 105struct submodule_cache *submodule_cache; 106 107/* 108 * Repository's in-memory index. 109 * 'repo_read_index()' can be used to populate 'index'. 110 */ 111struct index_state *index; 112 113/* Repository's current hash algorithm, as serialized on disk. */ 114const struct git_hash_algo *hash_algo; 115 116/* A unique-id for tracing purposes. */ 117int trace2_repo_id; 118 119/* Configurations */ 120 121/* Indicate if a repository has a different 'commondir' from 'gitdir' */ 122unsigned different_commondir:1; 123}; 124 125externstruct repository *the_repository; 126 127/* 128 * Define a custom repository layout. Any field can be NULL, which 129 * will default back to the path according to the default layout. 130 */ 131struct set_gitdir_args { 132const char*commondir; 133const char*object_dir; 134const char*graft_file; 135const char*index_file; 136const char*alternate_db; 137}; 138 139voidrepo_set_gitdir(struct repository *repo,const char*root, 140const struct set_gitdir_args *extra_args); 141voidrepo_set_worktree(struct repository *repo,const char*path); 142voidrepo_set_hash_algo(struct repository *repo,int algo); 143voidinitialize_the_repository(void); 144intrepo_init(struct repository *r,const char*gitdir,const char*worktree); 145 146/* 147 * Initialize the repository 'subrepo' as the submodule given by the 148 * struct submodule 'sub' in parent repository 'superproject'. 149 * Return 0 upon success and a non-zero value upon failure, which may happen 150 * if the submodule is not found, or 'sub' is NULL. 151 */ 152struct submodule; 153intrepo_submodule_init(struct repository *subrepo, 154struct repository *superproject, 155const struct submodule *sub); 156voidrepo_clear(struct repository *repo); 157 158/* 159 * Populates the repository's index from its index_file, an index struct will 160 * be allocated if needed. 161 * 162 * Return the number of index entries in the populated index or a value less 163 * than zero if an error occured. If the repository's index has already been 164 * populated then the number of entries will simply be returned. 165 */ 166intrepo_read_index(struct repository *repo); 167intrepo_hold_locked_index(struct repository *repo, 168struct lock_file *lf, 169int flags); 170 171intrepo_read_index_preload(struct repository *, 172const struct pathspec *pathspec, 173unsigned refresh_flags); 174intrepo_read_index_unmerged(struct repository *); 175/* 176 * Opportunistically update the index but do not complain if we can't. 177 * The lockfile is always committed or rolled back. 178 */ 179voidrepo_update_index_if_able(struct repository *,struct lock_file *); 180 181voidprepare_repo_settings(struct repository *r); 182 183#endif/* REPOSITORY_H */