summaryrefslogtreecommitdiff
path: root/tool/sync_default_gems.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-04-16 17:13:24 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-04-16 17:13:24 +0900
commita3ef0746ce07817845bfa9af697de53a28f599f7 (patch)
treeb48fa2e0c7a07197f9a2b717d9e11bb9a55c882a /tool/sync_default_gems.rb
parentb09e96341e8157a190b4c4b0ec0784be76887e0d (diff)
Extract `pipe_readlines` method which reads from the pipeline
Diffstat (limited to 'tool/sync_default_gems.rb')
-rwxr-xr-xtool/sync_default_gems.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index a65aab49ba..e5821898af 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -77,6 +77,12 @@ REPOSITORIES = {
win32ole: "ruby/win32ole",
}
+def pipe_readlines(args, rs: "\0", chomp: true)
+ IO.popen(args) do |f|
+ f.readlines(rs, chomp: chomp)
+ end
+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]
@@ -424,9 +430,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
# Ignore Merge commit and insufficiency commit for ruby core repository.
commits.delete_if do |sha, subject|
- files = IO.popen(%W"git diff-tree -z --no-commit-id --name-only -r #{sha}") {|f|
- f.readlines("\0", chomp: true)
- }
+ files = pipe_readlines(%W"git diff-tree -z --no-commit-id --name-only -r #{sha}")
subject.start_with?("Merge", "Auto Merge") or files.all?(IGNORE_FILE_PATTERN)
end
@@ -464,14 +468,14 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
if result.empty?
skipped = true
elsif /^CONFLICT/ =~ result
- result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!)
+ result = pipe_readlines(%W"git status --porcelain -z")
result.map! {|line| line[/^.U (.*)/, 1]}
result.compact!
ignore, conflict = result.partition {|name| IGNORE_FILE_PATTERN =~ name}
unless ignore.empty?
system(*%W"git reset HEAD --", *ignore)
File.unlink(*ignore)
- ignore = IO.popen(%W"git status --porcelain" + ignore, &:readlines).map! {|line| line[/^.. (.*)/, 1]}
+ ignore = pipe_readlines(%W"git status --porcelain -z" + ignore).map! {|line| line[/^.. (.*)/, 1]}
system(*%W"git checkout HEAD --", *ignore) unless ignore.empty?
end
unless conflict.empty?