Add UnifiedDiffWriter, a helper for writing diffs.

Review Request #12619 — Created Sept. 22, 2022 and submitted

Information

RBTools
release-4.x

Reviewers

This introduces rbtools.diffs.writers.UnifiedDiffWriter, which is a
io.BytesIO that allows for consistent, faster building of diffs.

Most of our SCMs have historically built diffs as lines that are then
joined together. While that worked, it wasn't as optimal as a BytesIO
should be, and it left so much of the diff building up to each
individual SCMClient, not all of which were consistent in how they built
diffs.

UnifiedDiffWriter provides a nicer interface with more consistent
results. There's functionality for writing original/modified headers,
hunks, and arbitrary lines. These can also be generated straight from a
DiffFileResult, minimizing the work required by SCMClients.

A writer can take a newline string, and an encoding for any Unicode
strings These will probably never need to be changed (and in fact the
encoding shouldn't be, as encodings in diffs is complicated and not
something that should generally be touched at this level). However, we
have these set so that we can have stable values to refer to during diff
building.

Upcoming changes to SCMClients will switch over to diff tools and the
writer for building diffs.

Unit tests passed.

Made use of this in some upcoming changes successfully.

Summary ID
Add UnifiedDiffWriter, a helper for writing diffs.
This introduces `rbtools.diffs.writers.UnifiedDiffWriter`, which is a `io.BytesIO` that allows for consistent, faster building of diffs. Most of our SCMs have historically built diffs as lines that are then joined together. While that worked, it wasn't as optimal as a `BytesIO` should be, and it left so much of the diff building up to each individual SCMClient, not all of which were consistent in how they built diffs. `UnifiedDiffWriter` provides a nicer interface with more consistent results. There's functionality for writing original/modified headers, hunks, and arbitrary lines. These can also be generated straight from a `DiffFileResult`, minimizing the work required by SCMClients. A writer can take a newline string, and an encoding for any Unicode strings These will probably never need to be changed (and in fact the encoding shouldn't be, as encodings in diffs is complicated and not something that should generally be touched at this level). However, we have these set so that we can have stable values to refer to during diff building. Upcoming changes to SCMClients will switch over to diff tools and the writer for building diffs.
3e3f9e23b7551d9ded935c84830b195ccb6a394c
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-4.x (0b1e69d)
Loading...