mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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.
This commit is contained in:
parent
799de9122e
commit
71f7b0421a
1 changed files with 30 additions and 20 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue