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

Function read_basic_state

builtin/rebase.c:439–513  ·  view source on GitHub ↗

Initialize the rebase options from the state directory. */

Source from the content-addressed store, hash-verified

437
438/* Initialize the rebase options from the state directory. */
439static int read_basic_state(struct rebase_options *opts)
440{
441 struct strbuf head_name = STRBUF_INIT;
442 struct strbuf buf = STRBUF_INIT;
443 struct object_id oid;
444
445 if (!read_oneliner(&head_name, state_dir_path("head-name", opts),
446 READ_ONELINER_WARN_MISSING) ||
447 !read_oneliner(&buf, state_dir_path("onto", opts),
448 READ_ONELINER_WARN_MISSING))
449 return -1;
450 opts->head_name = starts_with(head_name.buf, "refs/") ?
451 xstrdup(head_name.buf) : NULL;
452 strbuf_release(&head_name);
453 if (get_oid_hex(buf.buf, &oid) ||
454 !(opts->onto = lookup_commit_object(the_repository, &oid)))
455 return error(_("invalid onto: '%s'"), buf.buf);
456
457 /*
458 * We always write to orig-head, but interactive rebase used to write to
459 * head. Fall back to reading from head to cover for the case that the
460 * user upgraded git with an ongoing interactive rebase.
461 */
462 strbuf_reset(&buf);
463 if (file_exists(state_dir_path("orig-head", opts))) {
464 if (!read_oneliner(&buf, state_dir_path("orig-head", opts),
465 READ_ONELINER_WARN_MISSING))
466 return -1;
467 } else if (!read_oneliner(&buf, state_dir_path("head", opts),
468 READ_ONELINER_WARN_MISSING))
469 return -1;
470 if (get_oid_hex(buf.buf, &oid) ||
471 !(opts->orig_head = lookup_commit_object(the_repository, &oid)))
472 return error(_("invalid orig-head: '%s'"), buf.buf);
473
474 if (file_exists(state_dir_path("quiet", opts)))
475 opts->flags &= ~REBASE_NO_QUIET;
476 else
477 opts->flags |= REBASE_NO_QUIET;
478
479 if (file_exists(state_dir_path("verbose", opts)))
480 opts->flags |= REBASE_VERBOSE;
481
482 if (file_exists(state_dir_path("signoff", opts))) {
483 opts->signoff = 1;
484 opts->flags |= REBASE_FORCE;
485 }
486
487 if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) {
488 strbuf_reset(&buf);
489 if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts),
490 READ_ONELINER_WARN_MISSING))
491 return -1;
492 if (!strcmp(buf.buf, "--rerere-autoupdate"))
493 opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE;
494 else if (!strcmp(buf.buf, "--no-rerere-autoupdate"))
495 opts->allow_rerere_autoupdate = RERERE_NOAUTOUPDATE;
496 else

Callers 1

cmd_rebaseFunction · 0.85

Calls 10

read_onelinerFunction · 0.85
state_dir_pathFunction · 0.85
starts_withFunction · 0.85
xstrdupFunction · 0.85
strbuf_releaseFunction · 0.85
get_oid_hexFunction · 0.85
lookup_commit_objectFunction · 0.85
errorFunction · 0.85
file_existsFunction · 0.85
warningFunction · 0.85

Tested by

no test coverage detected