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

Function do_commit

builtin/am.c:1666–1733  ·  view source on GitHub ↗

* Commits the current index with state->msg as the commit message and * state->author_name, state->author_email and state->author_date as the author * information. */

Source from the content-addressed store, hash-verified

1664 * information.
1665 */
1666static void do_commit(const struct am_state *state)
1667{
1668 struct object_id tree, parent, commit;
1669 const struct object_id *old_oid;
1670 struct commit_list *parents = NULL;
1671 const char *reflog_msg, *author, *committer = NULL;
1672 struct strbuf sb = STRBUF_INIT;
1673
1674 if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
1675 exit(1);
1676
1677 if (write_index_as_tree(&tree, the_repository->index,
1678 repo_get_index_file(the_repository),
1679 0, NULL))
1680 die(_("git write-tree failed to write a tree"));
1681
1682 if (!repo_get_oid_commit(the_repository, "HEAD", &parent)) {
1683 old_oid = &parent;
1684 commit_list_insert(lookup_commit(the_repository, &parent),
1685 &parents);
1686 } else {
1687 old_oid = NULL;
1688 say(state, stderr, _("applying to an empty history"));
1689 }
1690
1691 author = fmt_ident(state->author_name, state->author_email,
1692 WANT_AUTHOR_IDENT,
1693 state->ignore_date ? NULL : state->author_date,
1694 IDENT_STRICT);
1695
1696 if (state->committer_date_is_author_date)
1697 committer = fmt_ident(getenv("GIT_COMMITTER_NAME"),
1698 getenv("GIT_COMMITTER_EMAIL"),
1699 WANT_COMMITTER_IDENT,
1700 state->ignore_date ? NULL
1701 : state->author_date,
1702 IDENT_STRICT);
1703
1704 if (commit_tree_extended(state->msg, state->msg_len, &tree, parents,
1705 &commit, author, committer, state->sign_commit,
1706 NULL))
1707 die(_("failed to write commit object"));
1708
1709 reflog_msg = getenv("GIT_REFLOG_ACTION");
1710 if (!reflog_msg)
1711 reflog_msg = "am";
1712
1713 strbuf_addf(&sb, "%s: %.*s", reflog_msg, linelen(state->msg),
1714 state->msg);
1715
1716 refs_update_ref(get_main_ref_store(the_repository), sb.buf, "HEAD",
1717 &commit, old_oid, 0,
1718 UPDATE_REFS_DIE_ON_ERR);
1719
1720 if (state->rebasing) {
1721 FILE *fp = xfopen(am_path(state, "rewritten"), "a");
1722
1723 assert(!is_null_oid(&state->orig_commit));

Callers 2

am_runFunction · 0.70
am_resolveFunction · 0.70

Calls 15

run_hooksFunction · 0.85
write_index_as_treeFunction · 0.85
repo_get_index_fileFunction · 0.85
repo_get_oid_commitFunction · 0.85
commit_list_insertFunction · 0.85
lookup_commitFunction · 0.85
sayFunction · 0.85
fmt_identFunction · 0.85
commit_tree_extendedFunction · 0.85
strbuf_addfFunction · 0.85
refs_update_refFunction · 0.85
get_main_ref_storeFunction · 0.85

Tested by

no test coverage detected