@@ -865,13 +865,9 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
865
865
struct commit_list * merge_bases = NULL ;
866
866
int res = 0 ;
867
867
868
- merge_bases = get_merge_bases (onto , head );
869
- if (!merge_bases || merge_bases -> next ) {
870
- oidcpy (branch_base , null_oid ());
871
- goto done ;
872
- }
868
+ if (is_null_oid (branch_base ))
869
+ goto done ; /* fill_branch_base() found multiple merge bases */
873
870
874
- oidcpy (branch_base , & merge_bases -> item -> object .oid );
875
871
if (!oideq (branch_base , & onto -> object .oid ))
876
872
goto done ;
877
873
@@ -881,7 +877,6 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
881
877
if (!upstream )
882
878
goto done ;
883
879
884
- free_commit_list (merge_bases );
885
880
merge_bases = get_merge_bases (upstream , head );
886
881
if (!merge_bases || merge_bases -> next )
887
882
goto done ;
@@ -896,6 +891,20 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,
896
891
return res && is_linear_history (onto , head );
897
892
}
898
893
894
+ static void fill_branch_base (struct rebase_options * options ,
895
+ struct object_id * branch_base )
896
+ {
897
+ struct commit_list * merge_bases = NULL ;
898
+
899
+ merge_bases = get_merge_bases (options -> onto , options -> orig_head );
900
+ if (!merge_bases || merge_bases -> next )
901
+ oidcpy (branch_base , null_oid ());
902
+ else
903
+ oidcpy (branch_base , & merge_bases -> item -> object .oid );
904
+
905
+ free_commit_list (merge_bases );
906
+ }
907
+
899
908
static int parse_opt_am (const struct option * opt , const char * arg , int unset )
900
909
{
901
910
struct rebase_options * opts = opt -> value ;
@@ -1660,6 +1669,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1660
1669
if (!options .onto )
1661
1670
die (_ ("Does not point to a valid commit '%s'" ),
1662
1671
options .onto_name );
1672
+ fill_branch_base (& options , & branch_base );
1663
1673
}
1664
1674
1665
1675
if (options .fork_point > 0 )
@@ -1689,13 +1699,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1689
1699
* Check if we are already based on onto with linear history,
1690
1700
* in which case we could fast-forward without replacing the commits
1691
1701
* with new commits recreated by replaying their changes.
1692
- *
1693
- * Note that can_fast_forward() initializes branch_base, so we have to
1694
- * call it before checking allow_preemptive_ff.
1695
1702
*/
1696
- if (can_fast_forward ( options . onto , options . upstream , options . restrict_revision ,
1697
- options .orig_head , & branch_base ) &&
1698
- allow_preemptive_ff ) {
1703
+ if (allow_preemptive_ff &&
1704
+ can_fast_forward ( options .onto , options . upstream , options . restrict_revision ,
1705
+ options . orig_head , & branch_base ) ) {
1699
1706
int flag ;
1700
1707
1701
1708
if (!(options .flags & REBASE_FORCE )) {
0 commit comments