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