class OhlohScm::Svn::Activity
Public Instance Methods
Source
# File lib/ohloh_scm/svn/activity.rb, line 27 def export(dest_dir, commit_id = 'HEAD') FileUtils.mkdir_p(File.dirname(dest_dir)) unless File.exist?(File.dirname(dest_dir)) run 'svn export --trust-server-cert --non-interactive --ignore-externals --force '\ "-r #{commit_id} '#{uri_encode(File.join(root.to_s, scm.branch_name.to_s))}'"\ " '#{dest_dir}'" end
Source
# File lib/ohloh_scm/svn/activity.rb, line 34 def export_tag(dest_dir, tag_name) tag_url = "#{base_path}/tags/#{tag_name}" run 'svn export --trust-server-cert --non-interactive --ignore-externals --force'\ " '#{tag_url}' '#{dest_dir}'" end
Source
# File lib/ohloh_scm/svn/activity.rb, line 58 def head_token return unless info =~ /^Revision: (\d+)$/ Regexp.last_match(1).to_i end
rubocop:enable Metrics/AbcSize
Source
# File lib/ohloh_scm/svn/activity.rb, line 18 def ls(path = nil, revision = 'HEAD') stdout = run "svn ls --trust-server-cert --non-interactive -r #{revision} "\ "#{username_and_password_opts} "\ "'#{uri_encode(File.join(root.to_s, scm.branch_name.to_s, path.to_s))}@#{revision}'" collect_files(stdout) rescue StandardError => e logger.error(e.message) && nil end
Source
# File lib/ohloh_scm/svn/activity.rb, line 8 def root Regexp.last_match(1) if info =~ /^Repository Root: (.+)$/ end
Source
# File lib/ohloh_scm/svn/activity.rb, line 12 def username_and_password_opts(source_scm = scm) username = source_scm.username.to_s.empty? ? '' : "--username #{source_scm.username}" password = source_scm.password.to_s.empty? ? '' : "--password='#{source_scm.password}'" "#{username} #{password}" end
Private Instance Methods
Source
# File lib/ohloh_scm/svn/activity.rb, line 90 def base_path url.sub(/(.*)(branches|trunk|tags)(.*)/, '\1').chomp('/') end
Source
# File lib/ohloh_scm/svn/activity.rb, line 66 def collect_files(stdout) stdout.split("\n").map do |line| # CVSROOT/ is found in cvs repos converted to svn. line.chomp unless line.chomp.empty? || line == 'CVSROOT/' end.compact.sort end
Source
# File lib/ohloh_scm/svn/activity.rb, line 73 def info(path = nil, revision = 'HEAD') @info ||= {} uri = path ? File.join(root, scm.branch_name.to_s, path) : url @info[[path, revision]] ||= run 'svn info --trust-server-cert --non-interactive -r '\ "#{revision} #{username_and_password_opts} '#{uri_encode(uri)}@#{revision}'" end
Source
# File lib/ohloh_scm/svn/activity.rb, line 81 def uri_encode(uri) # URI.encode is declared obsolete, however we couldn't find an alternative. # URI.encode('foo bar') => foo%20bar # `svn log svn://...foo%20bar` works. # CGI.escape('foo bar') => foo+bar # `svn log svn://...foo+bar` won't work. # rubocop:disable Lint/UriEscapeUnescape URI.encode(uri) # rubocop:enable Lint/UriEscapeUnescape end
Because uri(with branch) may have characters(e.g. space) that break the shell command.