2013-06-23 16:47:22 +00:00
|
|
|
class Projects::RefsController < Projects::ApplicationController
|
2013-04-14 12:08:16 +00:00
|
|
|
include ExtractsPath
|
2015-07-26 09:17:34 +00:00
|
|
|
include TreeHelper
|
2011-11-16 05:38:53 +00:00
|
|
|
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
2015-10-13 04:43:24 +00:00
|
|
|
before_action :validate_ref_id
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :assign_ref_vars
|
|
|
|
before_action :authorize_download_code!
|
2011-11-16 05:38:53 +00:00
|
|
|
|
2012-10-09 19:09:46 +00:00
|
|
|
def switch
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2015-07-02 18:12:24 +00:00
|
|
|
new_path =
|
|
|
|
case params[:destination]
|
|
|
|
when "tree"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_tree_path(@project, @id)
|
2015-07-02 18:12:24 +00:00
|
|
|
when "blob"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_blob_path(@project, @id)
|
2015-07-02 18:12:24 +00:00
|
|
|
when "graph"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_network_path(@project, @id, @options)
|
2015-07-02 18:12:24 +00:00
|
|
|
when "graphs"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_graph_path(@project, @id)
|
2016-01-07 11:56:18 +00:00
|
|
|
when "find_file"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_find_file_path(@project, @id)
|
2015-07-02 18:12:24 +00:00
|
|
|
when "graphs_commits"
|
2017-06-29 17:06:35 +00:00
|
|
|
commits_project_graph_path(@project, @id)
|
2016-04-04 08:40:40 +00:00
|
|
|
when "badges"
|
2017-06-29 17:06:35 +00:00
|
|
|
project_pipelines_settings_path(@project, ref: @id)
|
2015-07-02 18:12:24 +00:00
|
|
|
else
|
2017-06-29 17:06:35 +00:00
|
|
|
project_commits_path(@project, @id)
|
2015-07-02 18:12:24 +00:00
|
|
|
end
|
2011-11-16 17:19:18 +00:00
|
|
|
|
2012-09-17 17:49:57 +00:00
|
|
|
redirect_to new_path
|
2012-01-29 19:30:03 +00:00
|
|
|
end
|
|
|
|
end
|
2011-11-16 17:19:18 +00:00
|
|
|
end
|
|
|
|
|
2012-07-10 19:52:38 +00:00
|
|
|
def logs_tree
|
2014-06-12 09:01:54 +00:00
|
|
|
@offset = if params[:offset].present?
|
2015-02-03 05:38:50 +00:00
|
|
|
params[:offset].to_i
|
|
|
|
else
|
|
|
|
0
|
|
|
|
end
|
2014-06-12 09:01:54 +00:00
|
|
|
|
2014-06-26 07:29:39 +00:00
|
|
|
@limit = 25
|
2014-06-12 09:01:54 +00:00
|
|
|
|
|
|
|
@path = params[:path]
|
|
|
|
|
|
|
|
contents = []
|
2014-10-09 07:47:47 +00:00
|
|
|
contents.push(*tree.trees)
|
|
|
|
contents.push(*tree.blobs)
|
|
|
|
contents.push(*tree.submodules)
|
2014-06-12 09:01:54 +00:00
|
|
|
|
2017-09-19 10:55:37 +00:00
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37433
|
|
|
|
@logs = Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
contents[@offset, @limit].to_a.map do |content|
|
|
|
|
file = @path ? File.join(@path, content.name) : content.name
|
|
|
|
last_commit = @repo.last_commit_for_path(@commit.id, file)
|
2017-11-06 10:51:44 +00:00
|
|
|
commit_path = project_commit_path(@project, last_commit) if last_commit
|
2017-09-19 10:55:37 +00:00
|
|
|
{
|
|
|
|
file_name: content.name,
|
2017-11-01 16:08:06 +00:00
|
|
|
commit: last_commit,
|
2017-11-02 16:07:01 +00:00
|
|
|
type: content.type,
|
2017-11-06 10:51:44 +00:00
|
|
|
commit_path: commit_path
|
2017-09-19 10:55:37 +00:00
|
|
|
}
|
|
|
|
end
|
2012-07-10 19:52:38 +00:00
|
|
|
end
|
2015-04-07 03:02:06 +00:00
|
|
|
|
2016-02-23 13:41:03 +00:00
|
|
|
offset = (@offset + @limit)
|
2016-02-23 09:06:26 +00:00
|
|
|
if contents.size > offset
|
2017-06-29 17:06:35 +00:00
|
|
|
@more_log_url = logs_file_project_ref_path(@project, @ref, @path || '', offset: offset)
|
2015-07-26 09:17:34 +00:00
|
|
|
end
|
|
|
|
|
2015-04-07 03:02:06 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render_404 }
|
2017-11-01 16:08:06 +00:00
|
|
|
format.json do
|
2017-11-02 16:07:01 +00:00
|
|
|
response.headers["More-Logs-Url"] = @more_log_url
|
2017-11-01 16:08:06 +00:00
|
|
|
|
|
|
|
render json: @logs
|
|
|
|
end
|
2015-04-07 03:02:06 +00:00
|
|
|
format.js
|
|
|
|
end
|
2012-07-10 19:52:38 +00:00
|
|
|
end
|
2015-10-13 04:43:24 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_ref_id
|
2017-05-24 20:59:26 +00:00
|
|
|
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
|
2015-10-13 04:43:24 +00:00
|
|
|
end
|
2011-11-16 05:38:53 +00:00
|
|
|
end
|