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

ruby-changes:74316

From: Nobuyoshi <ko1@a...>
Date: Wed, 2 Nov 2022 13:30:00 +0900 (JST)
Subject: [ruby-changes:74316] 3475b66160 (master): file2lastrev.rb: try to overwrite the found revision.h as before

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

From 3475b661607e6d2c72460ea381ee856726128259 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 2 Nov 2022 12:18:17 +0900
Subject: file2lastrev.rb: try to overwrite the found revision.h as before

---
 tool/file2lastrev.rb |  2 +-
 tool/lib/output.rb   | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb
index a2b639a426..48b8a1ae99 100755
--- a/tool/file2lastrev.rb
+++ b/tool/file2lastrev.rb
@@ -90,7 +90,7 @@ formatter = https://github.com/ruby/ruby/blob/trunk/tool/file2lastrev.rb#L90
 ok = true
 (ARGV.empty? ? [nil] : ARGV).each do |arg|
   begin
-    @output.write(formatter[*vcs.get_revisions(arg)]+"\n")
+    @output.write(formatter[*vcs.get_revisions(arg)]+"\n", overwrite: true)
   rescue => e
     warn "#{File.basename(Program)}: #{e.message}"
     ok = false
diff --git a/tool/lib/output.rb b/tool/lib/output.rb
index 584be76974..cbaa4b5a3e 100644
--- a/tool/lib/output.rb
+++ b/tool/lib/output.rb
@@ -18,7 +18,7 @@ class Output https://github.com/ruby/ruby/blob/trunk/tool/lib/output.rb#L18
     @vpath.def_options(opt)
   end
 
-  def write(data)
+  def write(data, overwrite: false)
     unless @path
       $stdout.print data
       return true
@@ -26,13 +26,16 @@ class Output https://github.com/ruby/ruby/blob/trunk/tool/lib/output.rb#L26
     color = Colorize.new(@color)
     unchanged = color.pass("unchanged")
     updated = color.fail("updated")
+    outpath = nil
 
-    if @ifchange and (@vpath.read(@path, "rb") == data rescue false)
-      puts "#{@path} #{unchanged}"
+    if @ifchange and (@vpath.open(@path, "rb") {|f| outpath = f.path; f.read == data} rescue false)
+      puts "#{outpath} #{unchanged}"
       written = false
     else
-      File.binwrite(@path, data)
-      puts "#{@path} #{updated}"
+      unless overwrite and outpath and (File.binwrite(outpath, data) rescue nil)
+        File.binwrite(outpath = @path, data)
+      end
+      puts "#{outpath} #{updated}"
       written = true
     end
     if timestamp = @timestamp
-- 
cgit v1.2.3


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

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