git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH v7 1/5] pull: refactor fast-forward check
Date: Mon, 14 Dec 2020 12:26:43 -0800	[thread overview]
Message-ID: <20201214202647.3340193-2-gitster@pobox.com> (raw)
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


  reply	other threads:[~2020-12-14 20:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 20:26 [PATCH v7 0/5] making pull advice not to trigger when unneeded Junio C Hamano
2020-12-14 20:26 ` Junio C Hamano [this message]
2020-12-14 20:26 ` [PATCH v7 2/5] pull: give the advice for choosing rebase/merge much later Junio C Hamano
2020-12-14 20:26 ` [PATCH v7 3/5] pull: get rid of unnecessary global variable Junio C Hamano
2020-12-14 20:59   ` Felipe Contreras
2020-12-14 23:16     ` Junio C Hamano
2020-12-15  2:55       ` Felipe Contreras
2020-12-14 20:26 ` [PATCH v7 4/5] pull: correct condition to trigger non-ff advice Junio C Hamano
2020-12-14 21:17   ` Felipe Contreras
2020-12-14 23:19     ` Junio C Hamano
2020-12-15  6:35       ` Felipe Contreras
2020-12-14 20:26 ` [PATCH v7 5/5] pull: display default warning only when non-ff Junio C Hamano
2020-12-14 21:24   ` Felipe Contreras
2020-12-14 23:20     ` Junio C Hamano
2020-12-15  2:57       ` Felipe Contreras
2020-12-15  6:30 ` [PATCH v7 0/5] making pull advice not to trigger when unneeded Felipe Contreras
2020-12-15 10:58   ` Junio C Hamano
2020-12-15 12:22     ` Felipe Contreras
2020-12-18 20:46       ` Felipe Contreras
2020-12-23 10:04         ` Junio C Hamano
2020-12-23 14:10           ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201214202647.3340193-2-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).