Add the beginnings of a Diff Tool layer.
Review Request #12599 — Created Sept. 14, 2022 and submitted
We've used GNU Diff as a standard dependency for many of our SCMs for
many years now, as it's been readily available (either built-in or easy
to install) on all target systems for ages. However, that is changing
with the upcoming macOS Ventura release, which will replace GNU Diff
with Apple Diff, a fork of some unknown version of BSD Diff.To prepare for that, and to provide an opportunity for cleaning up any
code dealing with raw diffs, this change introduces a new
rbtools.diffs.tools
module. This provides abstractions around invoking
diff tools and creating a normalized representation of results.These will eventually be used in place of any
execute()
or
run_process()
call arounddiff
.To start, this change adds the abstract base class,
BaseDiffTool
, and
a results class,DiffFileResult
.
BaseDiffTool
subclasses must set a couple of attributes:
diff_tool_id
: A unique string for registration and identification.name
: A human-readable name for the diff tool (used for
errors/logging).
And implement some methods:
check_available()
: Checks for presence/compatibility of the wrapped
diff tool.run_diff_file()
: Runs the diff tool for two files, converting the
provided flags to command line arguments, and returning a normalized
diff result.get_install_instructions()
: Optional, but is used for error messages
if no diff tool can be found.
Results of a run_diff_file()
are represented by a DiffFileResult
object. This wraps a result byte stream that can be used by the caller,
along with some utility methods for getting the original/modified
headers or hunk data in different forms. This also contains state on
whether it diffed a binary file or a text file and whether there were
changes.
Currently, nothing uses this, and GNU Diff support isn't available.
Upcoming changes will flesh this out, providing a diff tool registry,
GNU diff support, SCMClient integration, and finally, Apple Diff
support.
Unit tests pass.
Tested these with some upcoming changes and verified this functionality
works.Built the docs and checked for obvious errors.
Summary | ID |
---|---|
e3fde7d9fecf3d739a5275901d5d37d2bcd4c761 |
- Change Summary:
-
- Renamed
{orig,modified}_line_header
properties to{orig,modified}_file_header
inDiffFileResult
. - Added
parsed_{orig,modified}_file_header
functions, for extracting the marker, filename, and extra info from header lines. - Added
orig_path
andmodified_path
attributes toDiffFileResult
, which are the ones passed to the diff tool. - Added some missing
Version Added
. - Updated
{orig,modified}_line_header
andhunks
to avoid work ifhas_text_differences=False
. - Updated
{orig,modified}_line_header
to avoid returning non-headers, if encountered. - Fixed some docstring typos.
- Renamed
- Commits:
-
Summary ID ce79281706321b36ca499e1332a769e191e20574 1179e97afe7345929ce59b97adecb084a1b100a0 - Diff:
-
Revision 2 (+3180)
Checks run (2 succeeded)
- Change Summary:
-
Actually added the missing
Version Added
this time. - Commits:
-
Summary ID 1179e97afe7345929ce59b97adecb084a1b100a0 e6db317f4132a612f04596ce0d92cd27a890e1dc - Diff:
-
Revision 3 (+3188)
Checks run (2 succeeded)
- Change Summary:
-
Updated
DiffFileResult.iter_hunk_lines()
to perform\r\r\n
newline normalization and enable stripping of newlines by default. - Commits:
-
Summary ID e6db317f4132a612f04596ce0d92cd27a890e1dc bd72d4184b02d63cb0a5478358173a3a4cfbe14b - Diff:
-
Revision 4 (+3236)
Checks run (2 succeeded)
- Change Summary:
-
Updated the
file_header_re
documentation to be more explicit about requirements and usage, and to fix a missing period. - Commits:
-
Summary ID bd72d4184b02d63cb0a5478358173a3a4cfbe14b 461cfe6a53cbf84332977f4440f4e2b61ee05fc5 - Diff:
-
Revision 5 (+3242)
Checks run (2 succeeded)
- Change Summary:
-
Added missing unit tests for the
iter_hunk_lines()
changes (keep_newlines=
and newline normalization). - Commits:
-
Summary ID 461cfe6a53cbf84332977f4440f4e2b61ee05fc5 e3fde7d9fecf3d739a5275901d5d37d2bcd4c761 - Diff:
-
Revision 6 (+3518)