BigW Consortium Gitlab

refs_controller.rb 2.25 KB
Newer Older
1
class Projects::RefsController < Projects::ApplicationController
2
  include ExtractsPath
3
  include TreeHelper
gitlabhq committed
4

5
  before_action :require_non_empty_project
6
  before_action :validate_ref_id
7 8
  before_action :assign_ref_vars
  before_action :authorize_download_code!
gitlabhq committed
9

10 11 12
  def switch
    respond_to do |format|
      format.html do
13 14 15 16 17 18 19 20 21 22
        new_path =
          case params[:destination]
          when "tree"
            namespace_project_tree_path(@project.namespace, @project, @id)
          when "blob"
            namespace_project_blob_path(@project.namespace, @project, @id)
          when "graph"
            namespace_project_network_path(@project.namespace, @project, @id, @options)
          when "graphs"
            namespace_project_graph_path(@project.namespace, @project, @id)
23 24
          when "find_file"
            namespace_project_find_file_path(@project.namespace, @project, @id)
25 26 27 28 29
          when "graphs_commits"
            commits_namespace_project_graph_path(@project.namespace, @project, @id)
          else
            namespace_project_commits_path(@project.namespace, @project, @id)
          end
gitlabhq committed
30

31
        redirect_to new_path
32
      end
33
      format.js do
34 35
        @ref = params[:ref]
        define_tree_vars
36
        tree
37 38 39
        render "tree"
      end
    end
gitlabhq committed
40 41
  end

42
  def logs_tree
43
    @offset = if params[:offset].present?
44 45 46 47
                params[:offset].to_i
              else
                0
              end
48

49
    @limit = 25
50 51 52 53

    @path = params[:path]

    contents = []
54 55 56
    contents.push(*tree.trees)
    contents.push(*tree.blobs)
    contents.push(*tree.submodules)
57 58 59

    @logs = contents[@offset, @limit].to_a.map do |content|
      file = @path ? File.join(@path, content.name) : content.name
60
      last_commit = @repo.last_commit_for_path(@commit.id, file)
61
      {
62
        file_name: content.name,
63
        commit: last_commit
64 65
      }
    end
66

67
    offset = (@offset + @limit)
68 69
    if contents.size > offset
      @more_log_url = logs_file_namespace_project_ref_path(@project.namespace, @project, @ref, @path || '', offset: offset)
70 71
    end

72 73 74 75
    respond_to do |format|
      format.html { render_404 }
      format.js
    end
76
  end
77 78 79 80 81 82

  private

  def validate_ref_id
    return not_found! if params[:id].present? && params[:id] !~ Gitlab::Regex.git_reference_regex
  end
gitlabhq committed
83
end