mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* tool/file2lastrev.rb: don't depend on pathname.rb if File.realpath
is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e4820b1cfa
commit
c68de8ee08
2 changed files with 29 additions and 17 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Jul 17 18:30:05 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* tool/file2lastrev.rb: don't depend on pathname.rb if File.realpath
|
||||||
|
is available.
|
||||||
|
|
||||||
Sat Jul 17 14:10:20 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sat Jul 17 14:10:20 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* util.c (ruby_add_suffix): fixed type warnings.
|
* util.c (ruby_add_suffix): fixed type warnings.
|
||||||
|
|
|
@ -3,9 +3,15 @@
|
||||||
ENV.delete('PWD')
|
ENV.delete('PWD')
|
||||||
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
require 'pathname'
|
|
||||||
|
|
||||||
Program = Pathname($0)
|
unless File.respond_to? :realpath
|
||||||
|
require 'pathname'
|
||||||
|
def File.realpath(arg)
|
||||||
|
Pathname(arg).realpath.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Program = $0
|
||||||
|
|
||||||
class VCS
|
class VCS
|
||||||
class NotFoundError < RuntimeError; end
|
class NotFoundError < RuntimeError; end
|
||||||
|
@ -39,18 +45,19 @@ class VCS
|
||||||
|
|
||||||
def relative_to(path)
|
def relative_to(path)
|
||||||
if path
|
if path
|
||||||
path = Pathname(path)
|
srcdir = File.realpath(@srcdir)
|
||||||
srcdir = @srcdir
|
path = File.realpath(path)
|
||||||
if path.absolute? ^ srcdir.absolute?
|
list1 = srcdir.split(%r{/})
|
||||||
if path.absolute?
|
list2 = path.split(%r{/})
|
||||||
srcdir = srcdir.expand_path
|
while !list1.empty? && !list2.empty? && list1.first == list2.first
|
||||||
|
list1.shift
|
||||||
|
list2.shift
|
||||||
end
|
end
|
||||||
|
if list1.empty? && list2.empty?
|
||||||
|
"."
|
||||||
else
|
else
|
||||||
if srcdir.absolute?
|
([".."] * list1.length + list2).join("/")
|
||||||
path = path.expand_path
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
path.relative_path_from(srcdir)
|
|
||||||
else
|
else
|
||||||
'.'
|
'.'
|
||||||
end
|
end
|
||||||
|
@ -118,18 +125,18 @@ parser = OptionParser.new {|opts|
|
||||||
@suppress_not_found = true
|
@suppress_not_found = true
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
parser.parse! rescue abort "#{Program.basename}: #{$!}\n#{parser}"
|
parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}"
|
||||||
|
|
||||||
srcdir = (srcdir ? Pathname(srcdir) : Program.parent.parent).freeze
|
srcdir = srcdir ? srcdir : File.dirname(File.dirname(Program))
|
||||||
begin
|
begin
|
||||||
vcs = VCS.detect(srcdir)
|
vcs = VCS.detect(srcdir)
|
||||||
rescue VCS::NotFoundError => e
|
rescue VCS::NotFoundError => e
|
||||||
abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
last, changed = vcs.get_revisions(ARGV.shift)
|
last, changed = vcs.get_revisions(ARGV.shift)
|
||||||
rescue => e
|
rescue => e
|
||||||
abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
||||||
exit false
|
exit false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue