Skip to content
Permalink
Browse files
[PrettyPatch] Support commit messages
https://bugs.webkit.org/show_bug.cgi?id=240386
<rdar://problem/93248835>

Rubber-stamped by Aakash Jain.

* Websites/bugs.webkit.org/PrettyPatch/PrettyPatch.rb:
(PrettyPatch.message_header): Match a commit message header.
(PrettyPatch.message_footer): Match a commit message footer.
(PrettyPatch.MESSAGE_HEADER_FORMATS): List of commit message headers.
(PrettyPatch.BUG_URL_RE): Regex to match bug urls in subject.
(PrettyPatch.MESSAGE_FOOTER_FORMATS): List of commit messagae footers.
(PrettyPatch.parse): Treat commit messages a new file named 'COMMIT_MESSAGE'.

Canonical link: https://commits.webkit.org/250530@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294161 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed May 13, 2022
1 parent f8fdb68 commit e4ced81ebbc9c7979d0a34c3554133059b025d48
Showing 2 changed files with 67 additions and 1 deletion.
@@ -1,3 +1,19 @@
2022-05-13 Jonathan Bedard <jbedard@apple.com>

[PrettyPatch] Support commit messages
https://bugs.webkit.org/show_bug.cgi?id=240386
<rdar://problem/93248835>

Rubber-stamped by Aakash Jain.

* PrettyPatch/PrettyPatch.rb:
(PrettyPatch.message_header): Match a commit message header.
(PrettyPatch.message_footer): Match a commit message footer.
(PrettyPatch.MESSAGE_HEADER_FORMATS): List of commit message headers.
(PrettyPatch.BUG_URL_RE): Regex to match bug urls in subject.
(PrettyPatch.MESSAGE_FOOTER_FORMATS): List of commit messagae footers.
(PrettyPatch.parse): Treat commit messages a new file named 'COMMIT_MESSAGE'.

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

[bugs.webkit.org] Use GitHub as baseline when diffing
@@ -47,6 +47,14 @@ def self.diff_header?(line)
RELAXED_DIFF_HEADER_FORMATS.any? { |format| line =~ format }
end

def self.message_header?(line)
MESSAGE_HEADER_FORMATS.any? { |format| line =~ format }
end

def self.message_footer?(line)
MESSAGE_FOOTER_FORMATS.any? { |format| line =~ format }
end

private
DIFF_HEADER_FORMATS = [
/^Index: (.*)\r?$/,
@@ -59,6 +67,16 @@ def self.diff_header?(line)
/^diff/
]

MESSAGE_HEADER_FORMATS = [
/^Subject: \[PATCH ?(\d+\/\d+)?\] (.+)/
]

BUG_URL_RE = / (Need the bug URL \(OOPS!\).)|(\S+:\/\/\S+)/

MESSAGE_FOOTER_FORMATS = [
/^---/
]

RENAME_FROM = /^rename from (.*)/

SVN_BINARY_FILE_MARKER_FORMAT = /^Cannot display: file marked as a binary type.$/
@@ -777,7 +795,9 @@ def to_html
end

def self.parse(string)
commitMessageLength = 0
haveSeenDiffHeader = false
subject = ''
linesForDiffs = []
line_array = string.lines.to_a
line_array.each_with_index do |line, index|
@@ -787,8 +807,38 @@ def self.parse(string)
elsif (!haveSeenDiffHeader && line =~ /^--- / && line_array[index + 1] =~ /^\+\+\+ /)
linesForDiffs << []
haveSeenDiffHeader = false
elsif (PrettyPatch.message_header?(line))
haveSeenDiffHeader = false
parsingSubject = true
commitMessageLength = 1
linesForDiffs << []
linesForDiffs.last << '+++ COMMIT_MESSAGE'
if line[MESSAGE_HEADER_FORMATS[0], 1]
linesForDiffs.last[-1] += ' (' + line[MESSAGE_HEADER_FORMATS[0], 1] + ')'
end
linesForDiffs.last << '@@ -0,0 +1,1 @@'
subject = line[MESSAGE_HEADER_FORMATS[0], 2]
elsif (!subject.empty? && line.strip.empty?)
subject.split(BUG_URL_RE).each { |mtch|
if !mtch.strip.empty?
commitMessageLength += 1
linesForDiffs.last << '+' + mtch
end
}
subject = ''
elsif (!subject.empty?)
subject += line
elsif (commitMessageLength != 0 && PrettyPatch.message_footer?(line))
linesForDiffs.last[1] = '@@ -0,0 +1,' + commitMessageLength.to_s + ' @@'
commitMessageLength = 0
end

if (subject.empty? && commitMessageLength != 0)
commitMessageLength += 1
linesForDiffs.last << '+' + line unless linesForDiffs.last.nil?
elsif (subject.empty? && haveSeenDiffHeader)
linesForDiffs.last << line unless linesForDiffs.last.nil?
end
linesForDiffs.last << line unless linesForDiffs.last.nil?
end

linesForDiffs.collect { |lines| FileDiff.new(lines) }

0 comments on commit e4ced81

Please sign in to comment.