[前][次][番号順一覧][スレッド一覧]

ruby-changes:71754

From: Nobuyoshi <ko1@a...>
Date: Sat, 16 Apr 2022 17:17:16 +0900 (JST)
Subject: [ruby-changes:71754] a3ef0746ce (master): Extract `pipe_readlines` method which reads from the pipeline

https://git.ruby-lang.org/ruby.git/commit/?id=a3ef0746ce

From a3ef0746ce07817845bfa9af697de53a28f599f7 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 16 Apr 2022 17:13:24 +0900
Subject: Extract `pipe_readlines` method which reads from the pipeline

---
 tool/sync_default_gems.rb | 14 +++++++++-----
 1 file 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 = { https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L77
   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) https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L430
 
   # 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) https://github.com/ruby/ruby/blob/trunk/tool/sync_default_gems.rb#L468
     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?
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]