Sha256: 642ad9b3e198c6598cb8b72b686a2193b0a7e0c20d6bc175e4cf8ed5296b6e3a

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

require 'uri'
require 'thread'
require 'open3'

module ASF

  class SVN
    @base = URI.parse('https://svn.apache.org/repos/')
    @mock = 'file:///var/tools/svnrep/'
    @semaphore = Mutex.new
    @testdata = {}

    def self.repos
      @semaphore.synchronize do
        svn = ASF::Config.get(:svn).map {|dir| dir.untaint}
        @repos ||= Hash[Dir[*svn].map { |name| 
          Dir.chdir name.untaint do
            out, err, status = Open3.capture3('svn', 'info')
            if status.success?
              [out[/URL: (.*)/,1].sub(/^http:/,'https:'), Dir.pwd.untaint]
            end
          end
        }.compact]
      end
    end

    def self.[]=(name, path)
      @testdata[name] = File.expand_path(path).untaint
    end

    def self.[](name)
      return @testdata[name] if @testdata[name]

      result = repos[(@mock+name.sub('private/','')).to_s.sub(/\/*$/, '')] ||
        repos[(@base+name).to_s.sub(/\/*$/, '')] # lose trailing slash

      return result if result

      # recursively try parent directory
      if name.include? '/'
        base = File.basename(name)
        result = self[File.dirname(name)]
        if result and File.exist?(File.join(result, base))
          File.join(result, base)
        end
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
whimsy-asf-0.0.74 lib/whimsy/asf/svn.rb
whimsy-asf-0.0.73 lib/whimsy/asf/svn.rb
whimsy-asf-0.0.72 lib/whimsy/asf/svn.rb
whimsy-asf-0.0.71 lib/whimsy/asf/svn.rb
whimsy-asf-0.0.70 lib/whimsy/asf/svn.rb