3

I found both these quotes on the same diffoption --horizon-lines=lines:

Do not discard the last lines lines of the common prefix and the first lines lines of the common suffix. [source]

The quote above links to the next quote here for more explaination:

The --horizon-lines=lines option prevents diff from discarding the last lines lines of the prefix and the first lines lines of the suffix. [source]

Can someonebody please explain what this might mean? Especially "the common prefix and the first lines lines of the common suffix"

1 Answer 1

4

This explanation seems to make more sense then the above 2 that you cited.

excerpt - https://www.gnu.org/software/diffutils/manual/html_node/diff-Performance.html

Normally diff discards the prefix and suffix that is common to both files before it attempts to find a minimal set of differences. This makes diff run faster, but occasionally it may produce non-minimal output. The --horizon-lines=lines option prevents diff from discarding the last lines lines of the prefix and the first lines lines of the suffix. This gives diff further opportunities to find a minimal output.

Suppose a run of changed lines includes a sequence of lines at one end and there is an identical sequence of lines just outside the other end. The diff command is free to choose which identical sequence is included in the hunk. In this case, diff normally shifts the hunk's boundaries when this merges adjacent hunks, or shifts a hunk's lines towards the end of the file. Merging hunks can make the output look nicer in some cases.

The reference to "lines lines" means X number of lines. So mentally read that sentence again but say "X lines" where it says "lines lines". The X would correspond to a number that was passed as an argument to diff --horizon-lines=lines.

The 2nd paragraph I cited above explains what the difference would be with that option specified.

2
  • 2
    A really good answer to this question would explain when the option makes a difference. It looks like a weird corner case. Sep 29, 2014 at 7:05
  • @slm So basically it shortens the output? What confuses me starts in the first line of the quote: If there is something common it can't be different at the same time - or did I miss something?
    – erch
    Sep 29, 2014 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .