From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Alex Henrie <alexhenrie24@gmail.com>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
John Keeping <john@keeping.me.uk>,
Richard Hansen <rhansen@rhansen.org>,
Philip Oakley <philipoakley@iee.email>,
"Brian M. Carlson" <sandals@crustytoothpaste.net>,
"W. Trevor King" <wking@tremily.us>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v8 01/10] pull: refactor fast-forward check
Date: Tue, 24 Nov 2020 21:29:29 -0600 [thread overview]
Message-ID: <20201125032938.786393-2-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20201125032938.786393-1-felipe.contreras@gmail.com>
This way we will be able to do the check unconditionally (merge or
rebase).
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
builtin/pull.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/builtin/pull.c b/builtin/pull.c
index 17aa63cd35..e2de0d4c91 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -906,6 +906,20 @@ static int run_rebase(const struct object_id *curr_head,
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;
@@ -1016,22 +1030,12 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
submodule_touches_in_range(the_repository, &rebase_fork_point, &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(&curr_head, merge_heads.oid, &rebase_fork_point);
--
2.29.2
next prev parent reply other threads:[~2020-11-25 3:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-25 3:29 [PATCH v8 00/10] Reject non-ff pulls by default Felipe Contreras
2020-11-25 3:29 ` Felipe Contreras [this message]
2020-11-25 3:29 ` [PATCH v8 02/10] pull: cleanup autostash check Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 03/10] pull: trivial cleanup Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 04/10] pull: move default warning Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 05/10] pull: display default warning only when non-ff Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 06/10] test: pull-options: revert unnecessary changes Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 07/10] rebase: add REBASE_DEFAULT Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 08/10] pull: add pull.mode Felipe Contreras
2020-11-25 12:31 ` Philip Oakley
2020-12-02 5:04 ` Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 09/10] pull: add pull.mode=ff-only Felipe Contreras
2020-11-25 3:29 ` [PATCH v8 10/10] pull: improve default warning 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=20201125032938.786393-2-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=alexhenrie24@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=john@keeping.me.uk \
--cc=newren@gmail.com \
--cc=peff@peff.net \
--cc=philipoakley@iee.email \
--cc=rhansen@rhansen.org \
--cc=sandals@crustytoothpaste.net \
--cc=wking@tremily.us \
/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).