# diff --break-rewrites for just a part of a file

2 messages from 2016-05-10 to 2016-05-10. Participants: Sascha Silbe, Junio C Hamano.
Thread: https://gitlist.dev/t/42276

## Sascha Silbe, 2016-05-10 16:22

Subject: diff --break-rewrites for just a part of a file
Message-ID: <toea8jx3mt1.fsf@mimosa.sascha.silbe.org>
URL: https://gitlist.dev/e/toea8jx3mt1.fsf%40mimosa.sascha.silbe.org

```
Hello,

the other day I was reviewing a patch that replaced a large chunk in a
Makefile with completely different logic. No matter what diff algorithm
and options I threw at it, the diff would always synchronise at the
empty lines between individual targets and thus show the rewrite of a
larger section as complete replacements of many smaller, but directly
adjacent sections (only separated by a blank line).

--break-rewrites would be nicely suited for this case, but once I dialed
down the parameters enough for the option to apply at all, it showed the
entire file as being replaced rather than just the section in between
that actually changed. Is there a way to have --break-rewrites leave out
the unchanged lines at beginning and end of the file?

A combination of --break-rewrites and --inter-hunk-context that merges
changes with less than the given number of unchanged lines between them
into a single delete/insert change would be even better. But just
ignoring the unchanged header and footer of a file for --break-rewrites
would already go a long way.

Sascha

```

## Junio C Hamano, 2016-05-10 19:16

Subject: Re: diff --break-rewrites for just a part of a file
Message-ID: <xmqq1t59pvtg.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq1t59pvtg.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <toea8jx3mt1.fsf@mimosa.sascha.silbe.org>

```
Sascha Silbe <sascha-ml-reply-to-2016-2@silbe.org> writes:

> A combination of --break-rewrites and --inter-hunk-context that merges
> changes with less than the given number of unchanged lines between them
> into a single delete/insert change would be even better. But just
> ignoring the unchanged header and footer of a file for --break-rewrites
> would already go a long way.

That's interesting.  Break-rewrites as originally designed and
implemented is only about "When the entire file been rewritten
completely, it is easier to read when the diff did not pay any
attention to those accidentally common lines".

We recently had a discussion on tweaking the logic used to merge and
minimize hunks; the topic was about where to start the hunk boundary
for maximum readability when the beginning and end of a hunk can be
shifted around, but this smells like a similar issue.

```
