Skip to content

Commit

Permalink
file2lastrev.rb: try to overwrite the found revision.h as before
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Nov 2, 2022
1 parent ac06951 commit 3475b66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tool/file2lastrev.rb
Expand Up @@ -90,7 +90,7 @@ def self.format=(format)
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
Expand Down
13 changes: 8 additions & 5 deletions tool/lib/output.rb
Expand Up @@ -18,21 +18,24 @@ def def_options(opt)
@vpath.def_options(opt)
end

def write(data)
def write(data, overwrite: false)
unless @path
$stdout.print data
return true
end
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
Expand Down

0 comments on commit 3475b66

Please sign in to comment.