@@ -24,26 +24,20 @@ static void check_valid(unsigned char *sha1, enum object_type expect)
24
24
typename (expect ));
25
25
}
26
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
-
34
27
static const char commit_tree_usage [] = "git-commit-tree <sha1> [-p <sha1>]* < changelog" ;
35
28
36
- static int new_parent (int idx )
29
+ static void new_parent (struct commit * parent , struct commit_list * * parents_p )
37
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 ) {
42
35
error ("duplicate parent %s ignored" , sha1_to_hex (sha1 ));
43
- return 0 ;
36
+ return ;
44
37
}
38
+ parents_p = & parents -> next ;
45
39
}
46
- return 1 ;
40
+ commit_list_insert ( parent , parents_p ) ;
47
41
}
48
42
49
43
static const char commit_utf8_warn [] =
@@ -54,7 +48,7 @@ static const char commit_utf8_warn[] =
54
48
int cmd_commit_tree (int argc , const char * * argv , const char * prefix )
55
49
{
56
50
int i ;
57
- int parents = 0 ;
51
+ struct commit_list * parents = NULL ;
58
52
unsigned char tree_sha1 [20 ];
59
53
unsigned char commit_sha1 [20 ];
60
54
struct strbuf buffer ;
@@ -69,18 +63,16 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
69
63
70
64
check_valid (tree_sha1 , OBJ_TREE );
71
65
for (i = 2 ; i < argc ; i += 2 ) {
66
+ unsigned char sha1 [20 ];
72
67
const char * a , * b ;
73
68
a = argv [i ]; b = argv [i + 1 ];
74
69
if (!b || strcmp (a , "-p" ))
75
70
usage (commit_tree_usage );
76
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 ))
80
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 );
84
76
}
85
77
86
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)
94
86
* different order of parents will be a _different_ changeset even
95
87
* if everything else stays the same.
96
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
+ }
99
96
100
97
/* Person/date information */
101
98
strbuf_addf (& buffer , "author %s\n" , git_author_info (IDENT_ERROR_ON_NO_NAME ));
0 commit comments