git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Ævar Arnfjörð Bjarmason  <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Denton Liu <liu.denton@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Johannes Sixt <j6t@kdbg.org>, SZEDER Gábor <szeder.dev@gmail.com>
Subject: Re: [RFC WIP PATCH v8 13/13] WIP: can_fast_forward() support for --preserve-merges and --rebase-merges
Date: Sat, 18 May 2019 00:02:24 +0200 (DST)
Message-ID: <nycvar.QRO.7.76.6.1905172316260.46@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <20190508001252.15752-14-avarab@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6434 bytes --]

Hi Ævar,

On Wed, 8 May 2019, Ævar Arnfjörð Bjarmason wrote:

> This seems to work, needs more tests etc...

I can see how it works, but it is a bit limited, and at the same time
overzealous.

The reason why we do not enter the fast-forwarding block in the
interactive case would appear to me to be that the interactive rebase
*might* want to avoid fast-forwarding e.g. with --force-rebase.

However, that is not the only instance where we must not simply
fast-forward: Think `--exec`. There might be others, too. (I just saw that
`--signoff` sets `FORCE_REBASE`, but `--exec` does not, so you cannot even
use the `FORCE_REBASE` flag as indicator.)

Since `git rebase -rx "make -j8"` is something I use myself, this here
patch would therefore break *my* workflow.

This is the "overzealous" part. Now for the "limited" part:

Let's take a step back and ask how the interactive rebase handles these
potentially fast-forwarding cases? Via `skip_unnecessary_picks()`.

And that function is ill-prepared for rebasing merges (I specifically do
*not* think about `--preserve-merges` at this point, for all I care, it is
already deprecated *and* dropped).

Even if this function *was* well-prepared for rebasing merges, I think
that would miss the mark. Take this todo list, for example:

	label onto

	# Branch dscho
	reset onto
	pick a123 first
	label dscho

	# Branch avar
	reset onto
	pick b789 second
	label avar

	reset onto
	merge -C c124 dscho
	merge -C d314 avar

Two branches, both one patch deep, both merged, one after the other. Now,
if you insert `pick abc zeroth` before the first `pick`, obviously the
first branch would no longer be skippable, but the second one totally
would be!

This is the "limited" part.

To remedy this, I think what we would need is code in `pick_commits()`,
right where `TODO_RESET` is handled (or more toward the beginning of that
function), that would:

- parse the argument (this is currently done in `do_reset()` and would
  have to be refactored out) and pretend that it is `HEAD`,

- look at the following command: if it is

	- a `pick`, and if its parent agrees with `HEAD`, pretend that
	  the `pick` was actually a `reset`, update the pretended `HEAD`
	  and keep looking at the next command,

	- a `merge`, and if its option was `-C <orig-merge>` (not
	  lower-case `-c`!), and if its parent agrees with `HEAD`, and if
	  its merge head(s) agree with the original merge commit's (if
	  any), pretend that it was actually a `reset <orig-merge>`,
	  update the pretended `HEAD` and keep looking at the next
	  command,

	- a `label`, perform it, but with the pretended `HEAD`, and keep
	  looking for the next command,

	- a `reset`, update the `done` and `git-rebase-todo` files and
	  start the entire spiel from the top,

	- otherwise perform the reset.

- all while skipping, this code would need to take care of updating the
  `done` and `git-rebase-todo` files,

- if a `reset` is necessary, and if it fails, the `done` and
  `git-rebase-todo` files should *not* be updated, but the original
  `reset` should be re-scheduled, and

- since this adds quite a bit of code, it should probably be done in a
  separate function.

Instead of marking this as a left-over bit (which I would either forget,
or whose status would be hard to track), I decided to open a ticket:

	https://github.com/gitgitgadget/git/issues/209

(I opened GitGitGadget's issues for exactly this kind of use case, because
I recently tried to find some useful left-over bits as easy project
starters, and even *I* found it super hard to find those, let alone figure
out whether they are being/have been addressed already, a mailing list is
just not a good bug tracker, even if it is still better than trying to
report a bug on Twitter, where I could not even have written this
paragraph in a single Tweet.)

