Skip to content

Commit 77a7ec6

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a0b884 commit 77a7ec6

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

builtin/pull.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,20 @@ static int run_rebase(const struct object_id *newbase,
924924
return ret;
925925
}
926926

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+
927941
int cmd_pull(int argc, const char **argv, const char *prefix)
928942
{
929943
const char *repo, **refspecs;
@@ -1040,22 +1054,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
10401054
submodule_touches_in_range(the_repository, &upstream, &curr_head))
10411055
die(_("cannot rebase with locally recorded submodule modifications"));
10421056
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])) {
10531058
/* we can fast-forward this without invoking rebase */
10541059
opt_ff = "--ff-only";
10551060
ran_ff = 1;
10561061
ret = run_merge();
10571062
}
1058-
free_commit_list(list);
10591063
}
10601064
if (!ran_ff)
10611065
ret = run_rebase(&newbase, &upstream);

0 commit comments

Comments
 (0)