MCPcopy Create free account
hub / github.com/git/git / write_commit_with_parents

Function write_commit_with_parents

builtin/stash.c:2076–2131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2074}
2075
2076static int write_commit_with_parents(struct repository *r,
2077 struct object_id *out,
2078 const struct object_id *oid,
2079 struct commit_list *parents)
2080{
2081 size_t author_len, committer_len;
2082 struct commit *this;
2083 const char *orig_author, *orig_committer;
2084 char *author = NULL, *committer = NULL;
2085 const char *buffer;
2086 unsigned long bufsize;
2087 const char *p;
2088 struct strbuf msg = STRBUF_INIT;
2089 int ret = 0;
2090 struct ident_split id;
2091
2092 this = lookup_commit_reference(r, oid);
2093 buffer = repo_get_commit_buffer(r, this, &bufsize);
2094 orig_author = find_commit_header(buffer, "author", &author_len);
2095 orig_committer = find_commit_header(buffer, "committer", &committer_len);
2096
2097 if (!orig_author || !orig_committer) {
2098 ret = error(_("cannot parse commit %s"), oid_to_hex(oid));
2099 goto out;
2100 }
2101
2102 if (split_ident_line(&id, orig_author, author_len) < 0 ||
2103 split_ident_line(&id, orig_committer, committer_len) < 0) {
2104 ret = error(_("invalid author or committer for %s"), oid_to_hex(oid));
2105 goto out;
2106 }
2107
2108 p = strstr(buffer, "\n\n");
2109 strbuf_addstr(&msg, "git stash: ");
2110
2111 if (p)
2112 strbuf_add(&msg, p + 2, bufsize - (p + 2 - buffer));
2113 strbuf_complete_line(&msg);
2114
2115 author = xmemdupz(orig_author, author_len);
2116 committer = xmemdupz(orig_committer, committer_len);
2117
2118 if (commit_tree_extended(msg.buf, msg.len,
2119 r->hash_algo->empty_tree, parents,
2120 out, author, committer,
2121 NULL, NULL)) {
2122 ret = error(_("could not write commit"));
2123 goto out;
2124 }
2125out:
2126 strbuf_release(&msg);
2127 repo_unuse_commit_buffer(r, this, buffer);
2128 free(author);
2129 free(committer);
2130 return ret;
2131}
2132
2133static int do_import_stash(struct repository *r, const char *rev)

Callers 1

do_export_stashFunction · 0.85

Calls 13

lookup_commit_referenceFunction · 0.85
repo_get_commit_bufferFunction · 0.85
find_commit_headerFunction · 0.85
errorFunction · 0.85
oid_to_hexFunction · 0.85
split_ident_lineFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addFunction · 0.85
strbuf_complete_lineFunction · 0.85
xmemdupzFunction · 0.85
commit_tree_extendedFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected