Sha256: 74dec3327cadc48f3ae0526f89469553d8a021094e9f4e75142465e640f8267e

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module OhlohScm::Adapters
  class GitSvnAdapter < AbstractAdapter
    def commit_count(opts={})
      cmd = "#{after_revision(opts)} | wc -l"
      git_svn_log(cmd: cmd, oneline: true).to_i
    end

    def commits(opts={})
      parsed_commits = []
      open_log_file(opts) do |io|
        parsed_commits = OhlohScm::Parsers::SvnParser.parse(io)
      end
      parsed_commits
    end

    def commit_tokens(opts={})
      cmd = "#{after_revision(opts)} | #{extract_revision_number}"
      git_svn_log(cmd: cmd, oneline: false).split
        .map(&:to_i)
    end

    def each_commit(opts={})
      commits(opts).each do |commit|
        yield commit
      end
    end

    private

    def open_log_file(opts={})
      cmd = "-v #{ after_revision(opts) } | #{string_encoder} > #{log_filename}"
      git_svn_log(cmd: cmd, oneline: false)
      File.open(log_filename, 'r') { |io| yield io }
    end

    def log_filename
      File.join('/tmp', url.gsub(/\W/,'') + '.log')
    end

    def after_revision(opts)
      next_token = opts[:after].to_i + 1
      next_head_token = head_token.to_i + 1
      "-r#{ next_token }:#{ next_head_token }"
    end

    def extract_revision_number
      "grep '^r[0-9].*|' | awk -F'|' '{print $1}' | cut -c 2-"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ohloh_scm-2.4.3 lib/ohloh_scm/adapters/git_svn/commits.rb
ohloh_scm-2.4.1 lib/ohloh_scm/adapters/git_svn/commits.rb
ohloh_scm-2.4.0 lib/ohloh_scm/adapters/git_svn/commits.rb