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@xxxxxx> --- On Fri, 27 Jun 2008, Johannes Schindelin wrote: > On Thu, 26 Jun 2008, Len Brown wrote: > > > it would be nice if a merge of more than 16 branches failed > > right at the start, rather than chunking along doing merges and then > > giving up, leaving my repo in an intermediate state. > > FWIW I think the rewrite of git-merge as a builtin, which is > currently in the works, lifts the limit. However, this is only true if > you do not use a custom script which calls commit-tree. And here is a patch to fix commit-tree. builtin-commit-tree.c | 43 ++++++++++++++++++++----------------------- 1 files changed, 20 insertions(+), 23 deletions(-) diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index e5e4bdb..5931a92 100644 --- a/builtin-commit-tree.c +++ b/builtin-commit-tree.c @@ -24,26 +24,20 @@ static void check_valid(unsigned char *sha1, enum object_type expect) typename(expect)); } -/* - * Having more than two parents is not strange at all, and this is - * how multi-way merges are represented. - */ -#define MAXPARENT (16) -static unsigned char parent_sha1[MAXPARENT][20]; - static const char commit_tree_usage[] = "git-commit-tree <sha1> [-p <sha1>]* < changelog"; -static int new_parent(int idx) +static void new_parent(struct commit *parent, struct commit_list **parents_p) { - int i; - unsigned char *sha1 = parent_sha1[idx]; - for (i = 0; i < idx; i++) { - if (!hashcmp(parent_sha1[i], sha1)) { + unsigned char *sha1 = parent->object.sha1; + struct commit_list *parents; + for (parents = *parents_p; parents; parents = parents->next) { + if (!hashcmp(parents->item->object.sha1, sha1)) { error("duplicate parent %s ignored", sha1_to_hex(sha1)); - return 0; + return; } + parents_p = &parents->next; } - return 1; + commit_list_insert(parent, parents_p); } static const char commit_utf8_warn[] = @@ -54,7 +48,7 @@ static const char commit_utf8_warn[] = int cmd_commit_tree(int argc, const char **argv, const char *prefix) { int i; - int parents = 0; + struct commit_list *parents = NULL; unsigned char tree_sha1[20]; unsigned char commit_sha1[20]; struct strbuf buffer; @@ -69,18 +63,16 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) check_valid(tree_sha1, OBJ_TREE); for (i = 2; i < argc; i += 2) { + unsigned char sha1[40]; const char *a, *b; a = argv[i]; b = argv[i+1]; if (!b || strcmp(a, "-p")) usage(commit_tree_usage); - if (parents >= MAXPARENT) - die("Too many parents (%d max)", MAXPARENT); - if (get_sha1(b, parent_sha1[parents])) + if (get_sha1(b, sha1)) die("Not a valid object name %s", b); - check_valid(parent_sha1[parents], OBJ_COMMIT); - if (new_parent(parents)) - parents++; + check_valid(sha1, OBJ_COMMIT); + new_parent(lookup_commit(sha1), &parents); } /* 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) * different order of parents will be a _different_ changeset even * if everything else stays the same. */ - for (i = 0; i < parents; i++) - strbuf_addf(&buffer, "parent %s\n", sha1_to_hex(parent_sha1[i])); + while (parents) { + struct commit_list *next = parents->next; + strbuf_addf(&buffer, "parent %s\n", + sha1_to_hex(parents->item->object.sha1)); + free(parents); + parents = next; + } /* Person/date information */ strbuf_addf(&buffer, "author %s\n", git_author_info(IDENT_ERROR_ON_NO_NAME)); -- 1.5.6.173.gde14c -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html