Expand diff parsing for additional metadata and multiple changes.
Review Request #11744 — Created July 26, 2021 and submitted
Historically, our diff parsing infrastructure was built around a base
set of manual line-by-line parsing rules, which could be specialized.
The result would be a list of files. This was expanded a bit in 4.0 and
subsequent releases to collect and handle additional data (such as being
able to populate
FileDiff.extra_data), but the core design remained.
With DiffX coming, we need more. This change expands our diff parsing
ParsedDiffChangeclasses were added, which
represent information on a diff as a whole, and a change within it,
respectively. These both provide support for populating
which will be set in
DiffCommitwhen parsing a diff.
BaseDiffParserhas been introduced as the new base class, which
DiffParsersubclasses. The new base class does very little, and is
more of an interface. It contains no built-in parsing logic. This will
allow for more specialized parsers with their own logic.
DiffParsernow provide a
which is the new method to call to parse a diff. This replaces
parse(), which still exists in
For new subclasses of
will be responsible for parsing into a series of
For subclasses of
parse()can still be overridden. The
DiffParser.parse_diff()will set up the new objects as
This new model will make it easier to implement DiffX, and will give us
some good capabilities down the road. For the moment, there are still
limitations based on our existing process of uploading and parsing
diffs. The main one being that, while a
ParsedDiff(and later a DiffX)
can in theory have multiple changes, it's not actually allowed through
our parsing. Clients of the API will need to provide diffs with only a
single change, until we're able to implement the appropriate changes
in the diff upload API and related code (probably post-4.0 sometime).
Unit tests pass on Python 2 and 3.
Tested posting diffs for review, without any issues.
- Removed a duplicate assertion.
- Fixed a variable access.
- Removed an unused import.
Revision 2 (+1164 -156)
Checks run (1 failed, 1 succeeded)
- Improved the deprecation handling in
- Added unit tests for
Revision 3 (+1320 -160)
Checks run (2 succeeded)