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

ruby-changes:57623

From: Nobuyoshi <ko1@a...>
Date: Sat, 7 Sep 2019 11:40:22 +0900 (JST)
Subject: [ruby-changes:57623] 71f7b0421a (master): Refined file2lastrev.rb options

https://git.ruby-lang.org/ruby.git/commit/?id=71f7b0421a

From 71f7b0421acff068b94953f4d3f5b4d987ce5350 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
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.

diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb
index 68c660e..9089b7f 100755
--- a/tool/file2lastrev.rb
+++ b/tool/file2lastrev.rb
@@ -22,10 +22,22 @@ end https://github.com/ruby/ruby/blob/trunk/tool/file2lastrev.rb#L22
 @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| https://github.com/ruby/ruby/blob/trunk/tool/file2lastrev.rb#L58
   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 https://github.com/ruby/ruby/blob/trunk/tool/file2lastrev.rb#L110
   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 v0.10.2


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

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