git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v7 1/5] pull: refactor fast-forward check

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 14, 2020, 20:26 UTC
Message-ID
<20201214202647.3340193-2-gitster@pobox.com>
In-Reply-To
<20201214202647.3340193-1-gitster@pobox.com>
From: Felipe Contreras <felipe.contreras@gmail.com>

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>
---
 builtin/pull.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/builtin/pull.c b/builtin/pull.c
index aa56ebcdd0..03e6d53243 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -924,6 +924,20 @@ static int run_rebase(const struct object_id *newbase,
 	return ret;
 }
 
+static int get_can_ff(struct object_id *orig_head, struct object_id *orig_merge_head)
+{
+	int ret;
+	struct commit_list *list = NULL;
+	struct commit *merge_head, *head;
+
+	head = lookup_commit_reference(the_repository, orig_head);
+	commit_list_insert(head, &list);
+	merge_head = lookup_commit_reference(the_repository, orig_merge_head);
+	ret = repo_is_descendant_of(the_repository, merge_head, list);
+	free_commit_list(list);
+	return ret;
+}
+
 int cmd_pull(int argc, const char **argv, const char *prefix)
 {
 	const char *repo, **refspecs;
@@ -1040,22 +1054,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 		    submodule_touches_in_range(the_repository, &upstream, &curr_head))
 			die(_("cannot rebase with locally recorded submodule modifications"));
 		if (!autostash) {
-			struct commit_list *list = NULL;
-			struct commit *merge_head, *head;
-
-			head = lookup_commit_reference(the_repository,
-						       &orig_head);
-			commit_list_insert(head, &list);
-			merge_head = lookup_commit_reference(the_repository,
-							     &merge_heads.oid[0]);
-			if (repo_is_descendant_of(the_repository,
-						  merge_head, list)) {
+			if (get_can_ff(&orig_head, &merge_heads.oid[0])) {
 				/* we can fast-forward this without invoking rebase */
 				opt_ff = "--ff-only";
 				ran_ff = 1;
 				ret = run_merge();
 			}
-			free_commit_list(list);
 		}
 		if (!ran_ff)
 			ret = run_rebase(&newbase, &upstream);
-- 
2.30.0-rc0-186-g20447144ec
Previous: Felipe ContrerasNext: Junio C Hamano
Message 11 of 21 in “making pull advice not to trigger when unneeded”
  1. 0/5 making pull advice not to trigger when unneededJunio C Hamano, Dec 14, 2020
  2. 2/5 pull: give the advice for choosing rebase/merge much laterJunio C Hamano, Dec 14, 2020
  3. 3/5 pull: get rid of unnecessary global variableJunio C Hamano, Dec 14, 2020
  4. Felipe ContrerasDec 14, 2020
  5. Junio C HamanoDec 14, 2020
  6. Felipe ContrerasDec 15, 2020
  7. 4/5 pull: correct condition to trigger non-ff adviceJunio C Hamano, Dec 14, 2020
  8. Felipe ContrerasDec 14, 2020
  9. Junio C HamanoDec 14, 2020
  10. Felipe ContrerasDec 15, 2020
  11. 1/5 pull: refactor fast-forward checkJunio C Hamano, Dec 14, 2020
  12. 5/5 pull: display default warning only when non-ffJunio C Hamano, Dec 14, 2020
  13. Felipe ContrerasDec 14, 2020
  14. Junio C HamanoDec 14, 2020
  15. Felipe ContrerasDec 15, 2020
  16. Felipe ContrerasDec 15, 2020
  17. Junio C HamanoDec 15, 2020
  18. Felipe ContrerasDec 15, 2020
  19. Felipe ContrerasDec 18, 2020
  20. Junio C HamanoDec 23, 2020
  21. Felipe ContrerasDec 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.