Nguyễn Thái Ngọc Duy | f8adbec | 2019-01-24 15:29:12 +0700 | [diff] [blame] | 1 | /* |
| 2 | * not really _using_ the compat macros, just make sure the_index |
| 3 | * declaration matches the definition in this file. |
| 4 | */ |
Ævar Arnfjörð Bjarmason | 666f53e | 2022-11-19 14:07:36 +0100 | [diff] [blame] | 5 | #define USE_THE_INDEX_VARIABLE |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 6 | #include "cache.h" |
| 7 | #include "repository.h" |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 8 | #include "object-store.h" |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 9 | #include "config.h" |
Stefan Beller | 99bf115 | 2018-05-08 12:37:24 -0700 | [diff] [blame] | 10 | #include "object.h" |
Nguyễn Thái Ngọc Duy | 3a95f31 | 2019-01-12 09:13:24 +0700 | [diff] [blame] | 11 | #include "lockfile.h" |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 12 | #include "remote.h" |
Brandon Williams | bf12fcd | 2017-06-22 11:43:44 -0700 | [diff] [blame] | 13 | #include "submodule-config.h" |
Derrick Stolee | 3964fc2 | 2021-03-30 13:10:47 +0000 | [diff] [blame] | 14 | #include "sparse-index.h" |
Jonathan Tan | ef7dc2e | 2021-06-17 10:13:23 -0700 | [diff] [blame] | 15 | #include "promisor-remote.h" |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 16 | |
| 17 | /* The main repository */ |
Nguyễn Thái Ngọc Duy | b2f0ece | 2018-03-03 18:35:54 +0700 | [diff] [blame] | 18 | static struct repository the_repo; |
| 19 | struct repository *the_repository; |
Nguyễn Thái Ngọc Duy | f8adbec | 2019-01-24 15:29:12 +0700 | [diff] [blame] | 20 | struct index_state the_index; |
Nguyễn Thái Ngọc Duy | b2f0ece | 2018-03-03 18:35:54 +0700 | [diff] [blame] | 21 | |
| 22 | void initialize_the_repository(void) |
| 23 | { |
| 24 | the_repository = &the_repo; |
| 25 | |
| 26 | the_repo.index = &the_index; |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 27 | the_repo.objects = raw_object_store_new(); |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 28 | the_repo.remote_state = remote_state_new(); |
Stefan Beller | 99bf115 | 2018-05-08 12:37:24 -0700 | [diff] [blame] | 29 | the_repo.parsed_objects = parsed_object_pool_new(); |
| 30 | |
Nguyễn Thái Ngọc Duy | b2f0ece | 2018-03-03 18:35:54 +0700 | [diff] [blame] | 31 | repo_set_hash_algo(&the_repo, GIT_HASH_SHA1); |
| 32 | } |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 33 | |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 34 | static void expand_base_dir(char **out, const char *in, |
| 35 | const char *base_dir, const char *def_in) |
| 36 | { |
| 37 | free(*out); |
| 38 | if (in) |
| 39 | *out = xstrdup(in); |
| 40 | else |
| 41 | *out = xstrfmt("%s/%s", base_dir, def_in); |
| 42 | } |
| 43 | |
| 44 | static void repo_set_commondir(struct repository *repo, |
| 45 | const char *commondir) |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 46 | { |
| 47 | struct strbuf sb = STRBUF_INIT; |
| 48 | |
Jeff King | f9b7573 | 2017-09-05 09:04:57 -0400 | [diff] [blame] | 49 | free(repo->commondir); |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 50 | |
| 51 | if (commondir) { |
| 52 | repo->different_commondir = 1; |
| 53 | repo->commondir = xstrdup(commondir); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | repo->different_commondir = get_common_dir_noenv(&sb, repo->gitdir); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 58 | repo->commondir = strbuf_detach(&sb, NULL); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 61 | void repo_set_gitdir(struct repository *repo, |
| 62 | const char *root, |
| 63 | const struct set_gitdir_args *o) |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 64 | { |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 65 | const char *gitfile = read_gitfile(root); |
| 66 | /* |
| 67 | * repo->gitdir is saved because the caller could pass "root" |
| 68 | * that also points to repo->gitdir. We want to keep it alive |
| 69 | * until after xstrdup(root). Then we can free it. |
| 70 | */ |
Jeff King | 1fb2b63 | 2017-09-05 09:05:01 -0400 | [diff] [blame] | 71 | char *old_gitdir = repo->gitdir; |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 72 | |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 73 | repo->gitdir = xstrdup(gitfile ? gitfile : root); |
Jeff King | 1fb2b63 | 2017-09-05 09:05:01 -0400 | [diff] [blame] | 74 | free(old_gitdir); |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 75 | |
| 76 | repo_set_commondir(repo, o->commondir); |
Jeff King | f0eaf63 | 2018-11-12 09:50:39 -0500 | [diff] [blame] | 77 | |
| 78 | if (!repo->objects->odb) { |
René Scharfe | ca56dad | 2021-03-13 17:17:22 +0100 | [diff] [blame] | 79 | CALLOC_ARRAY(repo->objects->odb, 1); |
Jeff King | f0eaf63 | 2018-11-12 09:50:39 -0500 | [diff] [blame] | 80 | repo->objects->odb_tail = &repo->objects->odb->next; |
| 81 | } |
| 82 | expand_base_dir(&repo->objects->odb->path, o->object_dir, |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 83 | repo->commondir, "objects"); |
Jeff King | f0eaf63 | 2018-11-12 09:50:39 -0500 | [diff] [blame] | 84 | |
Neeraj Singh | ecd81df | 2021-12-06 22:05:05 +0000 | [diff] [blame] | 85 | repo->objects->odb->disable_ref_updates = o->disable_ref_updates; |
| 86 | |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 87 | free(repo->objects->alternate_db); |
| 88 | repo->objects->alternate_db = xstrdup_or_null(o->alternate_db); |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 89 | expand_base_dir(&repo->graft_file, o->graft_file, |
| 90 | repo->commondir, "info/grafts"); |
| 91 | expand_base_dir(&repo->index_file, o->index_file, |
| 92 | repo->gitdir, "index"); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 93 | } |
| 94 | |
brian m. carlson | 78a6766 | 2017-11-12 21:28:53 +0000 | [diff] [blame] | 95 | void repo_set_hash_algo(struct repository *repo, int hash_algo) |
| 96 | { |
| 97 | repo->hash_algo = &hash_algos[hash_algo]; |
| 98 | } |
| 99 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 100 | /* |
| 101 | * Attempt to resolve and set the provided 'gitdir' for repository 'repo'. |
| 102 | * Return 0 upon success and a non-zero value upon failure. |
| 103 | */ |
| 104 | static int repo_init_gitdir(struct repository *repo, const char *gitdir) |
| 105 | { |
| 106 | int ret = 0; |
| 107 | int error = 0; |
| 108 | char *abspath = NULL; |
| 109 | const char *resolved_gitdir; |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 110 | struct set_gitdir_args args = { NULL }; |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 111 | |
| 112 | abspath = real_pathdup(gitdir, 0); |
| 113 | if (!abspath) { |
| 114 | ret = -1; |
| 115 | goto out; |
| 116 | } |
| 117 | |
| 118 | /* 'gitdir' must reference the gitdir directly */ |
| 119 | resolved_gitdir = resolve_gitdir_gently(abspath, &error); |
| 120 | if (!resolved_gitdir) { |
| 121 | ret = -1; |
| 122 | goto out; |
| 123 | } |
| 124 | |
Nguyễn Thái Ngọc Duy | 357a03e | 2018-03-03 18:35:55 +0700 | [diff] [blame] | 125 | repo_set_gitdir(repo, resolved_gitdir, &args); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 126 | |
| 127 | out: |
| 128 | free(abspath); |
| 129 | return ret; |
| 130 | } |
| 131 | |
| 132 | void repo_set_worktree(struct repository *repo, const char *path) |
| 133 | { |
| 134 | repo->worktree = real_pathdup(path, 1); |
Jeff Hostetler | ee4512e | 2019-02-22 14:25:01 -0800 | [diff] [blame] | 135 | |
| 136 | trace2_def_repo(repo); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static int read_and_verify_repository_format(struct repository_format *format, |
| 140 | const char *commondir) |
| 141 | { |
| 142 | int ret = 0; |
| 143 | struct strbuf sb = STRBUF_INIT; |
| 144 | |
| 145 | strbuf_addf(&sb, "%s/config", commondir); |
| 146 | read_repository_format(format, sb.buf); |
| 147 | strbuf_reset(&sb); |
| 148 | |
| 149 | if (verify_repository_format(format, &sb) < 0) { |
| 150 | warning("%s", sb.buf); |
| 151 | ret = -1; |
| 152 | } |
| 153 | |
| 154 | strbuf_release(&sb); |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Initialize 'repo' based on the provided 'gitdir'. |
| 160 | * Return 0 upon success and a non-zero value upon failure. |
| 161 | */ |
Stefan Beller | da62f78 | 2018-03-28 15:35:31 -0700 | [diff] [blame] | 162 | int repo_init(struct repository *repo, |
| 163 | const char *gitdir, |
| 164 | const char *worktree) |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 165 | { |
Martin Ågren | e8805af | 2019-02-28 21:36:28 +0100 | [diff] [blame] | 166 | struct repository_format format = REPOSITORY_FORMAT_INIT; |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 167 | memset(repo, 0, sizeof(*repo)); |
| 168 | |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 169 | repo->objects = raw_object_store_new(); |
Stefan Beller | 99bf115 | 2018-05-08 12:37:24 -0700 | [diff] [blame] | 170 | repo->parsed_objects = parsed_object_pool_new(); |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 171 | repo->remote_state = remote_state_new(); |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 172 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 173 | if (repo_init_gitdir(repo, gitdir)) |
| 174 | goto error; |
| 175 | |
| 176 | if (read_and_verify_repository_format(&format, repo->commondir)) |
| 177 | goto error; |
| 178 | |
brian m. carlson | 78a6766 | 2017-11-12 21:28:53 +0000 | [diff] [blame] | 179 | repo_set_hash_algo(repo, format.hash_algo); |
| 180 | |
Jonathan Tan | ebaf3bc | 2021-06-17 10:13:22 -0700 | [diff] [blame] | 181 | /* take ownership of format.partial_clone */ |
| 182 | repo->repository_format_partial_clone = format.partial_clone; |
| 183 | format.partial_clone = NULL; |
| 184 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 185 | if (worktree) |
| 186 | repo_set_worktree(repo, worktree); |
| 187 | |
Martin Ågren | e8805af | 2019-02-28 21:36:28 +0100 | [diff] [blame] | 188 | clear_repository_format(&format); |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 189 | return 0; |
| 190 | |
| 191 | error: |
| 192 | repo_clear(repo); |
| 193 | return -1; |
| 194 | } |
| 195 | |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 196 | int repo_submodule_init(struct repository *subrepo, |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 197 | struct repository *superproject, |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 198 | const char *path, |
| 199 | const struct object_id *treeish_name) |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 200 | { |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 201 | struct strbuf gitdir = STRBUF_INIT; |
| 202 | struct strbuf worktree = STRBUF_INIT; |
| 203 | int ret = 0; |
| 204 | |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 205 | strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path); |
| 206 | strbuf_repo_worktree_path(&worktree, superproject, "%s", path); |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 207 | |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 208 | if (repo_init(subrepo, gitdir.buf, worktree.buf)) { |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 209 | /* |
Elijah Newren | 15beaaa | 2019-11-05 17:07:23 +0000 | [diff] [blame] | 210 | * If initialization fails then it may be due to the submodule |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 211 | * not being populated in the superproject's worktree. Instead |
Elijah Newren | 15beaaa | 2019-11-05 17:07:23 +0000 | [diff] [blame] | 212 | * we can try to initialize the submodule by finding it's gitdir |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 213 | * in the superproject's 'modules' directory. In this case the |
| 214 | * submodule would not have a worktree. |
| 215 | */ |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 216 | const struct submodule *sub = |
| 217 | submodule_from_path(superproject, treeish_name, path); |
| 218 | if (!sub) { |
| 219 | ret = -1; |
| 220 | goto out; |
| 221 | } |
| 222 | |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 223 | strbuf_reset(&gitdir); |
Jonathan Tan | ce125d4 | 2021-09-15 11:59:19 -0700 | [diff] [blame] | 224 | submodule_name_to_gitdir(&gitdir, superproject, sub->name); |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 225 | |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 226 | if (repo_init(subrepo, gitdir.buf, NULL)) { |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 227 | ret = -1; |
| 228 | goto out; |
| 229 | } |
| 230 | } |
| 231 | |
Stefan Beller | d5498e0 | 2018-11-28 16:27:53 -0800 | [diff] [blame] | 232 | subrepo->submodule_prefix = xstrfmt("%s%s/", |
| 233 | superproject->submodule_prefix ? |
| 234 | superproject->submodule_prefix : |
Jonathan Tan | 8eb8dcf | 2021-09-09 11:47:28 -0700 | [diff] [blame] | 235 | "", path); |
Brandon Williams | 96dc883 | 2017-06-22 11:43:47 -0700 | [diff] [blame] | 236 | |
| 237 | out: |
| 238 | strbuf_release(&gitdir); |
| 239 | strbuf_release(&worktree); |
| 240 | return ret; |
| 241 | } |
| 242 | |
Ævar Arnfjörð Bjarmason | 759f340 | 2022-03-04 19:32:17 +0100 | [diff] [blame] | 243 | static void repo_clear_path_cache(struct repo_path_cache *cache) |
| 244 | { |
| 245 | FREE_AND_NULL(cache->squash_msg); |
| 246 | FREE_AND_NULL(cache->squash_msg); |
| 247 | FREE_AND_NULL(cache->merge_msg); |
| 248 | FREE_AND_NULL(cache->merge_rr); |
| 249 | FREE_AND_NULL(cache->merge_mode); |
| 250 | FREE_AND_NULL(cache->merge_head); |
| 251 | FREE_AND_NULL(cache->merge_autostash); |
| 252 | FREE_AND_NULL(cache->auto_merge); |
| 253 | FREE_AND_NULL(cache->fetch_head); |
| 254 | FREE_AND_NULL(cache->shallow); |
| 255 | } |
| 256 | |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 257 | void repo_clear(struct repository *repo) |
| 258 | { |
René Scharfe | 90dd04a | 2017-10-01 16:44:46 +0200 | [diff] [blame] | 259 | FREE_AND_NULL(repo->gitdir); |
| 260 | FREE_AND_NULL(repo->commondir); |
René Scharfe | 90dd04a | 2017-10-01 16:44:46 +0200 | [diff] [blame] | 261 | FREE_AND_NULL(repo->graft_file); |
| 262 | FREE_AND_NULL(repo->index_file); |
| 263 | FREE_AND_NULL(repo->worktree); |
| 264 | FREE_AND_NULL(repo->submodule_prefix); |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 265 | |
Stefan Beller | 90c6215 | 2018-03-23 18:20:55 +0100 | [diff] [blame] | 266 | raw_object_store_clear(repo->objects); |
| 267 | FREE_AND_NULL(repo->objects); |
| 268 | |
Stefan Beller | 99bf115 | 2018-05-08 12:37:24 -0700 | [diff] [blame] | 269 | parsed_object_pool_clear(repo->parsed_objects); |
| 270 | FREE_AND_NULL(repo->parsed_objects); |
| 271 | |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 272 | if (repo->config) { |
| 273 | git_configset_clear(repo->config); |
René Scharfe | 90dd04a | 2017-10-01 16:44:46 +0200 | [diff] [blame] | 274 | FREE_AND_NULL(repo->config); |
Brandon Williams | 3b25622 | 2017-06-22 11:43:42 -0700 | [diff] [blame] | 275 | } |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 276 | |
Brandon Williams | bf12fcd | 2017-06-22 11:43:44 -0700 | [diff] [blame] | 277 | if (repo->submodule_cache) { |
| 278 | submodule_cache_free(repo->submodule_cache); |
| 279 | repo->submodule_cache = NULL; |
| 280 | } |
| 281 | |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 282 | if (repo->index) { |
| 283 | discard_index(repo->index); |
Nguyễn Thái Ngọc Duy | 74373b5 | 2018-05-10 08:13:10 +0200 | [diff] [blame] | 284 | if (repo->index != &the_index) |
| 285 | FREE_AND_NULL(repo->index); |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 286 | } |
Jonathan Tan | ef7dc2e | 2021-06-17 10:13:23 -0700 | [diff] [blame] | 287 | |
| 288 | if (repo->promisor_remote_config) { |
| 289 | promisor_remote_clear(repo->promisor_remote_config); |
| 290 | FREE_AND_NULL(repo->promisor_remote_config); |
| 291 | } |
Glen Choo | fd3cb05 | 2021-11-17 16:53:22 -0800 | [diff] [blame] | 292 | |
| 293 | if (repo->remote_state) { |
| 294 | remote_state_clear(repo->remote_state); |
| 295 | FREE_AND_NULL(repo->remote_state); |
| 296 | } |
Ævar Arnfjörð Bjarmason | 759f340 | 2022-03-04 19:32:17 +0100 | [diff] [blame] | 297 | |
| 298 | repo_clear_path_cache(&repo->cached_paths); |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | int repo_read_index(struct repository *repo) |
| 302 | { |
Derrick Stolee | 3964fc2 | 2021-03-30 13:10:47 +0000 | [diff] [blame] | 303 | int res; |
| 304 | |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 305 | if (!repo->index) |
René Scharfe | ca56dad | 2021-03-13 17:17:22 +0100 | [diff] [blame] | 306 | CALLOC_ARRAY(repo->index, 1); |
Brandon Williams | 639e30b | 2017-06-22 11:43:43 -0700 | [diff] [blame] | 307 | |
Derrick Stolee | 1fd9ae5 | 2021-01-23 19:58:15 +0000 | [diff] [blame] | 308 | /* Complete the double-reference */ |
| 309 | if (!repo->index->repo) |
| 310 | repo->index->repo = repo; |
| 311 | else if (repo->index->repo != repo) |
| 312 | BUG("repo's index should point back at itself"); |
| 313 | |
Derrick Stolee | 3964fc2 | 2021-03-30 13:10:47 +0000 | [diff] [blame] | 314 | res = read_index_from(repo->index, repo->index_file, repo->gitdir); |
| 315 | |
| 316 | prepare_repo_settings(repo); |
| 317 | if (repo->settings.command_requires_full_index) |
| 318 | ensure_full_index(repo->index); |
| 319 | |
Elijah Newren | af6a518 | 2022-01-14 15:59:41 +0000 | [diff] [blame] | 320 | /* |
| 321 | * If sparse checkouts are in use, check whether paths with the |
| 322 | * SKIP_WORKTREE attribute are missing from the worktree; if not, |
| 323 | * clear that attribute for that path. |
| 324 | */ |
| 325 | clear_skip_worktree_from_present_files(repo->index); |
| 326 | |
Derrick Stolee | 3964fc2 | 2021-03-30 13:10:47 +0000 | [diff] [blame] | 327 | return res; |
Brandon Williams | 359efef | 2017-06-22 11:43:32 -0700 | [diff] [blame] | 328 | } |
Nguyễn Thái Ngọc Duy | 3a95f31 | 2019-01-12 09:13:24 +0700 | [diff] [blame] | 329 | |
| 330 | int repo_hold_locked_index(struct repository *repo, |
| 331 | struct lock_file *lf, |
| 332 | int flags) |
| 333 | { |
| 334 | if (!repo->index_file) |
| 335 | BUG("the repo hasn't been setup"); |
| 336 | return hold_lock_file_for_update(lf, repo->index_file, flags); |
| 337 | } |