Switch RBTools to use modern patching, and add a legacy patch wrapper.
Review Request #14224 — Created Nov. 3, 2024 and submitted — Latest diff uploaded
rbt patch
andrbt land
now use the newPatcher
class
(specifically, aSCMClientPatcher
), which gives SCMClients a lot more
control over the patching and committing process.By default, SCMClients that don't define custom patching logic will use
the built-in patching logic that leverages thepatch
tool.SCMClients that override
apply_patch()
will continue to use their
existing patching logic, but wrapped by a_LegacyPatcher
implementation that'll maintain compatibility until RBTools 7. This acts
as a bridge between the newPatcher
API and legacy implementations of
SCMClient.apply_patch()
andSCMClient.apply_patch_for_empty_files()
rbt patch
andrbt land
will callSCMClient.get_patcher()
to return
aSCMClientPatcher
-compatible instance for handling patching
operations.Now, there's a little bit of a complex transition here.
SCMClient.apply_patch()
will remain a valid function for applying
patches for the time-being, but its behavior changes between the legacy
patcher and the modern patcher:
-
By default, a SCMClient that doesn't implement custom patching
behavior) will use a defaultapply_patch()
method that gets a
defaultSCMClientPatcher
class for handling patches by way of
get_patcher()
. -
Updated SCMClients with custom patching behavior are expected to now
subclassPatcher
and overridepatcher_cls
to match it.
get_patcher()
will return it, andapply_patch()
will interface
with it. -
SCMClients that override
apply_patch()
with legacy patching behavior
will behave as they did before, for now, andget_patcher()
will
return a_LegacyPatcher
to wrap it. This enablesrbt patch
to work
with the legacy implementation.
Over time, we'll remove _LegacyPatcher
. We may also be deprecating
apply_patch()
soon, once everything is transitioned over.
All unit tests passed.
Applied patches to local trees using both the default patching
implementation and the legacy patcher. Tested applying, reversing,
and committing.
Diff Revision 2
This is not the most recent revision of the diff. The latest diff is revision 5. See what's changed.
Commits
rbtools/clients/base/scmclient.py |
---|
rbtools/clients/tests/test_base_scmclient.py |
---|
rbtools/clients/tests/test_legacy_patcher.py |
---|
rbtools/commands/patch.py |
---|
rbtools/diffs/patcher.py |
---|
rbtools/diffs/tests/test_patcher.py |
---|