From ef98c5cafb3e799b1568bb843fcd45920dc62f16 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 27 Jun 2008 13:24:47 +0100 Subject: [PATCH] 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 Signed-off-by: Junio C Hamano --- builtin-commit-tree.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index e5e4bdbe8..3881f6c2f 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 [-p ]* < 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 (parents->item == parent) { 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[20]; 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)); -- 2.26.2