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

Function convert_commit_object

object-file-convert.c:150–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150static int convert_commit_object(struct repository *repo,
151 struct strbuf *out,
152 const struct git_hash_algo *from,
153 const struct git_hash_algo *to,
154 const char *buffer, size_t size)
155{
156 const char *tail = buffer;
157 const char *bufptr = buffer;
158 const int tree_entry_len = from->hexsz + 5;
159 const int parent_entry_len = from->hexsz + 7;
160 struct object_id oid, mapped_oid;
161 const char *p, *eol;
162
163 tail += size;
164
165 while ((bufptr < tail) && (*bufptr != '\n')) {
166 eol = memchr(bufptr, '\n', tail - bufptr);
167 if (!eol)
168 return error(_("bad %s in commit"), "line");
169
170 if (((bufptr + 5) < eol) && !memcmp(bufptr, "tree ", 5))
171 {
172 if (((bufptr + tree_entry_len) != eol) ||
173 parse_oid_hex_algop(bufptr + 5, &oid, &p, from) ||
174 (p != eol))
175 return error(_("bad %s in commit"), "tree");
176
177 if (repo_oid_to_algop(repo, &oid, to, &mapped_oid))
178 return error(_("unable to map %s %s in commit object"),
179 "tree", oid_to_hex(&oid));
180 strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid));
181 }
182 else if (((bufptr + 7) < eol) && !memcmp(bufptr, "parent ", 7))
183 {
184 if (((bufptr + parent_entry_len) != eol) ||
185 parse_oid_hex_algop(bufptr + 7, &oid, &p, from) ||
186 (p != eol))
187 return error(_("bad %s in commit"), "parent");
188
189 if (repo_oid_to_algop(repo, &oid, to, &mapped_oid))
190 return error(_("unable to map %s %s in commit object"),
191 "parent", oid_to_hex(&oid));
192
193 strbuf_addf(out, "parent %s\n", oid_to_hex(&mapped_oid));
194 }
195 else if (((bufptr + 9) < eol) && !memcmp(bufptr, "mergetag ", 9))
196 {
197 struct strbuf tag = STRBUF_INIT, new_tag = STRBUF_INIT;
198
199 /* Recover the tag object from the mergetag */
200 strbuf_add(&tag, bufptr + 9, (eol - (bufptr + 9)) + 1);
201
202 bufptr = eol + 1;
203 while ((bufptr < tail) && (*bufptr == ' ')) {
204 eol = memchr(bufptr, '\n', tail - bufptr);
205 if (!eol) {
206 strbuf_release(&tag);
207 return error(_("bad %s in commit"), "mergetag continuation");

Callers 1

convert_object_fileFunction · 0.85

Calls 9

errorFunction · 0.85
repo_oid_to_algopFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addFunction · 0.85
strbuf_releaseFunction · 0.85
convert_tag_objectFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_add_linesFunction · 0.85

Tested by

no test coverage detected