diff options
-rwxr-xr-x | tool/file2lastrev.rb | 6 | ||||
-rw-r--r-- | tool/lib/output.rb | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb index 1dfb01ab9e..6200e78a56 100755 --- a/tool/file2lastrev.rb +++ b/tool/file2lastrev.rb @@ -25,6 +25,7 @@ end time_format = '%Y-%m-%dT%H:%M:%S%z' vcs = nil +create_only = false OptionParser.new {|opts| opts.banner << " paths..." vcs_options = VCS.define_options(opts) @@ -62,6 +63,9 @@ OptionParser.new {|opts| abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found opts.remove (vcs = VCS::Null.new(nil)).set_options(vcs_options) + if @format == :revision_h + create_only = true # don't overwrite existing revision.h when .git doesn't exist + end end } @@ -92,7 +96,7 @@ ok = true begin data = formatter[*vcs.get_revisions(arg)] data.sub!(/(?<!\A|\n)\z/, "\n") - @output.write(data, overwrite: true) + @output.write(data, overwrite: true, create_only: create_only) rescue => e warn "#{File.basename(Program)}: #{e.message}" ok = false diff --git a/tool/lib/output.rb b/tool/lib/output.rb index 3a9f3d87ae..b1c4f4a866 100644 --- a/tool/lib/output.rb +++ b/tool/lib/output.rb @@ -18,7 +18,7 @@ class Output @vpath.def_options(opt) end - def write(data, overwrite: false) + def write(data, overwrite: false, create_only: false) unless @path $stdout.print data return true @@ -28,8 +28,8 @@ class Output updated = color.fail("updated") outpath = nil - if (@ifchange or overwrite) and - (@vpath.open(@path, "rb") {|f| outpath = f.path; f.read == data if @ifchange} rescue false) + if (@ifchange or overwrite or create_only) and + (@vpath.open(@path, "rb") {|f| outpath = f.path; (@ifchange and f.read == data) or (create_only and !f.read.empty?)} rescue false) puts "#{outpath} #{unchanged}" written = false else |