From 71f7b0421acff068b94953f4d3f5b4d987ce5350 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 7 Sep 2019 01:00:14 +0900 Subject: Refined file2lastrev.rb options * check --srcdir if given twice or more * falls back to the current working directory if no --srcdir option is given. * define common VCS options. --- tool/file2lastrev.rb | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'tool') diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb index 68c660efaa..9089b7fbb0 100755 --- a/tool/file2lastrev.rb +++ b/tool/file2lastrev.rb @@ -22,10 +22,22 @@ end @limit = 20 format = '%Y-%m-%dT%H:%M:%S%z' -srcdir = nil -parser = OptionParser.new {|opts| +vcs = nil +OptionParser.new {|opts| + opts.banner << " paths..." + vcs_options = VCS.define_options(opts) + new_vcs = proc do |path| + begin + VCS.detect(path, vcs_options, opts.new) + rescue VCS::NotFoundError => e + abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found + opts.pop + end + end + opts.new opts.on("--srcdir=PATH", "use PATH as source directory") do |path| - srcdir = path + abort "#{File.basename(Program)}: srcdir is already set" if vcs + vcs = new_vcs[path] end opts.on("--changed", "changed rev") do self.output = :changed @@ -46,10 +58,14 @@ parser = OptionParser.new {|opts| opts.on("-q", "--suppress_not_found") do @suppress_not_found = true end + opts.order! rescue abort "#{File.basename(Program)}: #{$!}\n#{opts}" + if vcs + vcs.set_options(vcs_options) # options after --srcdir + else + vcs = new_vcs["."] + end } -parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}" -vcs = nil @output = case @output when :changed, nil @@ -94,20 +110,14 @@ vcs = nil end srcdir ||= File.dirname(File.dirname(Program)) -begin - vcs = VCS.detect(srcdir) -rescue VCS::NotFoundError => e - abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found -else - ok = true - (ARGV.empty? ? [nil] : ARGV).each do |arg| - begin - puts @output[*vcs.get_revisions(arg)] - rescue => e - next if @suppress_not_found and VCS::NotFoundError === e - warn "#{File.basename(Program)}: #{e.message}" - ok = false - end +ok = true +(ARGV.empty? ? [nil] : ARGV).each do |arg| + begin + puts @output[*vcs.get_revisions(arg)] + rescue => e + next if @suppress_not_found and VCS::NotFoundError === e + warn "#{File.basename(Program)}: #{e.message}" + ok = false end - exit ok end +exit ok -- cgit v1.2.3