~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to tool/file2lastrev.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
ENV.delete('PWD')
4
4
 
5
5
require 'optparse'
6
 
require 'pathname'
7
 
 
8
 
Program = Pathname($0)
 
6
 
 
7
unless File.respond_to? :realpath
 
8
  require 'pathname'
 
9
  def File.realpath(arg)
 
10
    Pathname(arg).realpath.to_s
 
11
  end
 
12
end
 
13
 
 
14
Program = $0
9
15
 
10
16
class VCS
11
17
  class NotFoundError < RuntimeError; end
39
45
 
40
46
  def relative_to(path)
41
47
    if path
42
 
      path = Pathname(path)
43
 
      srcdir = @srcdir
44
 
      if path.absolute? ^ srcdir.absolute?
45
 
        if path.absolute?
46
 
          srcdir = srcdir.expand_path
47
 
        end
 
48
      srcdir = File.realpath(@srcdir)
 
49
      path = File.realpath(path)
 
50
      list1 = srcdir.split(%r{/})
 
51
      list2 = path.split(%r{/})
 
52
      while !list1.empty? && !list2.empty? && list1.first == list2.first
 
53
        list1.shift
 
54
        list2.shift
 
55
      end
 
56
      if list1.empty? && list2.empty?
 
57
        "."
48
58
      else
49
 
        if srcdir.absolute?
50
 
          path = path.expand_path
51
 
        end
 
59
        ([".."] * list1.length + list2).join("/")
52
60
      end
53
 
      path.relative_path_from(srcdir)
54
61
    else
55
62
      '.'
56
63
    end
118
125
    @suppress_not_found = true
119
126
  end
120
127
}
121
 
parser.parse! rescue abort "#{Program.basename}: #{$!}\n#{parser}"
 
128
parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}"
122
129
 
123
 
srcdir = (srcdir ? Pathname(srcdir) : Program.parent.parent).freeze
 
130
srcdir = srcdir ? srcdir : File.dirname(File.dirname(Program))
124
131
begin
125
132
  vcs = VCS.detect(srcdir)
126
133
rescue VCS::NotFoundError => e
127
 
  abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
 
134
  abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
128
135
else
129
136
  begin
130
137
    last, changed = vcs.get_revisions(ARGV.shift)
131
138
  rescue => e
132
 
    abort "#{Program.basename}: #{e.message}" unless @suppress_not_found
 
139
    abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
133
140
    exit false
134
141
  end
135
142
end