Skip to content

Commit ef98c5c

Browse files
dschogitster
authored andcommitted
commit-tree: lift completely arbitrary limit of 16 parents
There is no really good reason to have a merge with more than 16 parents, but we have a history of giving our users rope. Combined with the fact that there was no good reason for that arbitrary limit in the first place, here is an all-too-easy to fix. Kind of wished-for by Len Brown. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b8e6f8 commit ef98c5c

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

builtin-commit-tree.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,20 @@ static void check_valid(unsigned char *sha1, enum object_type expect)
2424
typename(expect));
2525
}
2626

27-
/*
28-
* Having more than two parents is not strange at all, and this is
29-
* how multi-way merges are represented.
30-
*/
31-
#define MAXPARENT (16)
32-
static unsigned char parent_sha1[MAXPARENT][20];
33-
3427
static const char commit_tree_usage[] = "git-commit-tree <sha1> [-p <sha1>]* < changelog";
3528

36-
static int new_parent(int idx)
29+
static void new_parent(struct commit *parent, struct commit_list **parents_p)
3730
{
38-
int i;
39-
unsigned char *sha1 = parent_sha1[idx];
40-
for (i = 0; i < idx; i++) {
41-
if (!hashcmp(parent_sha1[i], sha1)) {
31+
unsigned char *sha1 = parent->object.sha1;
32+
struct commit_list *parents;
33+
for (parents = *parents_p; parents; parents = parents->next) {
34+
if (parents->item == parent) {
4235
error("duplicate parent %s ignored", sha1_to_hex(sha1));
43-
return 0;
36+
return;
4437
}
38+
parents_p = &parents->next;
4539
}
46-
return 1;
40+
commit_list_insert(parent, parents_p);
4741
}
4842

4943
static const char commit_utf8_warn[] =
@@ -54,7 +48,7 @@ static const char commit_utf8_warn[] =
5448
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
5549
{
5650
int i;
57-
int parents = 0;
51+
struct commit_list *parents = NULL;
5852
unsigned char tree_sha1[20];
5953
unsigned char commit_sha1[20];
6054
struct strbuf buffer;
@@ -69,18 +63,16 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
6963

7064
check_valid(tree_sha1, OBJ_TREE);
7165
for (i = 2; i < argc; i += 2) {
66+
unsigned char sha1[20];
7267
const char *a, *b;
7368
a = argv[i]; b = argv[i+1];
7469
if (!b || strcmp(a, "-p"))
7570
usage(commit_tree_usage);
7671

77-
if (parents >= MAXPARENT)
78-
die("Too many parents (%d max)", MAXPARENT);
79-
if (get_sha1(b, parent_sha1[parents]))
72+
if (get_sha1(b, sha1))
8073
die("Not a valid object name %s", b);
81-
check_valid(parent_sha1[parents], OBJ_COMMIT);
82-
if (new_parent(parents))
83-
parents++;
74+
check_valid(sha1, OBJ_COMMIT);
75+
new_parent(lookup_commit(sha1), &parents);
8476
}
8577

8678
/* Not having i18n.commitencoding is the same as having utf-8 */
@@ -94,8 +86,13 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
9486
* different order of parents will be a _different_ changeset even
9587
* if everything else stays the same.
9688
*/
97-
for (i = 0; i < parents; i++)
98-
strbuf_addf(&buffer, "parent %s\n", sha1_to_hex(parent_sha1[i]));
89+
while (parents) {
90+
struct commit_list *next = parents->next;
91+
strbuf_addf(&buffer, "parent %s\n",
92+
sha1_to_hex(parents->item->object.sha1));
93+
free(parents);
94+
parents = next;
95+
}
9996

10097
/* Person/date information */
10198
strbuf_addf(&buffer, "author %s\n", git_author_info(IDENT_ERROR_ON_NO_NAME));

0 commit comments

Comments
 (0)