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

Function create_commit

replay.c:80–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80static struct commit *create_commit(struct repository *repo,
81 struct tree *tree,
82 struct commit *based_on,
83 struct commit *parent,
84 enum replay_mode mode)
85{
86 struct object_id ret;
87 struct object *obj = NULL;
88 struct commit_list *parents = NULL;
89 char *author = NULL;
90 char *sign_commit = NULL; /* FIXME: cli users might want to sign again */
91 struct commit_extra_header *extra = NULL;
92 struct strbuf msg = STRBUF_INIT;
93 const char *out_enc = get_commit_output_encoding();
94 const char *message = repo_logmsg_reencode(repo, based_on,
95 NULL, out_enc);
96 const char *orig_message = NULL;
97 const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
98
99 commit_list_insert(parent, &parents);
100 extra = read_commit_extra_headers(based_on, exclude_gpgsig);
101 if (mode == REPLAY_MODE_REVERT) {
102 generate_revert_message(&msg, based_on, repo);
103 /* For revert, use current user as author (NULL = use default) */
104 } else if (mode == REPLAY_MODE_PICK) {
105 find_commit_subject(message, &orig_message);
106 strbuf_addstr(&msg, orig_message);
107 author = get_author(message);
108 } else {
109 BUG("unexpected replay mode %d", mode);
110 }
111 reset_ident_date();
112 if (commit_tree_extended(msg.buf, msg.len, &tree->object.oid, parents,
113 &ret, author, NULL, sign_commit, extra)) {
114 error(_("failed to write commit object"));
115 goto out;
116 }
117
118 obj = parse_object(repo, &ret);
119
120out:
121 repo_unuse_commit_buffer(repo, based_on, message);
122 free_commit_extra_headers(extra);
123 commit_list_free(parents);
124 strbuf_release(&msg);
125 free(author);
126 return (struct commit *)obj;
127}
128
129struct ref_info {
130 struct commit *onto;

Callers 1

pick_regular_commitFunction · 0.85

Calls 15

repo_logmsg_reencodeFunction · 0.85
commit_list_insertFunction · 0.85
generate_revert_messageFunction · 0.85
find_commit_subjectFunction · 0.85
strbuf_addstrFunction · 0.85
reset_ident_dateFunction · 0.85
commit_tree_extendedFunction · 0.85
errorFunction · 0.85
parse_objectFunction · 0.85
repo_unuse_commit_bufferFunction · 0.85

Tested by

no test coverage detected