| 328 | } |
| 329 | |
| 330 | static int write_patterns_and_update(struct repository *repo, |
| 331 | struct pattern_list *pl) |
| 332 | { |
| 333 | char *sparse_filename; |
| 334 | FILE *fp; |
| 335 | struct lock_file lk = LOCK_INIT; |
| 336 | int result; |
| 337 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 338 | |
| 339 | sparse_filename = get_sparse_checkout_filename(); |
| 340 | |
| 341 | if (safe_create_leading_directories(repo, sparse_filename)) |
| 342 | die(_("failed to create directory for sparse-checkout file")); |
| 343 | |
| 344 | hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR); |
| 345 | |
| 346 | result = update_working_directory(repo, pl); |
| 347 | if (result) { |
| 348 | rollback_lock_file(&lk); |
| 349 | update_working_directory(repo, NULL); |
| 350 | goto out; |
| 351 | } |
| 352 | |
| 353 | fp = fdopen_lock_file(&lk, "w"); |
| 354 | if (!fp) |
| 355 | die_errno(_("unable to fdopen %s"), get_lock_file_path(&lk)); |
| 356 | |
| 357 | if (cfg->core_sparse_checkout_cone) |
| 358 | write_cone_to_file(fp, pl); |
| 359 | else |
| 360 | write_patterns_to_file(fp, pl); |
| 361 | |
| 362 | if (commit_lock_file(&lk)) |
| 363 | die_errno(_("unable to write %s"), sparse_filename); |
| 364 | |
| 365 | out: |
| 366 | clear_pattern_list(pl); |
| 367 | free(sparse_filename); |
| 368 | return result; |
| 369 | } |
| 370 | |
| 371 | enum sparse_checkout_mode { |
| 372 | MODE_NO_PATTERNS = 0, |
no test coverage detected