From f798ff4c43fc8cf7b00bd770d7eb78c0af664eee Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 10 Dec 2018 01:58:28 +0000 Subject: Limit uplevel travarsing * tool/vcs.rb (VCS.detect): limit level of travarsing parent directories, 0 by the default. curretly always detecting at the source directory itself. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/vcs.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tool') diff --git a/tool/vcs.rb b/tool/vcs.rb index db3e5cf4bc..b97334ecfb 100644 --- a/tool/vcs.rb +++ b/tool/vcs.rb @@ -124,12 +124,16 @@ class VCS @@dirs << [dir, self, pred] end - def self.detect(path) + def self.detect(path, uplevel_limit: 0) curr = path begin @@dirs.each do |dir, klass, pred| return klass.new(curr) if pred ? pred[curr, dir] : File.directory?(File.join(curr, dir)) end + if uplevel_limit + break if uplevel_limit.zero? + uplevel_limit -= 1 + end prev, curr = curr, File.realpath(File.join(curr, '..')) end until curr == prev # stop at the root directory raise VCS::NotFoundError, "does not seem to be under a vcs: #{path}" -- cgit v1.2.3