| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 1 | #ifndef REPOSITORY_H |
| 2 | #define REPOSITORY_H |
| 3 | |
| Elijah Newren | ef3ca95 | 2018-08-15 17:54:05 | [diff] [blame] | 4 | #include "path.h" |
| 5 | |
| Brandon Williams | 3b25622 | 2017-06-22 18:43:42 | [diff] [blame] | 6 | struct config_set; |
| brian m. carlson | 78a6766 | 2017-11-12 21:28:53 | [diff] [blame] | 7 | struct git_hash_algo; |
| Stefan Beller | 90c6215 | 2018-03-23 17:20:55 | [diff] [blame] | 8 | struct index_state; |
| 9 | struct raw_object_store; |
| 10 | struct submodule_cache; |
| Brandon Williams | 3b25622 | 2017-06-22 18:43:42 | [diff] [blame] | 11 | |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 12 | struct repository { |
| 13 | /* Environment */ |
| 14 | /* |
| 15 | * Path to the git directory. |
| 16 | * Cannot be NULL after initialization. |
| 17 | */ |
| 18 | char *gitdir; |
| 19 | |
| 20 | /* |
| 21 | * Path to the common git directory. |
| 22 | * Cannot be NULL after initialization. |
| 23 | */ |
| 24 | char *commondir; |
| 25 | |
| 26 | /* |
| Stefan Beller | 90c6215 | 2018-03-23 17:20:55 | [diff] [blame] | 27 | * Holds any information related to accessing the raw object content. |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 28 | */ |
| Stefan Beller | 90c6215 | 2018-03-23 17:20:55 | [diff] [blame] | 29 | struct raw_object_store *objects; |
| Nguyễn Thái Ngọc Duy | 7bc0dca | 2018-03-03 11:35:57 | [diff] [blame] | 30 | |
| Stefan Beller | 99bf115 | 2018-05-08 19:37:24 | [diff] [blame] | 31 | /* |
| 32 | * All objects in this repository that have been parsed. This structure |
| 33 | * owns all objects it references, so users of "struct object *" |
| 34 | * generally do not need to free them; instead, when a repository is no |
| 35 | * longer used, call parsed_object_pool_clear() on this structure, which |
| 36 | * is called by the repositories repo_clear on its desconstruction. |
| 37 | */ |
| 38 | struct parsed_object_pool *parsed_objects; |
| 39 | |
| Stefan Beller | 64a7416 | 2018-04-12 00:21:14 | [diff] [blame] | 40 | /* The store in which the refs are held. */ |
| 41 | struct ref_store *refs; |
| 42 | |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 43 | /* |
| Stefan Beller | 102de88 | 2018-05-17 22:51:51 | [diff] [blame] | 44 | * Contains path to often used file names. |
| 45 | */ |
| 46 | struct path_cache cached_paths; |
| 47 | |
| 48 | /* |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 49 | * Path to the repository's graft file. |
| 50 | * Cannot be NULL after initialization. |
| 51 | */ |
| 52 | char *graft_file; |
| 53 | |
| 54 | /* |
| 55 | * Path to the current worktree's index file. |
| 56 | * Cannot be NULL after initialization. |
| 57 | */ |
| 58 | char *index_file; |
| 59 | |
| 60 | /* |
| 61 | * Path to the working directory. |
| 62 | * A NULL value indicates that there is no working directory. |
| 63 | */ |
| 64 | char *worktree; |
| 65 | |
| Brandon Williams | 96dc883 | 2017-06-22 18:43:47 | [diff] [blame] | 66 | /* |
| 67 | * Path from the root of the top-level superproject down to this |
| 68 | * repository. This is only non-NULL if the repository is initialized |
| 69 | * as a submodule of another repository. |
| 70 | */ |
| 71 | char *submodule_prefix; |
| 72 | |
| Brandon Williams | 3b25622 | 2017-06-22 18:43:42 | [diff] [blame] | 73 | /* Subsystems */ |
| 74 | /* |
| 75 | * Repository's config which contains key-value pairs from the usual |
| 76 | * set of config files (i.e. repo specific .git/config, user wide |
| 77 | * ~/.gitconfig, XDG config file and the global /etc/gitconfig) |
| 78 | */ |
| 79 | struct config_set *config; |
| 80 | |
| Brandon Williams | bf12fcd | 2017-06-22 18:43:44 | [diff] [blame] | 81 | /* Repository's submodule config as defined by '.gitmodules' */ |
| 82 | struct submodule_cache *submodule_cache; |
| 83 | |
| Brandon Williams | 639e30b | 2017-06-22 18:43:43 | [diff] [blame] | 84 | /* |
| 85 | * Repository's in-memory index. |
| 86 | * 'repo_read_index()' can be used to populate 'index'. |
| 87 | */ |
| 88 | struct index_state *index; |
| 89 | |
| brian m. carlson | 78a6766 | 2017-11-12 21:28:53 | [diff] [blame] | 90 | /* Repository's current hash algorithm, as serialized on disk. */ |
| 91 | const struct git_hash_algo *hash_algo; |
| 92 | |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 93 | /* Configurations */ |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 94 | |
| 95 | /* Indicate if a repository has a different 'commondir' from 'gitdir' */ |
| 96 | unsigned different_commondir:1; |
| 97 | }; |
| 98 | |
| 99 | extern struct repository *the_repository; |
| 100 | |
| Nguyễn Thái Ngọc Duy | 00a3da2 | 2018-03-23 15:55:23 | [diff] [blame] | 101 | /* |
| 102 | * Define a custom repository layout. Any field can be NULL, which |
| 103 | * will default back to the path according to the default layout. |
| 104 | */ |
| Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 11:35:55 | [diff] [blame] | 105 | struct set_gitdir_args { |
| 106 | const char *commondir; |
| 107 | const char *object_dir; |
| 108 | const char *graft_file; |
| 109 | const char *index_file; |
| Nguyễn Thái Ngọc Duy | 7bc0dca | 2018-03-03 11:35:57 | [diff] [blame] | 110 | const char *alternate_db; |
| Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 11:35:55 | [diff] [blame] | 111 | }; |
| 112 | |
| Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 09:20:29 | [diff] [blame] | 113 | void repo_set_gitdir(struct repository *repo, const char *root, |
| 114 | const struct set_gitdir_args *extra_args); |
| 115 | void repo_set_worktree(struct repository *repo, const char *path); |
| 116 | void repo_set_hash_algo(struct repository *repo, int algo); |
| 117 | void initialize_the_repository(void); |
| 118 | int repo_init(struct repository *r, const char *gitdir, const char *worktree); |
| 119 | int repo_submodule_init(struct repository *submodule, |
| 120 | struct repository *superproject, |
| 121 | const char *path); |
| 122 | void repo_clear(struct repository *repo); |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 123 | |
| Brandon Williams | 3f13877 | 2017-07-18 19:05:18 | [diff] [blame] | 124 | /* |
| 125 | * Populates the repository's index from its index_file, an index struct will |
| 126 | * be allocated if needed. |
| 127 | * |
| 128 | * Return the number of index entries in the populated index or a value less |
| 129 | * than zero if an error occured. If the repository's index has already been |
| 130 | * populated then the number of entries will simply be returned. |
| 131 | */ |
| Nguyễn Thái Ngọc Duy | c2ec417 | 2018-06-30 09:20:29 | [diff] [blame] | 132 | int repo_read_index(struct repository *repo); |
| Brandon Williams | 639e30b | 2017-06-22 18:43:43 | [diff] [blame] | 133 | |
| Brandon Williams | 359efef | 2017-06-22 18:43:32 | [diff] [blame] | 134 | #endif /* REPOSITORY_H */ |