| 151 | } |
| 152 | |
| 153 | int is_sparse_index_allowed(struct index_state *istate, int flags) |
| 154 | { |
| 155 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 156 | |
| 157 | if (!cfg->apply_sparse_checkout || !cfg->core_sparse_checkout_cone) |
| 158 | return 0; |
| 159 | |
| 160 | if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) { |
| 161 | int test_env; |
| 162 | |
| 163 | /* |
| 164 | * The sparse index is not (yet) integrated with a split index. |
| 165 | */ |
| 166 | if (istate->split_index || git_env_bool("GIT_TEST_SPLIT_INDEX", 0)) |
| 167 | return 0; |
| 168 | /* |
| 169 | * The GIT_TEST_SPARSE_INDEX environment variable triggers the |
| 170 | * index.sparse config variable to be on. |
| 171 | */ |
| 172 | test_env = git_env_bool("GIT_TEST_SPARSE_INDEX", -1); |
| 173 | if (test_env >= 0) |
| 174 | set_sparse_index_config(istate->repo, test_env); |
| 175 | |
| 176 | /* |
| 177 | * Only convert to sparse if index.sparse is set. |
| 178 | */ |
| 179 | prepare_repo_settings(istate->repo); |
| 180 | if (!istate->repo->settings.sparse_index) |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | if (init_sparse_checkout_patterns(istate)) |
| 185 | return 0; |
| 186 | |
| 187 | /* |
| 188 | * We need cone-mode patterns to use sparse-index. If a user edits |
| 189 | * their sparse-checkout file manually, then we can detect during |
| 190 | * parsing that they are not actually using cone-mode patterns and |
| 191 | * hence we need to abort this conversion _without error_. Warnings |
| 192 | * already exist in the pattern parsing to inform the user of their |
| 193 | * bad patterns. |
| 194 | */ |
| 195 | if (!istate->sparse_checkout_patterns->use_cone_patterns) |
| 196 | return 0; |
| 197 | |
| 198 | return 1; |
| 199 | } |
| 200 | |
| 201 | int convert_to_sparse(struct index_state *istate, int flags) |
| 202 | { |
no test coverage detected