summaryrefslogtreecommitdiff
path: root/tool/sync_default_gems.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-12 11:50:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-12 12:27:40 +0900
commitdf588440ee01e91d87cb815ff85dd6c785dc7827 (patch)
tree1ace8cb4875367509b0c7808121c6c7e9c20a42b /tool/sync_default_gems.rb
parentc67e49688642b5a650f53765dd11c1202d1ea57f (diff)
sync_default_gems: Replace the external URIs to docs with rdoc-ref
Diffstat (limited to 'tool/sync_default_gems.rb')
-rwxr-xr-xtool/sync_default_gems.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 530ec6e7b3..3aabd3739c 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -84,6 +84,30 @@ def pipe_readlines(args, rs: "\0", chomp: true)
end
end
+def replace_rdoc_ref(file)
+ src = File.binread(file)
+ src.gsub!(%r[\[\Khttps://docs\.ruby-lang\.org/en/master/(([A-Z]\w+(?:/[A-Z]\w+)*)|\w+_rdoc)\.html(\#\S+)?(?=\])]) do
+ name, mod, label = $1, $2, $3
+ mod &&= mod.gsub('/', '::')
+ if label && (m = label.match(/\A\#(?:method-([ci])|(?:(?:class|module)-#{mod}-)?label)-([-+\w]+)\z/))
+ scope, label = m[1], m[2]
+ scope = scope ? scope.tr('ci', '.#') : '@'
+ end
+ "rdoc-ref:#{mod || name.chomp("_rdoc") + ".rdoc"}#{scope}#{label}"
+ end or return false
+ File.rename(file, file + "~")
+ File.binwrite(file, src)
+ return true
+end
+
+def replace_rdoc_ref_all
+ result = pipe_readlines(%W"git status porcelain -z -- *.c *.rb *.rdoc")
+ result.map! {|line| line[/\A.M (.*)/, 1]}
+ result.compact!
+ result = pipe_readlines(%W"git grep -z -l -F [https://docs.ruby-lang.org/en/master/ --" + result)
+ result.inject(false) {|changed, file| changed | replace_rdoc_ref(file)}
+end
+
# We usually don't use this. Please consider using #sync_default_gems_with_commits instead.
def sync_default_gems(gem)
repo = REPOSITORIES[gem.to_sym]
@@ -382,6 +406,7 @@ def sync_default_gems(gem)
else
sync_lib gem, upstream
end
+ replace_rdoc_ref_all
end
IGNORE_FILE_PATTERN =
@@ -508,6 +533,10 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
next
end
+ if replace_rdoc_ref_all
+ `git commit --amend --no-edit`
+ end
+
puts "Update commit message: #{sha}"
IO.popen(%W[git filter-branch -f --msg-filter #{[filter, repo, sha].join(' ')} -- HEAD~1..HEAD], &:read)