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

Function lock_ref_oid_basic

refs/files-backend.c:1210–1258  ·  view source on GitHub ↗

* Locks a ref returning the lock on success and NULL on failure. */

Source from the content-addressed store, hash-verified

1208 * Locks a ref returning the lock on success and NULL on failure.
1209 */
1210static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
1211 const char *refname,
1212 struct strbuf *err)
1213{
1214 struct strbuf ref_file = STRBUF_INIT;
1215 struct ref_lock *lock;
1216 struct create_reflock_cb cb_data;
1217
1218 files_assert_main_repository(refs, "lock_ref_oid_basic");
1219 assert(err);
1220
1221 CALLOC_ARRAY(lock, 1);
1222
1223 files_ref_path(refs, &ref_file, refname);
1224
1225 /*
1226 * If the ref did not exist and we are creating it, make sure
1227 * there is no existing packed ref whose name begins with our
1228 * refname, nor a packed ref whose name is a proper prefix of
1229 * our refname.
1230 */
1231 if (is_null_oid(&lock->old_oid) &&
1232 refs_verify_refname_available(refs->packed_ref_store, refname,
1233 NULL, NULL, 0, err))
1234 goto error_return;
1235
1236 lock->ref_name = xstrdup(refname);
1237 lock->count = 1;
1238 cb_data.lk = &lock->lk;
1239 cb_data.repo = refs->base.repo;
1240
1241 if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
1242 unable_to_lock_message(ref_file.buf, errno, err);
1243 goto error_return;
1244 }
1245
1246 if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
1247 &lock->old_oid, NULL))
1248 oidclr(&lock->old_oid, refs->base.repo->hash_algo);
1249 goto out;
1250
1251 error_return:
1252 unlock_ref(lock);
1253 lock = NULL;
1254
1255 out:
1256 strbuf_release(&ref_file);
1257 return lock;
1258}
1259
1260struct ref_to_prune {
1261 struct ref_to_prune *next;

Callers 2

files_copy_or_rename_refFunction · 0.85
files_reflog_expireFunction · 0.85

Calls 11

files_ref_pathFunction · 0.85
is_null_oidFunction · 0.85
xstrdupFunction · 0.85
raceproof_create_fileFunction · 0.85
unable_to_lock_messageFunction · 0.85
refs_resolve_ref_unsafeFunction · 0.85
oidclrFunction · 0.85
unlock_refFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected