Re: [PATCH v5 1/5] rebase -i: add --ignore-whitespace flag
- From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
- Date
- Jun 29, 2020, 14:14 UTC
- Message-ID
- <20200629141453.GB20303@danh.dev>
- In-Reply-To
- <78c32f2d-3af6-1514-51a3-1110531cbb88@gmail.com>
Hi Phillip,
On 2020-06-26 15:43:00+0100, Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 31 quoted lines
> > > + if (options.type == REBASE_APPLY) {
> > > + if (ignore_whitespace)
> > > + argv_array_push (&options.git_am_opts,
> > > + "--ignore-whitespace");
> > > + } else if (ignore_whitespace) {
> > > + string_list_append (&strategy_options,
> > > + "ignore-space-change");
> > > + }
> > > +
> >
> > Hm, I've just noticed this by now.
> > Would it's better if we rewrite it as:
> >
> > if (ignore_whitespace) {
> > if (options.type == REBASE_APPLY)
> > argv_array_push(&options.git_am_opts,
> > "--ignore-whitespace");
> > else
> > string_list_append(&strategy_options,
> > "ignore-space-change");
> > }
> >
> > Ah, the incoming patches will add more conditions into the:
> >
> > if (options.type == REBASE_APPLY)
> >
> > I'm still not convinced, though.
>
> I wanted to keep the subsequent patches as simple as possible. Having to
> rewrite the if statement in the next patch just clutters it up and makes the
> real changes introduced by that patch less obviousI think the code suggested by Junio may be cleaner ;) I may write as:
if (ignore_whitespace) {
if (options.type == REBASE_APPLY)
argv_array_push(...)
else
string_list_append(...)
}if (other_condition) do_something_else(...)
I don't know if it's cleaner or not. I haven't tried applied it into real code.
Show 10 quoted lines
> > Anyway, IIRC, --ignore-whitespace and --ignore-space-change has the > > same meaning, I think it's better to use the same option for both > > legs, no? > > > > I can understand the decision to use --ignore-whitespace as keeping > > the pass-through behavior of old code, but I think future maintenance > > is more important than that. > > I'm not sure how it affects future maintenance. The two different options > are for two different commands so I'm not sure it is worth the effort
I vaguely remember I was thinking about same option text in both leg would make the code easier for reasoning. And we can unify the recommendation for both backend. We will never strip --ignore-whitespace from git-apply, but it would be easier to always answer: "--ignore-space-change should be used to ignore space" when someone asks about it.
Typing this now makes me wonder if we should teach --ignore-space-change to git-rebase?
Thanks,
-- Danh
Show 93 quoted lines
>
> Best Wishes
>
> Phillip
>
> > I've tried changing ignore-whitespace to ignore-space-change and run
> > make test
> >
> > It looks good to me (aka nothing failed _in my machine_),
> > 4/5 and 5/5 is not applied, though.
> >
> > > if (strategy_options.nr) {
> > > int i;
> > > diff --git a/t/t3422-rebase-incompatible-options.sh b/t/t3422-rebase-incompatible-options.sh
> > > index 50e7960702..55ca46786d 100755
> > > --- a/t/t3422-rebase-incompatible-options.sh
> > > +++ b/t/t3422-rebase-incompatible-options.sh
> > > @@ -61,7 +61,6 @@ test_rebase_am_only () {
> > > }
> > > test_rebase_am_only --whitespace=fix
> > > -test_rebase_am_only --ignore-whitespace
> > > test_rebase_am_only --committer-date-is-author-date
> > > test_rebase_am_only -C4
> > > diff --git a/t/t3436-rebase-more-options.sh b/t/t3436-rebase-more-options.sh
> > > new file mode 100755
> > > index 0000000000..4f8a6e51c9
> > > --- /dev/null
> > > +++ b/t/t3436-rebase-more-options.sh
> > > @@ -0,0 +1,60 @@
> > > +#!/bin/sh
> > > +#
> > > +# Copyright (c) 2019 Rohit Ashiwal
> > > +#
> > > +
> > > +test_description='tests to ensure compatibility between am and interactive backends'
> > > +
> > > +. ./test-lib.sh
> > > +
> > > +. "$TEST_DIRECTORY"/lib-rebase.sh
> > > +
> > > +# This is a special case in which both am and interactive backends
> > > +# provide the same output. It was done intentionally because
> > > +# both the backends fall short of optimal behaviour.
> > > +test_expect_success 'setup' '
> > > + git checkout -b topic &&
> > > + test_write_lines "line 1" " line 2" "line 3" >file &&
> > > + git add file &&
> > > + git commit -m "add file" &&
> > > +
> > > + test_write_lines "line 1" "new line 2" "line 3" >file &&
> > > + git commit -am "update file" &&
> > > + git tag side &&
> > > +
> > > + git checkout --orphan master &&
> > > + test_write_lines "line 1" " line 2" "line 3" >file &&
> > > + git commit -am "add file" &&
> > > + git tag main
> > > +'
> > > +
> > > +test_expect_success '--ignore-whitespace works with apply backend' '
> > > + test_must_fail git rebase --apply main side &&
> > > + git rebase --abort &&
> > > + git rebase --apply --ignore-whitespace main side &&
> > > + git diff --exit-code side
> > > +'
> > > +
> > > +test_expect_success '--ignore-whitespace works with merge backend' '
> > > + test_must_fail git rebase --merge main side &&
> > > + git rebase --abort &&
> > > + git rebase --merge --ignore-whitespace main side &&
> > > + git diff --exit-code side
> > > +'
> > > +
> > > +test_expect_success '--ignore-whitespace is remembered when continuing' '
> > > + (
> > > + set_fake_editor &&
> > > + FAKE_LINES="break 1" git rebase -i --ignore-whitespace \
> > > + main side &&
> > > + git rebase --continue
> > > + ) &&
> > > + git diff --exit-code side
> > > +'
> > > +
> > > +# This must be the last test in this file
> > > +test_expect_success '$EDITOR and friends are unchanged' '
> > > + test_editor_unchanged
> > > +'
> > > +
> > > +test_done
> > > --
> > > 2.27.0
> > >
> > -- Danh