| 148 | } |
| 149 | |
| 150 | static 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"); |
no test coverage detected