Namespace
- CLASS VCS::GIT
- CLASS VCS::NotFoundError
- CLASS VCS::SVN
Methods
- D
- G
- N
- R
Class Public methods
detect(path)
Link
Source: show
# File tool/vcs.rb, line 20 def self.detect(path) @@dirs.each do |dir, klass| return klass.new(path) if File.directory?(File.join(path, dir)) prev = path loop { curr = File.realpath(File.join(prev, '..')) break if curr == prev # stop at the root directory return klass.new(path) if File.directory?(File.join(curr, dir)) prev = curr } end raise VCS::NotFoundError, "does not seem to be under a vcs: #{path}" end
new(path)
Link
Source: show
# File tool/vcs.rb, line 34 def initialize(path) @srcdir = path super() end
register(dir)
Link
Source: show
# File tool/vcs.rb, line 16 def self.register(dir) @@dirs << [dir, self] end
Instance Public methods
get_revisions(path)
Link
return a pair of strings, the last revision and the last revision in which
path was modified.
Source: show
# File tool/vcs.rb, line 41 def get_revisions(path) path = relative_to(path) last, changed, modified, *rest = Dir.chdir(@srcdir) {self.class.get_revisions(path)} last or raise VCS::NotFoundError, "last revision not found" changed or raise VCS::NotFoundError, "changed revision not found" if modified /\A(\d+)-(\d+)-(\d+)\D(\d+):(\d+):(\d+(?:\.\d+)?)\s*(?:Z|([-+]\d\d)(\d\d))\z/ =~ modified or raise "unknown time format - #{modified}" modified = Time.mktime(*($~[1..6] + [$7 ? "#{$7}:#{$8}" : "+00:00"])) end return last, changed, modified, *rest end
relative_to(path)
Link
Source: show
# File tool/vcs.rb, line 54 def relative_to(path) if path srcdir = File.realpath(@srcdir) path = File.realpath(path) list1 = srcdir.split(%r{/}) list2 = path.split(%r{/}) while !list1.empty? && !list2.empty? && list1.first == list2.first list1.shift list2.shift end if list1.empty? && list2.empty? "." else ([".."] * list1.length + list2).join("/") end else '.' end end