<commit_before>class FilesController < ApplicationController

  helper_method :repository, :ref, :oid, :path, :branch_name
  before_filter :check_permissions, only: [:new, :create]

  # FIXME
  #load_and_authorize_resource :except => [:index, :show]

  def files
    @info = repository.path_info(params[:path], oid)

    raise Repository::FileNotFoundError, path if @info.nil?

    if request.format == 'text/html' || @info[:type] != :file
      case @info[:type]
      when :file
        @file = repository.read_file(path, oid)
      when :file_base
        ontology = repository.ontologies.
                    where(basepath: File.basepath(@info[:entry][:path])).
                    order('id asc').first
        redirect_to [repository, ontology]
      end
    else
      send_download(path, oid)
    end
  end

  def download
    send_download(path, oid)
  end

  def entries_info
    render json: repository.entries_info(oid, path)
  end

  def diff
    @message = repository.commit_message(oid)
    @changed_files = repository.changed_files(oid)
  end

  def history
    @per_page = 25
    page = @page = params[:page].nil? ? 1 : params[:page].to_i
    offset = page > 0 ? (page - 1) * @per_page : 0

    @ontology = repository.primary_ontology(path)

    if repository.empty?
      @commits = []
    else
      @current_file = repository.read_file(path, oid) if path && !repository.dir?(path)
      @commits = repository.commits(start_oid: oid, path: path, offset: offset, limit: @per_page)
    end
  end

  def new
    build_file
  end

  def create
    if build_file.valid?
      repository.save_file @file.file.path, @file.filepath, @file.message, current_user
      flash[:success] = "Successfully saved uploaded file."
      redirect_to fancy_repository_path(repository, path: @file.path)
    else
      render :new
    end
  end

  protected

  def repository
    @repository ||= Repository.find_by_path!(params[:repository_id])
  end

  def ref
    params[:ref] || 'master'
  end

  def build_file
    @file ||= UploadFile.new(params[:upload_file])
  end

  def check_permissions
    authorize! :write, repository
  end

  def send_download(path, oid)
    render text: repository.read_file(path, oid)[:content],
           content_type: Mime::Type.lookup('application/force-download')
  end

  def commit_id
    @commit_id ||= repository.commit_id(params[:ref])
  end

  def oid
    @oid ||= commit_id[:oid]
  end

  def branch_name
    commit_id[:branch_name]
  end

  def path
    params[:path]
  end

end
<commit_msg>remove unneeded fixme comment - already fixed by before filter<commit_after>class FilesController < ApplicationController

  helper_method :repository, :ref, :oid, :path, :branch_name
  before_filter :check_permissions, only: [:new, :create]

  def files
    @info = repository.path_info(params[:path], oid)

    raise Repository::FileNotFoundError, path if @info.nil?

    if request.format == 'text/html' || @info[:type] != :file
      case @info[:type]
      when :file
        @file = repository.read_file(path, oid)
      when :file_base
        ontology = repository.ontologies.
                    where(basepath: File.basepath(@info[:entry][:path])).
                    order('id asc').first
        redirect_to [repository, ontology]
      end
    else
      send_download(path, oid)
    end
  end

  def download
    send_download(path, oid)
  end

  def entries_info
    render json: repository.entries_info(oid, path)
  end

  def diff
    @message = repository.commit_message(oid)
    @changed_files = repository.changed_files(oid)
  end

  def history
    @per_page = 25
    page = @page = params[:page].nil? ? 1 : params[:page].to_i
    offset = page > 0 ? (page - 1) * @per_page : 0

    @ontology = repository.primary_ontology(path)

    if repository.empty?
      @commits = []
    else
      @current_file = repository.read_file(path, oid) if path && !repository.dir?(path)
      @commits = repository.commits(start_oid: oid, path: path, offset: offset, limit: @per_page)
    end
  end

  def new
    build_file
  end

  def create
    if build_file.valid?
      repository.save_file @file.file.path, @file.filepath, @file.message, current_user
      flash[:success] = "Successfully saved uploaded file."
      redirect_to fancy_repository_path(repository, path: @file.path)
    else
      render :new
    end
  end

  protected

  def repository
    @repository ||= Repository.find_by_path!(params[:repository_id])
  end

  def ref
    params[:ref] || 'master'
  end

  def build_file
    @file ||= UploadFile.new(params[:upload_file])
  end

  def check_permissions
    authorize! :write, repository
  end

  def send_download(path, oid)
    render text: repository.read_file(path, oid)[:content],
           content_type: Mime::Type.lookup('application/force-download')
  end

  def commit_id
    @commit_id ||= repository.commit_id(params[:ref])
  end

  def oid
    @oid ||= commit_id[:oid]
  end

  def branch_name
    commit_id[:branch_name]
  end

  def path
    params[:path]
  end

end

{'fraction_non_alphanumeric': 0.1106492478226445, 'fraction_numerical': 0.0023752969121140144, 'mean_word_length': 3.045636509207366, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4650617', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1607, 'n_words': 391}