git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] add -p: coalesce hunks before testing applicability

From
PWPhillip Wood <phillip.wood@talktalk.net>
Date
Sep 13, 2018, 10:20 UTC
Message-ID
<d6a8f77b-0a83-90ae-a7fb-a3954ac3b346@talktalk.net>
In-Reply-To
<20180903190114.GC17416@vis>
Hi Jochen
On 03/09/2018 20:01, Jochen Sprickerhof wrote:
Show 15 quoted lines
> Hi Phillip,
> 
> * Phillip Wood <phillip.wood@talktalk.net> [2018-08-30 14:47]:
>> When $newhunk is created it is marked as dirty to prevent
>> coalesce_overlapping_hunks() from coalescing it. This patch does not
>> change that. What is happening is that by calling
>> coalesce_overlapping_hunks() the hunks that are not currently selected
>> are filtered out and any hunks that can be coalesced are (I think that
>> in the test that starts passing with this patch the only change is the
>> filtering as there's only a single hunk selected).
> 
> Agreed here. It would be enough to include the first hunk in the test to
> make it fail again. Still I would see the patch as going in the right
> direction as we need something like coalesce_overlapping_hunks() to make
> the hunks applicable after the edit.

Yes in the long term we want to be able to coalesce edited hunks, but I think it is confusing to call coalesce_overlapping_hunks() at the moment as it will not coalesce the edited hunks.

Show 9 quoted lines
>> This is a subtle change to the test for the applicability of an edited
>> hunk. Previously when all the hunks were used to create the test patch
>> we could be certain that if the test patch applied then if the user
>> later selected any unselected hunk or deselected any selected hunk
>> then that operation would succeed. I'm not sure that is true now (but
>> I haven't thought about it for very long).
> 
> I'm not sure here. If we use the same test from t3701, do s(plit),
> y(es), e(dit), it would fail later on. Can you come up with an example?

I think that if you split a hunk, edit the first subhunk, transforming a trailing context line to a deletion then try if you try to stage the second subhunk it will fail. With your patch the edit will succeed as the second subhunk is skipped when testing the edited patch. Then when you try to stage the second subhunk it will fail as it's leading context will contradict the trailing lines of the edited subhunk. With the old method the edit failed but didn't store up trouble for the future.

Show 6 quoted lines
>> We could restore the old test condition and coalesce the hunks by
>> copying all the hunks and setting $hunk->{USE}=1 when creating the
>> test patch if that turns out to be useful (it would be interesting to
>> see if the test still passes with that change).
> 
> We set USE=1 for $newhunk already, or where would you set it?

To match the old test it needs to be set on the hunks we've skipped or haven't got to yet so they're all in the patch that's tested after editing a hunk.

Best Wishes
Phillip
> 
> Cheers Jochen
Previous: Jochen SprickerhofNext: Jochen Sprickerhof
Message 6 of 12 in “add -p: coalesce hunks before testing applicability”
  1. add -p: coalesce hunks before testing applicabilityJochen Sprickerhof, Aug 28, 2018
  2. Junio C HamanoAug 28, 2018
  3. Phillip WoodAug 30, 2018
  4. Junio C HamanoAug 30, 2018
  5. Jochen SprickerhofSep 3, 2018
  6. Phillip WoodSep 13, 2018
  7. Jochen SprickerhofSep 23, 2018
  8. Johannes SchindelinMar 22, 2019
  9. Phillip WoodJun 2, 2019
  10. Johannes SchindelinJun 3, 2019
  11. Phillip WoodJun 3, 2019
  12. Johannes SchindelinJun 4, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.