git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: John Cai <johncai86@gmail.com>
Cc: git@vger.kernel.org, "Tilman Vogel" <tilman.vogel@web.de>,
	"Philippe Blain" <levraiphilippeblain@gmail.com>
Subject: Re: [PATCH 1/1] builtin/pull.c: use config value of autostash
Date: Tue, 04 Jan 2022 14:46:50 -0800	[thread overview]
Message-ID: <xmqqbl0r9l0l.fsf@gitster.g> (raw)
In-Reply-To: <20220104214522.10692-2-johncai86@gmail.com> (John Cai's message of "Tue, 4 Jan 2022 16:45:22 -0500")

John Cai <johncai86@gmail.com> writes:

> diff --git a/builtin/pull.c b/builtin/pull.c
> index 100cbf9fb8..fb700c2d39 100644
> --- a/builtin/pull.c
> +++ b/builtin/pull.c
> @@ -86,7 +86,8 @@ static char *opt_ff;
>  static char *opt_verify_signatures;
>  static char *opt_verify;
>  static int opt_autostash = -1;
> -static int config_autostash;
> +static int rebase_autostash = 0;
> +static int cfg_rebase_autostash;

Do not explicitly initialize statics to '0' (or NULL for that matter).

But more importantly, I have a feeling that you are making a piece
of code that is already hard to read impossible to follow by adding
yet another variable.

> diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
> index 66cfcb09c5..28f551db8e 100755
> --- a/t/t5521-pull-options.sh
> +++ b/t/t5521-pull-options.sh
> @@ -251,5 +251,56 @@ test_expect_success 'git pull --no-verify --verify passed to merge' '
>  	test_commit -C src two &&
>  	test_must_fail git -C dst pull --no-ff --no-verify --verify
>  '
> +test_expect_success 'git pull --rebase --autostash succeeds on ff' '

Missing blank line between tests.


I thought that the root cause of the problem is that run_merge() is
called even when rebase was asked for (either via pull.rebase=true
configuration or "pull --rebase" option), when the other side is a
descendant of HEAD.  The basic idea behind that behaviour may be
sound (i.e. if we do not have any of our own development on top of
their history, rebase vs merge shouldn't make any difference while
fast-forwarding HEAD to their history), except that rebase vs merge
look at different configuration variables.

I wonder if the following two-liner patch is a simpler fix that is
easier to understand.  run_merge() decides if we should pass the
"--[no-]autostash" option based on the value of opt_autostash, and
we know the value of rebase.autostash in config_autostash variable.

It appears to pass all four tests your patch adds.

 builtin/pull.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git c/builtin/pull.c w/builtin/pull.c
index 100cbf9fb8..d459a91a64 100644
--- c/builtin/pull.c
+++ w/builtin/pull.c
@@ -1133,7 +1133,14 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			die(_("cannot rebase with locally recorded submodule modifications"));
 
 		if (can_ff) {
-			/* we can fast-forward this without invoking rebase */
+			/*
+			 * We can fast-forward without invoking
+			 * rebase, by calling run_merge().  But we
+			 * have to allow rebase.autostash=true to kick
+			 * in.
+			 */
+			if (opt_autostash < 0)
+				opt_autostash = config_autostash;
 			opt_ff = "--ff-only";
 			ret = run_merge();
 		} else {

  reply	other threads:[~2022-01-04 22:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04 21:45 [PATCH 0/1] Fix bug in pull --rebase not recognizing rebase.autostash John Cai
2022-01-04 21:45 ` [PATCH 1/1] builtin/pull.c: use config value of autostash John Cai
2022-01-04 22:46   ` Junio C Hamano [this message]
2022-01-05  3:58     ` Philippe Blain
2022-01-06 19:11       ` Junio C Hamano
2022-01-14  0:00         ` Junio C Hamano
2022-01-14  3:14           ` Philippe Blain
2022-01-14 14:09             ` John Cai
2022-01-14 19:40             ` Junio C Hamano
2022-01-14 23:33               ` Philippe Blain
2022-01-05 11:21     ` Phillip Wood
2022-01-05  3:40   ` Philippe Blain
2022-01-05  4:02     ` Philippe Blain
2022-01-05 15:50   ` Johannes Schindelin
2022-01-04 23:32 ` [PATCH 0/1] Fix bug in pull --rebase not recognizing rebase.autostash Philippe Blain

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqbl0r9l0l.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=johncai86@gmail.com \
    --cc=levraiphilippeblain@gmail.com \
    --cc=tilman.vogel@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).