git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rubén Justo" <rjusto@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH 2/5] apply: honor `ignore_ws_none` with `correct_ws_error`
Date: Wed, 4 Sep 2024 20:20:37 +0200	[thread overview]
Message-ID: <f3f863da-50bd-41e3-981c-df93ae771d24@gmail.com> (raw)
In-Reply-To: <xmqqseugdo90.fsf@gitster.g>

On Tue, Sep 03, 2024 at 09:41:31PM -0700, Junio C Hamano wrote:

> ... a new "silent-fix" that makes
> corrections in the same way as "fix" (or "strip"), but wihtout
> giving any warnings.

My main intention is not to make "fix" quieter, although it will
probably be a pleasant consequence.

Let's consider a sequence of patches where some whitespace errors in
one patch are carried over to the next:
    
    $ # underscore (_) is whitespace for readability
    $ cat >file <<END
    a
    END
    $ cat >patch1 <<END # this adds a whitespace error
    --- v/file
    +++ m/file
    @@ -1 +1,2 @@
     a
    +b_
    END
    $ cat >patch2 <<END # this adds another one
    --- v/file
    +++ m/file
    @@ -1,2 +1,3 @@
     a
     b_
    +c_
    END

When applying "patch1" with `--whitespace=fix`, we'll fix the
whitespace error in "b ".  Consequently, when applying "patch2" we'll
need to fix that line in the patch before applying it, so that it
matches the context line, now with "b".  Makes sense.

This applies not only to:

    $ git apply --whitespace=fix patch1 && \
      git apply --whitespace=fix patch2
    
But to:

    $ git apply --whitespace=fix patch1 patch2
    
Even to:

    $ git apply --whitespace=fix <(cat patch1 patch2)

So far, so good.

However, a legit question is: Why "a " is being modified here?:

    $ cat >foo <<END
    a_
    b_
    END
    $ cat >patch <<END
    --- v/foo
    +++ m/foo
    @@ -1,2 +1,2 @@
     a
    -b_
    +b
    END
    $ git apply -v --whitespace=fix patch
    Checking patch foo...
    Applied patch foo cleanly.
    $ xxd foo
    00000000: 610a                                     a.

Is this a bug?  I don't think so.  But the result, IMHO, is
questionable, and "git apply" rejecting the patch could also be an
expected outcome.

We are assuming an implicit, and perhaps unwanted, step:

    --- v/foo
    +++ m/foo
    @@ -1,2 +1,2 @@
    -a_
    +a
     b_
    END

We cannot change the default behaviour (I won't dig into this), but I
think we can give a knob to allow changing it.  This is the main
intention of the, ugly, new "_default" enum value.

And... as a nice side effect, we'll know when to stop showing warnings
when the user touches lines next to other lines with whitespace errors
that they don't want, or can, change ;-)

  reply	other threads:[~2024-09-04 18:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-25 10:09 [PATCH 0/5] `--whitespace=fix` with `--no-ignore-whitespace` Rubén Justo
2024-08-25 10:17 ` [PATCH 1/5] apply: introduce `ignore_ws_default` Rubén Justo
2024-08-27  1:11   ` Junio C Hamano
2024-08-25 10:18 ` [PATCH 2/5] apply: honor `ignore_ws_none` with `correct_ws_error` Rubén Justo
2024-08-27  0:35   ` Junio C Hamano
2024-08-29  5:07     ` Rubén Justo
2024-08-29 23:13       ` Junio C Hamano
2024-09-03 22:06         ` Rubén Justo
2024-09-04  4:41           ` Junio C Hamano
2024-09-04 18:20             ` Rubén Justo [this message]
2024-08-25 10:18 ` [PATCH 3/5] apply: whitespace errors in context lines if we have Rubén Justo
2024-08-27  0:43   ` Junio C Hamano
2024-08-27  1:49     ` Junio C Hamano
2024-08-27 16:12       ` Junio C Hamano
2024-08-27  0:51   ` Junio C Hamano
2024-08-25 10:19 ` [PATCH 4/5] apply: error message in `record_ws_error()` Rubén Justo
2024-08-27  0:44   ` Junio C Hamano
2024-08-25 10:19 ` [PATCH 5/5] t4124: move test preparation into the test context Rubén Justo

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=f3f863da-50bd-41e3-981c-df93ae771d24@gmail.com \
    --to=rjusto@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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
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).