@@ -83,8 +83,13 @@ int git_revwalk__push_commit(git_revwalk *walk, const git_oid *oid, const git_re
8383
8484 commit -> uninteresting = opts -> uninteresting ;
8585 list = walk -> user_input ;
86- if ((opts -> insert_by_date &&
87- git_commit_list_insert_by_date (commit , & list ) == NULL ) ||
86+
87+ /* To insert by date, we need to parse so we know the date. */
88+ if (opts -> insert_by_date && ((error = git_commit_list_parse (walk , commit )) < 0 ))
89+ return error ;
90+
91+ if ((opts -> insert_by_date == 0 ||
92+ git_commit_list_insert_by_date (commit , & list ) == NULL ) &&
8893 git_commit_list_insert (commit , & list ) == NULL ) {
8994 git_error_set_oom ();
9095 return -1 ;
@@ -609,7 +614,7 @@ static int sort_in_topological_order(git_commit_list **out, git_revwalk *walk, g
609614static int prepare_walk (git_revwalk * walk )
610615{
611616 int error = 0 ;
612- git_commit_list * list , * commits = NULL ;
617+ git_commit_list * list , * commits = NULL , * commits_last = NULL ;
613618 git_commit_list_node * next ;
614619
615620 /* If there were no pushes, we know that the walk is already over */
@@ -618,6 +623,12 @@ static int prepare_walk(git_revwalk *walk)
618623 return GIT_ITEROVER ;
619624 }
620625
626+ /*
627+ * This is a bit convoluted, but necessary to maintain the order of
628+ * the commits. This is especially important in situations where
629+ * git_revwalk__push_glob is called with a git_revwalk__push_options
630+ * setting insert_by_date = 1, which is critical for fetch negotiation.
631+ */
621632 for (list = walk -> user_input ; list ; list = list -> next ) {
622633 git_commit_list_node * commit = list -> item ;
623634 if ((error = git_commit_list_parse (walk , commit )) < 0 )
@@ -627,8 +638,19 @@ static int prepare_walk(git_revwalk *walk)
627638 mark_parents_uninteresting (commit );
628639
629640 if (!commit -> seen ) {
641+ git_commit_list * new_list = NULL ;
642+ if ((new_list = git_commit_list_create (commit , NULL )) == NULL ) {
643+ git_error_set_oom ();
644+ return -1 ;
645+ }
646+
630647 commit -> seen = 1 ;
631- git_commit_list_insert (commit , & commits );
648+ if (commits_last == NULL )
649+ commits = new_list ;
650+ else
651+ commits_last -> next = new_list ;
652+
653+ commits_last = new_list ;
632654 }
633655 }
634656
0 commit comments