Ciao,
Dscho

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/rebase.c               | 6 ++++++
>  t/t3432-rebase-fast-forward.sh | 7 +++++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 167d4fcf67..de1c5cacb8 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -892,6 +892,12 @@ static void populate_merge_bases(struct commit *head, struct commit *onto,
>
>  static int should_fast_forward(struct rebase_options *opts)
>  {
> +	if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) {
> +		if (opts->rebase_merges)
> +			return 1;
> +		if (opts->type == REBASE_PRESERVE_MERGES)
> +			return 1;
> +	}
>  	return !is_interactive(opts);
>  }
>
> diff --git a/t/t3432-rebase-fast-forward.sh b/t/t3432-rebase-fast-forward.sh
> index e8a9bf42b6..d3e1815057 100755
> --- a/t/t3432-rebase-fast-forward.sh
> +++ b/t/t3432-rebase-fast-forward.sh
> @@ -44,12 +44,13 @@ test_rebase_same_head_ () {
>  	test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
>  		oldhead=\$(git rev-parse HEAD) &&
>  		test_when_finished 'git reset --hard \$oldhead' &&
> -		git rebase$flag $* >stdout &&
> +		git rebase$flag $* >stdout 2>stderr &&
>  		if test $what = work
>  		then
>  			# Must check this case first, for 'is up to
>  			# date, rebase forced[...]rewinding head' cases
> -			test_i18ngrep 'rewinding head' stdout
> +			test_i18ngrep 'rewinding head' stdout ||
> +			test_i18ngrep 'is up to date, rebase forced' stdout
>  		elif test $what = noop
>  		then
>  			test_i18ngrep 'is up to date' stdout &&
> @@ -79,6 +80,8 @@ test_rebase_same_head success noop same success noop-force same --keep-base mast
>  test_rebase_same_head success noop same success noop-force same --keep-base
>  test_rebase_same_head success noop same success noop-force same --no-fork-point
>  test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
> +test_rebase_same_head success noop same success noop-force same --preserve-merges
> +test_rebase_same_head success noop same success noop-force same --rebase-merges
>  test_rebase_same_head success noop same success work same --fork-point master
>  test_rebase_same_head success noop same success work diff --fork-point --onto B B
>  test_rebase_same_head success noop same success work diff --fork-point --onto B... B
> --
> 2.21.0.1020.gf2820cf01a
>
>

  reply index

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-23 15:25 [PATCH 0/3] rebase: learn --keep-base Denton Liu
2019-03-23 15:25 ` [PATCH 1/3] rebase: teach rebase --keep-base Denton Liu
2019-03-24  3:46   ` Eric Sunshine
2019-03-24 13:20   ` Junio C Hamano
2019-03-25  0:06     ` Denton Liu
2019-03-25  5:41       ` Denton Liu
2019-04-01 10:45         ` Junio C Hamano
2019-03-24 13:37   ` Junio C Hamano
2019-03-25  5:47   ` Denton Liu
2019-03-25 18:50   ` Johannes Schindelin
2019-03-25 19:29     ` Denton Liu
2019-03-26 13:27       ` Johannes Schindelin
2019-03-23 15:25 ` [PATCH 2/3] t3416: test " Denton Liu
2019-03-23 15:25 ` [PATCH 3/3] git-rebase.txt: document --keep-base option Denton Liu
2019-03-24 13:15 ` [PATCH 0/3] rebase: learn --keep-base Junio C Hamano
2019-03-25  0:04   ` Denton Liu
2019-04-01 10:45     ` Junio C Hamano
2019-03-26 14:35 ` Ævar Arnfjörð Bjarmason
2019-03-26 17:50   ` Denton Liu
2019-03-26 20:35     ` Ævar Arnfjörð Bjarmason
2019-03-26 21:30       ` Denton Liu
2019-03-27 15:39         ` Ævar Arnfjörð Bjarmason
2019-03-28 22:17 ` [PATCH v2] rebase: teach rebase --keep-base Denton Liu
2019-03-28 23:13   ` Ævar Arnfjörð Bjarmason
2019-03-29 15:47   ` Johannes Schindelin
2019-03-29 17:52     ` Denton Liu
2019-04-01 10:46     ` Junio C Hamano
2019-04-01 20:51   ` [PATCH v3 0/4] " Denton Liu
2019-04-01 20:51     ` [PATCH v3 1/4] t3431: add rebase --fork-point tests Denton Liu
2019-04-04 20:28       ` Denton Liu
2019-04-05 11:15       ` SZEDER Gábor
2019-04-08  4:38         ` Junio C Hamano
2019-04-05 14:55       ` Johannes Schindelin
2019-04-05 17:25         ` Denton Liu
2019-04-05 17:51           ` Johannes Sixt
2019-04-05 18:51             ` Johannes Schindelin
2019-04-05 20:19               ` Johannes Schindelin
2019-04-05 21:10                 ` SZEDER Gábor
2019-04-01 20:51     ` [PATCH v3 2/4] t3432: test rebase fast-forward behavior Denton Liu
2019-04-01 20:52     ` [PATCH v3 3/4] rebase: fast-forward --onto in more cases Denton Liu
2019-04-02  1:25       ` Junio C Hamano
2019-04-02  1:48         ` Junio C Hamano
2019-04-02  4:44           ` Denton Liu
2019-04-01 20:52     ` [PATCH v3 4/4] rebase: teach rebase --keep-base Denton Liu
2019-04-05 21:39     ` [PATCH v4 0/4] " Denton Liu
2019-04-05 21:40       ` [PATCH v4 1/4] t3431: add rebase --fork-point tests Denton Liu
2019-04-05 21:40       ` [PATCH v4 2/4] t3432: test rebase fast-forward behavior Denton Liu
2019-04-05 21:40       ` [PATCH v4 3/4] rebase: fast-forward --onto in more cases Denton Liu
2019-04-05 21:40       ` [PATCH v4 4/4] rebase: teach rebase --keep-base Denton Liu
2019-04-15 22:29       ` [PATCH v5 0/5] " Denton Liu
2019-04-15 22:29         ` [PATCH v5 1/5] t3431: add rebase --fork-point tests Denton Liu
2019-04-15 22:29         ` [PATCH v5 2/5] t3432: test rebase fast-forward behavior Denton Liu
2019-04-15 22:29         ` [PATCH v5 3/5] rebase: fast-forward --onto in more cases Denton Liu
2019-04-16  6:26           ` Junio C Hamano
2019-04-16 13:59           ` Phillip Wood
2019-04-17  6:44             ` Denton Liu
2019-04-17 14:14               ` Phillip Wood
2019-04-19 17:08           ` Denton Liu
2019-04-15 22:29         ` [PATCH v5 4/5] rebase: fast-forward --fork-point " Denton Liu
2019-04-15 22:29         ` [PATCH v5 5/5] rebase: teach rebase --keep-base Denton Liu
2019-04-17 18:01       ` [PATCH v6 0/5] " Denton Liu
2019-04-17 18:01         ` [PATCH v6 1/6] t3431: add rebase --fork-point tests Denton Liu
2019-04-17 18:01         ` [PATCH v6 2/6] t3432: test rebase fast-forward behavior Denton Liu
2019-04-17 18:01         ` [PATCH v6 3/6] rebase: refactor can_fast_forward into goto tower Denton Liu
2019-04-17 18:01         ` [PATCH v6 4/6] rebase: fast-forward --onto in more cases Denton Liu
2019-04-17 19:59           ` Phillip Wood
2019-04-17 18:01         ` [PATCH v6 5/6] rebase: fast-forward --fork-point " Denton Liu
2019-04-17 18:01         ` [PATCH v6 6/6] rebase: teach rebase --keep-base Denton Liu
2019-04-21  8:11         ` [PATCH v7 0/6] rebase: learn --keep-base Denton Liu
2019-04-21  8:11           ` [PATCH v7 1/6] t3431: add rebase --fork-point tests Denton Liu
2019-04-23 23:12             ` Denton Liu
2019-04-21  8:11           ` [PATCH v7 2/6] t3432: test rebase fast-forward behavior Denton Liu
2019-04-21  8:11           ` [PATCH v7 3/6] rebase: refactor can_fast_forward into goto tower Denton Liu
2019-04-21  8:11           ` [PATCH v7 4/6] rebase: fast-forward --onto in more cases Denton Liu
2019-04-21  8:11           ` [PATCH v7 5/6] rebase: fast-forward --fork-point " Denton Liu
2019-04-21  8:11           ` [PATCH v7 6/6] rebase: teach rebase --keep-base Denton Liu
2019-05-08  0:12           ` [RFC WIP PATCH v8 00/13] learn --keep-base & more Ævar Arnfjörð Bjarmason
2019-05-08  3:57             ` Junio C Hamano
2019-07-19 19:14               ` Junio C Hamano
2019-07-19 21:01                 ` Denton Liu
2019-05-08  0:12           ` [RFC WIP PATCH v8 01/13] t3431: add rebase --fork-point tests Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 02/13] t3432: test rebase fast-forward behavior Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 03/13] t3432: distinguish "noop-same" v.s. "work-same" in "same head" tests Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 04/13] t3432: test for --no-ff's interaction with fast-forward Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 05/13] rebase: refactor can_fast_forward into goto tower Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 06/13] rebase: fast-forward --onto in more cases Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 07/13] rebase: fast-forward --fork-point " Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 08/13] rebase: teach rebase --keep-base Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 09/13] rebase tests: test linear branch topology Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 10/13] rebase: don't rebase linear topology with --fork-point Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 11/13] rebase: eliminate side-effects from can_fast_forward() Ævar Arnfjörð Bjarmason
2019-05-17 21:16             ` Johannes Schindelin
2019-05-08  0:12           ` [RFC WIP PATCH v8 12/13] rebase: add a should_fast_forward() utility function Ævar Arnfjörð Bjarmason
2019-05-08  0:12           ` [RFC WIP PATCH v8 13/13] WIP: can_fast_forward() support for --preserve-merges and --rebase-merges Ævar Arnfjörð Bjarmason
2019-05-17 22:02             ` Johannes Schindelin [this message]
2019-04-06 19:44     ` [PATCH v3 0/4] rebase: teach rebase --keep-base Ævar Arnfjörð Bjarmason
2019-04-06 20:38       ` Denton Liu
2019-04-13 21:10         ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publically 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=nycvar.QRO.7.76.6.1905172316260.46@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=liu.denton@gmail.com \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@gmail.com \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox