summaryrefslogtreecommitdiff
path: root/tool/file2lastrev.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-17 09:30:54 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-17 09:30:54 +0000
commitc68de8ee083eb80c2e11f019ff1504a60871901f (patch)
tree6f98f4154554d0650a08944016a8b652d4ea5d56 /tool/file2lastrev.rb
parente4820b1cfadbd7cbd5713d774a0bc0db527e479d (diff)
* 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
Diffstat (limited to 'tool/file2lastrev.rb')
-rwxr-xr-xtool/file2lastrev.rb39
1 files changed, 23 insertions, 16 deletions
diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb
index 7f668a2..2965d21 100755
--- a/tool/file2lastrev.rb
+++ b/tool/file2lastrev.rb
@@ -3,9 +3,15 @@
ENV.delete('PWD')
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 NotFoundError < RuntimeError; end
@@ -39,18 +45,19 @@ class VCS
def relative_to(path)
if path
- path = Pathname(path)
- srcdir = @srcdir
- if path.absolute? ^ srcdir.absolute?
- if path.absolute?
- srcdir = srcdir.expand_path
- end
+ 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
- if srcdir.absolute?
- path = path.expand_path
- end
+ ([".."] * list1.length + list2).join("/")
end
- path.relative_path_from(srcdir)
else
'.'
end
@@ -118,18 +125,18 @@ parser = OptionParser.new {|opts|
@suppress_not_found = true
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
vcs = VCS.detect(srcdir)
rescue VCS::NotFoundError => e
- abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
+ abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
else
begin
last, changed = vcs.get_revisions(ARGV.shift)
rescue => e
- abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
+ abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
exit false
end
end