pull: refactor fast-forward check
We would like to be able to make this check before the decision to rebase is made in a future step. Besides, using a separate helper makes the code easier to follow. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Dec 12, 2020 at 10:52 UTC
77a7ec632952ee335cb544fee7c6b3fb1c5ec147
1 file changed
+15
-11
builtin/pull.c
+15
-11
@@ -924,6 +924,20 @@ static int run_rebase(const struct object_id *newbase,
924
return ret;
925
}
926
927
+static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_head)
928
+{
929
+ int ret;
930
+ struct commit_list *list = NULL;
931
+ struct commit *merge_head, *head;
932
+
933
+ head = lookup_commit_reference(the_repository, orig_head);
934
+ commit_list_insert(head, &list);
935
+ merge_head = lookup_commit_reference(the_repository, orig_merge_head);
936
+ ret = repo_is_descendant_of(the_repository, merge_head, list);
937
+ free_commit_list(list);
938
+ return ret;
939
+}
940
+
941
int cmd_pull(int argc, const char **argv, const char *prefix)
942
{
943
const char *repo, **refspecs;
@@ -1040,22 +1054,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
1054
submodule_touches_in_range(the_repository, &upstream, &curr_head))
1055
die(_("cannot rebase with locally recorded submodule modifications"));
1056
if (!autostash) {
1043
- struct commit_list *list = NULL;
1044
- struct commit *merge_head, *head;
1045
-
1046
- head = lookup_commit_reference(the_repository,
1047
- &orig_head);
1048
- commit_list_insert(head, &list);
1049
- merge_head = lookup_commit_reference(the_repository,
1050
- &merge_heads.oid[0]);
1051
- if (repo_is_descendant_of(the_repository,
1052
- merge_head, list)) {
1057
+ if (get_can_ff(&orig_head, &merge_heads.oid[0])) {
1058
/* we can fast-forward this without invoking rebase */
1059
opt_ff = "--ff-only";
1060
ran_ff = 1;
1061
ret = run_merge();
1062
}
1058
- free_commit_list(list);
1063
}
1064
if (!ran_ff)
1065
ret = run_rebase(&newbase, &upstream);