summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-07 01:00:14 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-09-07 11:38:38 +0900
commit71f7b0421acff068b94953f4d3f5b4d987ce5350 (patch)
treed857486f736076264152fd19fd3847e5392c7958 /tool
parent799de9122e2bd9c2f4cc7e0611f6f8313876ca1d (diff)
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.
Diffstat (limited to 'tool')
-rwxr-xr-xtool/file2lastrev.rb50
1 files changed, 30 insertions, 20 deletions
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