aboutsummaryrefslogtreecommitdiffstats
path: root/tool/lib/vcs.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-03 22:02:02 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-10-03 22:02:02 +0900
commit10379ebf90acd9622e4fccd9d4386ab3a69f4e9c (patch)
tree6368cb6253b8c201611f8a9ceeef529695002c9b /tool/lib/vcs.rb
parented0661e618fa9fe9e685f755f02e3a1de2d4726b (diff)
downloadruby-10379ebf90acd9622e4fccd9d4386ab3a69f4e9c.tar.gz
Support regexp in log-fix [ci skip]
Diffstat (limited to 'tool/lib/vcs.rb')
-rw-r--r--tool/lib/vcs.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index 13e74ac017..ace60f8f8e 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -707,12 +707,31 @@ class VCS
range = b..b
end
case x
- when %r[^s([#{LOG_FIX_REGEXP_SEPARATORS}])(.+)\1(.*)\1]o
+ when %r[^s([#{LOG_FIX_REGEXP_SEPARATORS}])(.+)\1(.*)\1([gr]+)?]o
wrong = $2
correct = $3
+ if opt = $4 and opt.include?("r") # regexp
+ wrong = Regexp.new(wrong)
+ correct.gsub!(/(?<!\\)(?:\\\\)*\K(?:\\n)+/) {"\n" * ($&.size / 2)}
+ sub = opt.include?("g") ? :gsub! : :sub!
+ else
+ sub = false
+ end
range.each do |n|
- s[n][wrong] = correct
- rescue IndexError
+ if sub
+ ss = s[n].sub(/^#{sp}/, "") # un-indent for /^/
+ if ss.__send__(sub, wrong, correct)
+ s[n, 1] = ss.lines.map {|l| "#{sp}#{l}"}
+ next
+ end
+ else
+ begin
+ s[n][wrong] = correct
+ rescue IndexError
+ else
+ next
+ end
+ end
message = ["format_changelog failed to replace #{wrong.dump} with #{correct.dump} at #{n}\n"]
from = [1, n-2].max
to = [s.size-1, n+2].min