From af68112a1b8512c8d5c9823f0f71db8df1c0c6b1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 3 Sep 2021 23:46:33 +0900 Subject: Add some punctuations as regexp separators to fix commit logs --- tool/lib/vcs.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'tool/lib/vcs.rb') diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb index 5d78d94c26..1ccf80a49f 100644 --- a/tool/lib/vcs.rb +++ b/tool/lib/vcs.rb @@ -575,6 +575,8 @@ class VCS end end + LOG_FIX_REGEXP_SEPARATORS = '/!:;|,#%&' + def format_changelog(path, arg, base_url = nil) env = {'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'} cmd = %W"#{COMMAND} log --format=fuller --notes=commits --notes=log-fix --topo-order --no-merges" @@ -596,13 +598,16 @@ class VCS s = s.lines fix.each_line do |x| case x - when %r[^ +(\d+)s/(.+)/(.*)/] + when %r[^ +(\d+)s([#{LOG_FIX_REGEXP_SEPARATORS}])(.+)\2(.*)\2]o + n = $1.to_i + wrong = $3 + correct = $4 begin - s[$1.to_i][$2] = $3 + s[n][wrong] = correct rescue IndexError - message = ["format_changelog failed to replace #{$2.dump} with #{$3.dump} at #$1\n"] - from = [1, $1.to_i-2].max - to = [s.size-1, $1.to_i+2].min + message = ["format_changelog failed to replace #{wrong.dump} with #{correct.dump} at #$1\n"] + from = [1, n-2].max + to = [s.size-1, n+2].min s.each_with_index do |e, i| next if i < from break if to < i @@ -610,8 +615,8 @@ class VCS end raise message.join('') end - when %r[^( +)(\d+)i/(.*)/] - s[$2.to_i, 0] = "#{$1}#{$3}\n" + when %r[^( +)(\d+)i([#{LOG_FIX_REGEXP_SEPARATORS}])(.*)\3]o + s[$2.to_i, 0] = "#{$1}#{$4}\n" when %r[^ +(\d+)(?:,(\d+))?d] n = $1.to_i e = $2 -- cgit v1.2.3