<commit_before>class DownloadGitRevision
  unloadable

  attr_reader :commit_valid
  attr_reader :content_type
  attr_reader :filename


  def initialize(repository, revision, format)
    @repository = repository
    @revision   = revision
    @format     = format
    @project    = repository.project

    @commit_valid  = false
    @commit_id     = ''
    @content_type  = ''
    @filename      = ''
    @cmd_args      = []

    validate_revision
    fill_data
  end


  def content
    RedmineGitHosting::Commands.sudo_git_archive(@repository.gitolite_repository_path, @commit_id, @cmd_args)
  end


  private


    def validate_revision
      commit_id = nil

      # is the revision a branch?
      @repository.branches.each do |x|
        if x.to_s == @revision
          commit_id = x.revision
          break
        end
      end

      # is the revision a tag?
      if commit_id.nil?
        tags = RedmineGitHosting::Commands.sudo_git_tag(@repository.gitolite_repository_path)
        tags.each do |x|
          if x == @revision
            commit_id = RedmineGitHosting::Commands.sudo_git_rev_list(@repository.gitolite_repository_path, @revision).split[0]
            break
          end
        end
      end

      # well, let check if this is a valid commit_id
      if commit_id.nil?
        commit_id = @revision
      end

      valid_commit = RedmineGitHosting::Commands.sudo_git_rev_parse(@repository.gitolite_repository_path, commit_id, ['--quiet', '--verify'])

      if valid_commit == ''
        @commit_valid = false
      else
        @commit_valid = true
        @commit_id = valid_commit
      end
    end


    def fill_data
      project_name = @project.to_s.parameterize.to_s
      project_name = "tarball" if project_name.length == 0

      case @format
        when 'tar' then
          extension     = 'tar'
          @content_type = 'application/x-tar'
          @cmd_args << "--format=tar"

        when 'tar.gz' then
          extension     = 'tar.gz'
          @content_type = 'application/x-gzip'
          @cmd_args << "--format=tar.gz"
          @cmd_args << "-7"

        when 'zip' then
          extension     = 'zip'
          @content_type = 'application/x-zip'
          @cmd_args << "--format=zip"
          @cmd_args << "-7"
      end

      @filename = "#{project_name}-#{@revision}.#{extension}"
    end

end<commit_msg>Add attr_reader for params<commit_after>class DownloadGitRevision
  unloadable

  attr_reader :repository
  attr_reader :revision
  attr_reader :format
  attr_reader :project

  attr_reader :commit_valid
  attr_reader :content_type
  attr_reader :filename


  def initialize(repository, revision, format)
    @repository = repository
    @revision   = revision
    @format     = format
    @project    = repository.project

    @commit_valid  = false
    @commit_id     = ''
    @content_type  = ''
    @filename      = ''
    @cmd_args      = []

    validate_revision
    fill_data
  end


  def content
    RedmineGitHosting::Commands.sudo_git_archive(repository.gitolite_repository_path, @commit_id, @cmd_args)
  end


  private


    def validate_revision
      commit_id = nil

      # is the revision a branch?
      repository.branches.each do |x|
        if x.to_s == revision
          commit_id = x.revision
          break
        end
      end

      # is the revision a tag?
      if commit_id.nil?
        tags = RedmineGitHosting::Commands.sudo_git_tag(repository.gitolite_repository_path)
        tags.each do |x|
          if x == revision
            commit_id = RedmineGitHosting::Commands.sudo_git_rev_list(repository.gitolite_repository_path, revision).split[0]
            break
          end
        end
      end

      # well, let check if this is a valid commit_id
      if commit_id.nil?
        commit_id = revision
      end

      valid_commit = RedmineGitHosting::Commands.sudo_git_rev_parse(repository.gitolite_repository_path, commit_id, ['--quiet', '--verify'])

      if valid_commit == ''
        @commit_valid = false
      else
        @commit_valid = true
        @commit_id = valid_commit
      end
    end


    def fill_data
      project_name = project.to_s.parameterize.to_s
      project_name = "tarball" if project_name.length == 0

      case format
        when 'tar' then
          extension     = 'tar'
          @content_type = 'application/x-tar'
          @cmd_args << "--format=tar"

        when 'tar.gz' then
          extension     = 'tar.gz'
          @content_type = 'application/x-gzip'
          @cmd_args << "--format=tar.gz"
          @cmd_args << "-7"

        when 'zip' then
          extension     = 'zip'
          @content_type = 'application/x-zip'
          @cmd_args << "--format=zip"
          @cmd_args << "-7"
      end

      @filename = "#{project_name}-#{revision}.#{extension}"
    end

end
{'fraction_non_alphanumeric': 0.0933305802188726, 'fraction_numerical': 0.001651868676440223, 'mean_word_length': 2.1071199486850545, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '655078', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1460, 'n_words': 322}