file2lastrev.rb: Refactor VCS directory search

Search VCS directory after other options are in effective, i.e.,
`--srcdir=nonexitent --suppress_not_found` options, as well as the
reverse order case, should print the current date only and exit
successfully.
This commit is contained in:
Nobuyoshi Nakada 2022-10-12 22:03:35 +09:00
Родитель 70bc8cc6c2
Коммит 80da7250c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7CD2805BFA3770C6
1 изменённых файлов: 8 добавлений и 15 удалений

Просмотреть файл

@ -26,19 +26,11 @@ vcs = nil
OptionParser.new {|opts| OptionParser.new {|opts|
opts.banner << " paths..." opts.banner << " paths..."
vcs_options = VCS.define_options(opts) vcs_options = VCS.define_options(opts)
new_vcs = proc do |path| srcdir = nil
begin
vcs = VCS.detect(path, vcs_options, opts.new)
rescue VCS::NotFoundError => e
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
opts.remove
nil
end
end
opts.new opts.new
opts.on("--srcdir=PATH", "use PATH as source directory") do |path| opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
abort "#{File.basename(Program)}: srcdir is already set" if vcs abort "#{File.basename(Program)}: srcdir is already set" if srcdir
new_vcs[path] srcdir = path
end end
opts.on("--changed", "changed rev") do opts.on("--changed", "changed rev") do
self.output = :changed self.output = :changed
@ -60,10 +52,11 @@ OptionParser.new {|opts|
@suppress_not_found = true @suppress_not_found = true
end end
opts.order! rescue abort "#{File.basename(Program)}: #{$!}\n#{opts}" opts.order! rescue abort "#{File.basename(Program)}: #{$!}\n#{opts}"
if vcs begin
vcs.set_options(vcs_options) # options after --srcdir vcs = VCS.detect(srcdir || ".", vcs_options, opts.new)
elsif new_vcs["."] rescue VCS::NotFoundError => e
else @suppress_not_found abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
opts.remove
(vcs = VCS::Null.new(nil)).set_options(vcs_options) (vcs = VCS::Null.new(nil)).set_options(vcs_options)
end end
} }