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

Function try_to_commit

sequencer.c:1529–1709  ·  view source on GitHub ↗

* Try to commit without forking 'git commit'. In some cases we need * to run 'git commit' to display an error message * * Returns: * -1 - error unable to commit * 0 - success * 1 - run 'git commit' */

Source from the content-addressed store, hash-verified

1527 * 1 - run 'git commit'
1528 */
1529static int try_to_commit(struct repository *r,
1530 struct strbuf *msg, const char *author,
1531 const char *reflog_action,
1532 struct replay_opts *opts, unsigned int flags,
1533 struct object_id *oid)
1534{
1535 struct object_id tree;
1536 struct commit *current_head = NULL;
1537 struct commit_list *parents = NULL;
1538 struct commit_extra_header *extra = NULL;
1539 struct strbuf err = STRBUF_INIT;
1540 struct strbuf commit_msg = STRBUF_INIT;
1541 char *amend_author = NULL;
1542 const char *committer = NULL;
1543 const char *hook_commit = NULL;
1544 enum commit_msg_cleanup_mode cleanup;
1545 int res = 0;
1546
1547 if (parse_head(r, &current_head))
1548 return -1;
1549
1550 if (flags & AMEND_MSG) {
1551 const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
1552 const char *out_enc = get_commit_output_encoding();
1553 const char *message = repo_logmsg_reencode(r, current_head,
1554 NULL, out_enc);
1555
1556 if (!msg) {
1557 const char *orig_message = NULL;
1558
1559 find_commit_subject(message, &orig_message);
1560 msg = &commit_msg;
1561 strbuf_addstr(msg, orig_message);
1562 hook_commit = "HEAD";
1563 }
1564 author = amend_author = get_author(message);
1565 repo_unuse_commit_buffer(r, current_head,
1566 message);
1567 if (!author) {
1568 res = error(_("unable to parse commit author"));
1569 goto out;
1570 }
1571 parents = commit_list_copy(current_head->parents);
1572 extra = read_commit_extra_headers(current_head, exclude_gpgsig);
1573 } else if (current_head &&
1574 (!(flags & CREATE_ROOT_COMMIT) || (flags & AMEND_MSG))) {
1575 commit_list_insert(current_head, &parents);
1576 }
1577
1578 if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) {
1579 res = error(_("git write-tree failed to write a tree"));
1580 goto out;
1581 }
1582
1583 if (!(flags & ALLOW_EMPTY)) {
1584 struct commit *first_parent = current_head;
1585
1586 if (flags & AMEND_MSG) {

Callers 1

do_commitFunction · 0.85

Calls 15

parse_headFunction · 0.85
repo_logmsg_reencodeFunction · 0.85
find_commit_subjectFunction · 0.85
strbuf_addstrFunction · 0.85
repo_unuse_commit_bufferFunction · 0.85
errorFunction · 0.85
commit_list_copyFunction · 0.85
commit_list_insertFunction · 0.85
write_index_as_treeFunction · 0.85
repo_parse_commitFunction · 0.85

Tested by

no test coverage detected