@@ -1642,7 +1642,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16421642 const char * index_file , * reflog_msg ;
16431643 char * nl ;
16441644 unsigned char sha1 [20 ];
1645- struct commit_list * parents = NULL , * * pptr = & parents ;
1645+ struct commit_list * parents = NULL ;
16461646 struct stat statbuf ;
16471647 struct commit * current_head = NULL ;
16481648 struct commit_extra_header * extra = NULL ;
@@ -1688,20 +1688,18 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16881688 if (!reflog_msg )
16891689 reflog_msg = "commit (initial)" ;
16901690 } else if (amend ) {
1691- struct commit_list * c ;
1692-
16931691 if (!reflog_msg )
16941692 reflog_msg = "commit (amend)" ;
1695- for (c = current_head -> parents ; c ; c = c -> next )
1696- pptr = & commit_list_insert (c -> item , pptr )-> next ;
1693+ parents = copy_commit_list (current_head -> parents );
16971694 } else if (whence == FROM_MERGE ) {
16981695 struct strbuf m = STRBUF_INIT ;
16991696 FILE * fp ;
17001697 int allow_fast_forward = 1 ;
1698+ struct commit_list * * pptr = & parents ;
17011699
17021700 if (!reflog_msg )
17031701 reflog_msg = "commit (merge)" ;
1704- pptr = & commit_list_insert (current_head , pptr )-> next ;
1702+ pptr = commit_list_append (current_head , pptr );
17051703 fp = fopen (git_path_merge_head (), "r" );
17061704 if (fp == NULL )
17071705 die_errno (_ ("could not open '%s' for reading" ),
@@ -1712,7 +1710,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17121710 parent = get_merge_parent (m .buf );
17131711 if (!parent )
17141712 die (_ ("Corrupt MERGE_HEAD file (%s)" ), m .buf );
1715- pptr = & commit_list_insert (parent , pptr )-> next ;
1713+ pptr = commit_list_append (parent , pptr );
17161714 }
17171715 fclose (fp );
17181716 strbuf_release (& m );
@@ -1729,7 +1727,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17291727 reflog_msg = (whence == FROM_CHERRY_PICK )
17301728 ? "commit (cherry-pick)"
17311729 : "commit" ;
1732- pptr = & commit_list_insert (current_head , pptr ) -> next ;
1730+ commit_list_insert (current_head , & parents ) ;
17331731 }
17341732
17351733 /* Finally, get the commit message */
0 commit comments