Skip to content

Commit a3e8ae5

Browse files
ebiedermgitster
authored andcommitted
commit: convert mergetag before computing the signature of a commit
It so happens that commit mergetag lines embed a tag object. So to compute the compatible signature of a commit object that has mergetag lines the compatible embedded tag must be computed first. Implement this by duplicating and converting the commit extra headers into the compatible version of the commit extra headers, that need to be passed to commit_tree_extended. To handle merge tags only the compatible extra headers need to be computed. Signed-off-by: Eric W. Biederman <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6206089 commit a3e8ae5

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

commit.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,39 @@ void append_merge_tag_headers(struct commit_list *parents,
13551355
}
13561356
}
13571357

1358+
static int convert_commit_extra_headers(struct commit_extra_header *orig,
1359+
struct commit_extra_header **result)
1360+
{
1361+
const struct git_hash_algo *compat = the_repository->compat_hash_algo;
1362+
const struct git_hash_algo *algo = the_repository->hash_algo;
1363+
struct commit_extra_header *extra = NULL, **tail = &extra;
1364+
struct strbuf out = STRBUF_INIT;
1365+
while (orig) {
1366+
struct commit_extra_header *new;
1367+
CALLOC_ARRAY(new, 1);
1368+
if (!strcmp(orig->key, "mergetag")) {
1369+
if (convert_object_file(&out, algo, compat,
1370+
orig->value, orig->len,
1371+
OBJ_TAG, 1)) {
1372+
free(new);
1373+
free_commit_extra_headers(extra);
1374+
return -1;
1375+
}
1376+
new->key = xstrdup("mergetag");
1377+
new->value = strbuf_detach(&out, &new->len);
1378+
} else {
1379+
new->key = xstrdup(orig->key);
1380+
new->len = orig->len;
1381+
new->value = xmemdupz(orig->value, orig->len);
1382+
}
1383+
*tail = new;
1384+
tail = &new->next;
1385+
orig = orig->next;
1386+
}
1387+
*result = extra;
1388+
return 0;
1389+
}
1390+
13581391
static void add_extra_header(struct strbuf *buffer,
13591392
struct commit_extra_header *extra)
13601393
{
@@ -1679,6 +1712,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
16791712
goto out;
16801713
}
16811714
if (r->compat_hash_algo) {
1715+
struct commit_extra_header *compat_extra = NULL;
16821716
struct object_id mapped_tree;
16831717
struct object_id *mapped_parents;
16841718

@@ -1695,8 +1729,14 @@ int commit_tree_extended(const char *msg, size_t msg_len,
16951729
free(mapped_parents);
16961730
goto out;
16971731
}
1732+
if (convert_commit_extra_headers(extra, &compat_extra)) {
1733+
result = -1;
1734+
free(mapped_parents);
1735+
goto out;
1736+
}
16981737
write_commit_tree(&compat_buffer, msg, msg_len, &mapped_tree,
1699-
mapped_parents, nparents, author, committer, extra);
1738+
mapped_parents, nparents, author, committer, compat_extra);
1739+
free_commit_extra_headers(compat_extra);
17001740
free(mapped_parents);
17011741

17021742
if (sign_commit && sign_commit_to_strbuf(&compat_sig, &compat_buffer, sign_commit)) {

0 commit comments

Comments
 (0)