Skip to content
Permalink
Browse files
[webkit-patch] Apply patches commit messages
https://bugs.webkit.org/show_bug.cgi?id=240402
<rdar://93272455>

Reviewed by Dewei Zhu.

* Tools/Scripts/webkitpy/common/checkout/checkout.py:
(Checkout):
(filter_patch_content): Insert reviewer to git patch as we're applying it.
(apply_patch): If a patch has a commit subject, it contains commit messages
and we should apply those commit messages.

Canonical link: https://commits.webkit.org/250551@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294184 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 14, 2022
1 parent 9fb799e commit eae6342c07946fe63fab6196b5b132594dd74964
Showing with 56 additions and 7 deletions.
  1. +14 −0 Tools/ChangeLog
  2. +42 −7 Tools/Scripts/webkitpy/common/checkout/checkout.py
@@ -1,3 +1,17 @@
2022-05-13 Jonathan Bedard <jbedard@apple.com>

[webkit-patch] Apply patches commit messages
https://bugs.webkit.org/show_bug.cgi?id=240402
<rdar://93272455>

Reviewed by Dewei Zhu.

* Scripts/webkitpy/common/checkout/checkout.py:
(Checkout):
(filter_patch_content): Insert reviewer to git patch as we're applying it.
(apply_patch): If a patch has a commit subject, it contains commit messages
and we should apply those commit messages.

2022-05-13 Jonathan Bedard <jbedard@apple.com>

[webkit-patch] Include commit messages in patches
@@ -27,9 +27,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import re
import sys

from webkitcorepy import StringIO
from webkitcorepy import StringIO, string_utils

from webkitpy.common.config import urls
from webkitpy.common.checkout.changelog import ChangeLog, parse_bug_id_from_changelog
@@ -47,6 +48,27 @@
# FIXME: Move a bunch of ChangeLog-specific processing from SCM to this object.
# NOTE: All paths returned from this class should be absolute.
class Checkout(object):
COMMIT_SUBJECT_RE = re.compile(b'Subject: \[PATCH ?(\d+\/\d+)?] (.+)')
FILTER_BRANCH_PROGRAM = '''import re
import sys
lines = [l for l in sys.stdin]
for s in re.split(r' (Need the bug URL \(OOPS!\).)|(\S+:\/\/\S+)', lines[0].rstrip()):
if s and s != ' ':
print(s)
for l in lines[1:]:
sys.stdout.write(l)
'''

@classmethod
def filter_patch_content(cls, content, reviewer=None):
new_content = b''
for line in string_utils.encode(content).splitlines():
if b'Reviewed by NOBODY (OOPS!).' == line and reviewer:
line = b'Reviewed by ' + string_utils.encode(reviewer) + b'.'
new_content += line + b'\n'
return new_content

def __init__(self, scm, executive=None, filesystem=None):
self._scm = scm
# FIXME: We shouldn't be grabbing at private members on scm.
@@ -164,14 +186,27 @@ def bug_id_for_this_commit(self, git_commit, changed_files=None):
pass # We might not have ChangeLogs.

def apply_patch(self, patch):
# It's possible that the patch was not made from the root directory.
# We should detect and handle that case.
# FIXME: Move _scm.script_path here once we get rid of all the dependencies.
# --force (continue after errors) is the common case, so we always use it.
args = [self.script_path('svn-apply'), "--force"]
if patch.reviewer():
args += ['--reviewer', patch.reviewer().full_name]
self._executive.run_command(args, input=patch.contents(), cwd=self._scm.checkout_root)
from webkitpy.common.checkout.scm import Git

encoded_patch = string_utils.encode(patch.contents())
num_commits = len(self.COMMIT_SUBJECT_RE.findall(encoded_patch))
if isinstance(self._scm, Git) and num_commits:
self._executive.run_command(
['git', 'am'],
input=self.filter_patch_content(encoded_patch, reviewer=patch.reviewer().full_name if patch.reviewer() else None),
cwd=self._scm.checkout_root,
)
self._executive.run_command(
['git', 'filter-branch', '-f', '--msg-filter', '{} -c "{}"'.format(sys.executable, self.FILTER_BRANCH_PROGRAM), 'HEAD...HEAD~{}'.format(num_commits)],
cwd=self._scm.checkout_root,
)
else:
args = [self.script_path('svn-apply'), "--force"]
if patch.reviewer():
args += ['--reviewer', patch.reviewer().full_name]
self._executive.run_command(args, input=patch.contents(), cwd=self._scm.checkout_root)

def apply_reverse_diff(self, revision):
self._scm.apply_reverse_diff(revision)

0 comments on commit eae6342

Please sign in to comment.