<commit_before>class DownloadGitRevision
  unloadable

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

  attr_reader :commit_valid
  attr_reader :commit_id
  attr_reader :content_type
  attr_reader :filename


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

    @commit_valid  = false
    @commit_id     = nil
    @content_type  = ''
    @filename      = ''

    validate_revision
    fill_data
  end


  def content
    repository.archive(commit_id, format)
  end


  private


    def validate_revision
      commit = nil

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

      # is the revision a tag?
      if commit.nil?
        repository.tags.each do |x|
          if x == revision
            commit = repository.rev_list(revision).first
            break
          end
        end
      end

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

      valid_commit = repository.rev_parse(commit)

      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'
      when 'tar.gz' then
        extension     = 'tar.gz'
        @content_type = 'application/x-gzip'
      when 'zip' then
        extension     = 'zip'
        @content_type = 'application/x-zip'
      end
      @filename = "#{project_name}-#{revision}.#{extension}"
    end

end<commit_msg>Fix archive name in DownloadGitRevision<commit_after>class DownloadGitRevision
  unloadable

  attr_reader :repository
  attr_reader :revision
  attr_reader :format
  attr_reader :gitolite_repository_path

  attr_reader :commit_valid
  attr_reader :commit_id
  attr_reader :content_type
  attr_reader :filename


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

    @commit_valid  = false
    @commit_id     = nil
    @content_type  = ''
    @filename      = ''

    validate_revision
    fill_data
  end


  def content
    repository.archive(commit_id, format)
  end


  private


    def validate_revision
      commit = nil

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

      # is the revision a tag?
      if commit.nil?
        repository.tags.each do |x|
          if x == revision
            commit = repository.rev_list(revision).first
            break
          end
        end
      end

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

      valid_commit = repository.rev_parse(commit)

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


    def fill_data
      case format
      when 'tar' then
        extension     = 'tar'
        @content_type = 'application/x-tar'
      when 'tar.gz' then
        extension     = 'tar.gz'
        @content_type = 'application/x-gzip'
      when 'zip' then
        extension     = 'zip'
        @content_type = 'application/x-zip'
      end
      @filename = "#{repository.redmine_name}-#{revision}.#{extension}"
    end

end
{'fraction_non_alphanumeric': 0.07319561336393778, 'fraction_numerical': 0.0002550369803621525, 'mean_word_length': 2.073667711598746, 'pattern_counts': {'":': 0, '<': 3, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3502742', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1131, 'n_words': 296}