| 4412 | } |
| 4413 | |
| 4414 | static int write_update_refs_state(struct string_list *refs_to_oids) |
| 4415 | { |
| 4416 | int result = 0; |
| 4417 | struct lock_file lock = LOCK_INIT; |
| 4418 | FILE *fp = NULL; |
| 4419 | struct string_list_item *item; |
| 4420 | char *path; |
| 4421 | |
| 4422 | path = rebase_path_update_refs(the_repository->gitdir); |
| 4423 | |
| 4424 | if (!refs_to_oids->nr) { |
| 4425 | if (unlink(path) && errno != ENOENT) |
| 4426 | result = error_errno(_("could not unlink: %s"), path); |
| 4427 | goto cleanup; |
| 4428 | } |
| 4429 | |
| 4430 | if (safe_create_leading_directories(the_repository, path)) { |
| 4431 | result = error(_("unable to create leading directories of %s"), |
| 4432 | path); |
| 4433 | goto cleanup; |
| 4434 | } |
| 4435 | |
| 4436 | if (hold_lock_file_for_update(&lock, path, 0) < 0) { |
| 4437 | result = error(_("another 'rebase' process appears to be running; " |
| 4438 | "'%s.lock' already exists"), |
| 4439 | path); |
| 4440 | goto cleanup; |
| 4441 | } |
| 4442 | |
| 4443 | fp = fdopen_lock_file(&lock, "w"); |
| 4444 | if (!fp) { |
| 4445 | result = error_errno(_("could not open '%s' for writing"), path); |
| 4446 | rollback_lock_file(&lock); |
| 4447 | goto cleanup; |
| 4448 | } |
| 4449 | |
| 4450 | for_each_string_list_item(item, refs_to_oids) { |
| 4451 | struct update_ref_record *rec = item->util; |
| 4452 | fprintf(fp, "%s\n%s\n%s\n", item->string, |
| 4453 | oid_to_hex(&rec->before), oid_to_hex(&rec->after)); |
| 4454 | } |
| 4455 | |
| 4456 | result = commit_lock_file(&lock); |
| 4457 | |
| 4458 | cleanup: |
| 4459 | free(path); |
| 4460 | return result; |
| 4461 | } |
| 4462 | |
| 4463 | /* |
| 4464 | * Parse the update-refs file for the current rebase, then remove the |
no test coverage detected