MCPcopy Index your code
hub / github.com/git/git / write_update_refs_state

Function write_update_refs_state

sequencer.c:4414–4461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4412}
4413
4414static 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
4458cleanup:
4459 free(path);
4460 return result;
4461}
4462
4463/*
4464 * Parse the update-refs file for the current rebase, then remove the

Callers 3

do_update_refFunction · 0.85

Calls 8

error_errnoFunction · 0.85
errorFunction · 0.85
fdopen_lock_fileFunction · 0.85
rollback_lock_fileFunction · 0.85
oid_to_hexFunction · 0.85
commit_lock_fileFunction · 0.85

Tested by

no test coverage detected