* Write oid into the open lockfile, then close the lockfile. On * errors, rollback the lockfile, fill in *err and return -1. */
| 2003 | * errors, rollback the lockfile, fill in *err and return -1. |
| 2004 | */ |
| 2005 | static enum ref_transaction_error write_ref_to_lockfile(struct files_ref_store *refs, |
| 2006 | struct ref_lock *lock, |
| 2007 | const struct object_id *oid, |
| 2008 | struct strbuf *err) |
| 2009 | { |
| 2010 | static char term = '\n'; |
| 2011 | int fd; |
| 2012 | |
| 2013 | fd = get_lock_file_fd(&lock->lk); |
| 2014 | if (write_in_full(fd, oid_to_hex(oid), refs->base.repo->hash_algo->hexsz) < 0 || |
| 2015 | write_in_full(fd, &term, 1) < 0 || |
| 2016 | fsync_component(FSYNC_COMPONENT_REFERENCE, get_lock_file_fd(&lock->lk)) < 0 || |
| 2017 | close_ref_gently(lock) < 0) { |
| 2018 | strbuf_addf(err, |
| 2019 | "couldn't write '%s'", get_lock_file_path(&lock->lk)); |
| 2020 | unlock_ref(lock); |
| 2021 | return REF_TRANSACTION_ERROR_GENERIC; |
| 2022 | } |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
| 2026 | /* |
| 2027 | * Commit a change to a loose reference that has already been written |
no test coverage detected