diff mbox series

[v5,1/3] pull: refactor fast-forward check

Message ID 20201210100538.696787-2-felipe.contreras@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v5,1/3] pull: refactor fast-forward check | expand

Commit Message

Felipe Contreras Dec. 10, 2020, 10:05 a.m. UTC
It's much cleaner this way.

Also, we would like to be able to make this check before the decision to
rebase is made.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/pull.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

Comments

Junio C Hamano Dec. 11, 2020, 6:54 a.m. UTC | #1
Felipe Contreras <felipe.contreras@gmail.com> writes:

> It's much cleaner this way.

It is obvious that a focused single purpose helper with less
indentation is easier to follow both at the calling site and the
implementation itself.

"It's much cleaner" is not something you need to say.

If you were making it uglier, but other benefits outweigh the
ugliness, that may deserve to be said, but that is not the case
here.

> Also, we would like to be able to make this check before the decision to
> rebase is made.

... in a future step.

That is something we want to say upfront, not "Also".

The patch itself looks quite straightforward.

Thanks.
Felipe Contreras Dec. 12, 2020, 3:18 p.m. UTC | #2
Hello,

Just to state that I'm not ignoring this feedback.

Junio C Hamano wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
> 
> > It's much cleaner this way.
> 
> It is obvious that a focused single purpose helper with less
> indentation is easier to follow both at the calling site and the
> implementation itself.

Yes, but the reader hasn't reached that point of the story yet.

> "It's much cleaner" is not something you need to say.

From the top of my head I can think of a few other reasons to refactor
code: a) it's more logical, b) it's less code, c) it's helps further
changes.

It's not necessary to say, but that's what I want to say; this reason,
and no other reason, is the main reason for this patch's existence.

> > Also, we would like to be able to make this check before the decision to
> > rebase is made.
> 
> ... in a future step.

Right.

It's not necessarily the case (could be an indeterminate future), but it
is the case in this patch series.

> That is something we want to say upfront, not "Also".

Not from my point of view. Even if it didn't help in future steps,
cleaning up code is generally desirable.

Cheers.
diff mbox series

Patch

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);