Modified: trunk/Tools/ChangeLog (294183 => 294184)
--- trunk/Tools/ChangeLog 2022-05-13 23:37:58 UTC (rev 294183)
+++ trunk/Tools/ChangeLog 2022-05-14 01:42:44 UTC (rev 294184)
@@ -1,5 +1,19 @@
2022-05-13 Jonathan Bedard <jbed...@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 <jbed...@apple.com>
+
[webkit-patch] Include commit messages in patches
https://bugs.webkit.org/show_bug.cgi?id=240256
<rdar://92982358>
Modified: trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py (294183 => 294184)
--- trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py 2022-05-13 23:37:58 UTC (rev 294183)
+++ trunk/Tools/Scripts/webkitpy/common/checkout/checkout.py 2022-05-14 01:42:44 UTC (rev 294184)
@@ -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,15 +186,28 @@
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)