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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jun 27, 2008 at 13:24 UTC
ef98c5cafb3e799b1568bb843fcd45920dc62f16
1 file changed
+20
-23
builtin-commit-tree.c
+20
-23
@@ -24,26 +24,20 @@ static void check_valid(unsigned char *sha1, enum object_type expect)
24
typename(expect));
25
}
26
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
-
27
static const char commit_tree_usage[] = "git-commit-tree <sha1> [-p <sha1>]* < changelog";
28
36
-static int new_parent(int idx)
29
+static void new_parent(struct commit *parent, struct commit_list **parents_p)
30
{
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) {
35
error("duplicate parent %s ignored", sha1_to_hex(sha1));
43
- return 0;
36
+ return;
37
}
38
+ parents_p = &parents->next;
39
}
46
- return 1;
40
+ commit_list_insert(parent, parents_p);
41
}
42
43
static const char commit_utf8_warn[] =
@@ -54,7 +48,7 @@ static const char commit_utf8_warn[] =
48
int cmd_commit_tree(int argc, const char **argv, const char *prefix)
49
{
50
int i;
57
- int parents = 0;
51
+ struct commit_list *parents = NULL;
52
unsigned char tree_sha1[20];
53
unsigned char commit_sha1[20];
54
struct strbuf buffer;
@@ -69,18 +63,16 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
63
64
check_valid(tree_sha1, OBJ_TREE);
65
for (i = 2; i < argc; i += 2) {
66
+ unsigned char sha1[20];
67
const char *a, *b;
68
a = argv[i]; b = argv[i+1];
69
if (!b || strcmp(a, "-p"))
70
usage(commit_tree_usage);
71
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))
73
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);
76
}
77
78
/* 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)
86
* different order of parents will be a _different_ changeset even
87
* if everything else stays the same.
88
*/
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
+ }
96
97
/* Person/date information */
98
strbuf_addf(&buffer, "author %s\n", git_author_info(IDENT_ERROR_ON_NO_NAME));