Skip to content

Improve focus of multi-line string diffs when there are loads of lines #68

Open
@novemberborn

Description

See discussion: avajs/ava#2665

When comparing two strings that are many lines long, the diff output should focus on the lines that are actually different, not the potentially dozens or hundreds of lines that are the same.

  1. If the diff is longer than, say, 30 lines, divide it into sections of changes and non-changes.
  2. If the non-change sections are 5 lines or less, merge the surrounding change sections into one larger change section.
  3. For the sections with changes, provide 5 lines of context before and after the actual change. Take 5 lines from the preceding and succeeding non-change sections, if any. Due to step 2, these sections must be larger than 5 lines.
  4. Prefix the change sections with a hunk heading @@ -l, +l @@, where the line numbers l correspond to the - and + sides of the diff.
  5. Print the change sections, prefixed with their heading, and separated with an empty line between them.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions