MCPcopy Create free account
hub / github.com/git/git / write_ref_to_lockfile

Function write_ref_to_lockfile

refs/files-backend.c:2005–2024  ·  view source on GitHub ↗

* Write oid into the open lockfile, then close the lockfile. On * errors, rollback the lockfile, fill in *err and return -1. */

Source from the content-addressed store, hash-verified

2003 * errors, rollback the lockfile, fill in *err and return -1.
2004 */
2005static 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

Callers 2

files_copy_or_rename_refFunction · 0.85
lock_ref_for_updateFunction · 0.85

Calls 8

get_lock_file_fdFunction · 0.85
write_in_fullFunction · 0.85
oid_to_hexFunction · 0.85
close_ref_gentlyFunction · 0.85
strbuf_addfFunction · 0.85
get_lock_file_pathFunction · 0.85
unlock_refFunction · 0.85
fsync_componentEnum · 0.50

Tested by

no test coverage detected