summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-09-17 13:49:57 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-09-26 16:32:22 -0400
commit576cec6c67dcc4ee00b8220ca1a45385583e25b2 (patch)
tree3fc61345a7a2ec716dbed39fd4916a8f2d3f9dc4 /app
parent39c657930625ddc3ac8a921f01ffc83acadce68f (diff)
downloadgitlab-ce-576cec6c67dcc4ee00b8220ca1a45385583e25b2.tar.gz
Add BlobController, remove Refs#blob
Diffstat (limited to 'app')
-rw-r--r--app/controllers/blob_controller.rb62
-rw-r--r--app/controllers/refs_controller.rb49
-rw-r--r--app/views/blame/show.html.haml2
-rw-r--r--app/views/commits/_diffs.html.haml2
-rw-r--r--app/views/tree/_tree_file.html.haml6
5 files changed, 75 insertions, 46 deletions
diff --git a/app/controllers/blob_controller.rb b/app/controllers/blob_controller.rb
new file mode 100644
index 00000000000..bb051281013
--- /dev/null
+++ b/app/controllers/blob_controller.rb
@@ -0,0 +1,62 @@
+# Controller for viewing a file's blame
+class BlobController < ApplicationController
+ # Thrown when given an invalid path
+ class InvalidPathError < StandardError; end
+
+ include RefExtractor
+ include Gitlab::Encode
+
+ layout "project"
+
+ before_filter :project
+
+ # Authorize
+ before_filter :add_project_abilities
+ before_filter :authorize_read_project!
+ before_filter :authorize_code_access!
+ before_filter :require_non_empty_project
+
+ before_filter :define_tree_vars
+
+ def show
+ if @tree.is_blob?
+ if @tree.text?
+ encoding = detect_encoding(@tree.data)
+ mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
+ else
+ mime_type = @tree.mime_type
+ end
+
+ send_data(
+ @tree.data,
+ type: mime_type,
+ disposition: 'inline',
+ filename: @tree.name
+ )
+ else
+ not_found!
+ end
+ end
+
+ private
+
+ def define_tree_vars
+ @ref, @path = extract_ref(params[:id])
+
+ @id = File.join(@ref, @path)
+ @repo = @project.repo
+ @commit = CommitDecorator.decorate(@project.commit(@ref))
+
+ @tree = Tree.new(@commit.tree, @project, @ref, @path)
+ @tree = TreeDecorator.new(@tree)
+
+ raise InvalidPathError if @tree.invalid?
+
+ @hex_path = Digest::SHA1.hexdigest(@path)
+
+ @history_path = project_tree_path(@project, @id)
+ @logs_path = logs_file_project_ref_path(@project, @ref, @path)
+ rescue NoMethodError, InvalidPathError
+ not_found!
+ end
+end
diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb
index 334dfc7f0cf..f9cd4734d50 100644
--- a/app/controllers/refs_controller.rb
+++ b/app/controllers/refs_controller.rb
@@ -18,14 +18,14 @@ class RefsController < ApplicationController
respond_to do |format|
format.html do
new_path = if params[:destination] == "tree"
- project_tree_path(@project, params[:ref])
+ project_tree_path(@project, @ref)
else
- project_commits_path(@project, ref: params[:ref])
+ project_commits_path(@project, ref: @ref)
end
- redirect_to new_path
+ redirect_to new_path
end
- format.js do
+ format.js do
@ref = params[:ref]
define_tree_vars
render "tree"
@@ -33,19 +33,6 @@ class RefsController < ApplicationController
end
end
- #
- # Repository preview
- #
- def tree
- respond_to do |format|
- format.html
- format.js do
- # disable cache to allow back button works
- no_cache_headers
- end
- end
- end
-
def logs_tree
contents = @tree.contents
@logs = contents.map do |content|
@@ -53,32 +40,12 @@ class RefsController < ApplicationController
last_commit = @project.commits(@commit.id, file, 1).last
last_commit = CommitDecorator.decorate(last_commit)
{
- file_name: content.name,
+ file_name: content.name,
commit: last_commit
}
end
end
- def blob
- if @tree.is_blob?
- if @tree.text?
- encoding = detect_encoding(@tree.data)
- mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
- else
- mime_type = @tree.mime_type
- end
-
- send_data(
- @tree.data,
- type: mime_type,
- disposition: 'inline',
- filename: @tree.name
- )
- else
- head(404)
- end
- end
-
protected
def define_tree_vars
@@ -93,15 +60,15 @@ class RefsController < ApplicationController
if params[:path]
@history_path = project_tree_path(@project, File.join(@ref, params[:path]))
- @logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
+ @logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
else
@history_path = project_tree_path(@project, @ref)
- @logs_path = logs_tree_project_ref_path(@project, @ref)
+ @logs_path = logs_tree_project_ref_path(@project, @ref)
end
rescue
return render_404
end
-
+
def ref
@ref = params[:id]
end
diff --git a/app/views/blame/show.html.haml b/app/views/blame/show.html.haml
index 0b2f93bea2b..12b4e66884e 100644
--- a/app/views/blame/show.html.haml
+++ b/app/views/blame/show.html.haml
@@ -18,7 +18,7 @@
= @tree.name
%small blame
%span.options
- = link_to "raw", blob_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small", target: "_blank"
+ = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank"
= link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small"
= link_to "source", project_tree_path(@project, @id), class: "btn very_small"
.file_content.blame
diff --git a/app/views/commits/_diffs.html.haml b/app/views/commits/_diffs.html.haml
index bc53911cb7c..301cd554b42 100644
--- a/app/views/commits/_diffs.html.haml
+++ b/app/views/commits/_diffs.html.haml
@@ -24,7 +24,7 @@
%i.icon-file
%span{id: "#{diff.old_path}"}= diff.old_path
- else
- = link_to project_tree_path(@project, @commit, diff.new_path) do
+ = link_to project_tree_path(@project, tree_join(@commit.id, diff.new_path)) do
%i.icon-file
%span{id: "#{diff.new_path}"}= diff.new_path
%br/
diff --git a/app/views/tree/_tree_file.html.haml b/app/views/tree/_tree_file.html.haml
index 052172be008..b4c4566b429 100644
--- a/app/views/tree/_tree_file.html.haml
+++ b/app/views/tree/_tree_file.html.haml
@@ -5,8 +5,8 @@
= name.force_encoding('utf-8')
%small #{file.mode}
%span.options
- = link_to "raw", blob_project_ref_path(@project, @ref, path: @path), class: "btn very_small", target: "_blank"
- = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small"
+ = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank"
+ = link_to "history", project_commits_path(@project, path: @path, ref: @ref), class: "btn very_small"
= link_to "blame", project_blame_path(@project, @id), class: "btn very_small"
- if file.text?
- if gitlab_markdown?(name)
@@ -32,7 +32,7 @@
- else
.file_content.blob_file
%center
- = link_to blob_project_ref_path(@project, @ref, path: params[:path]) do
+ = link_to project_blob_path(@project, @id) do
%div.padded
%br
= image_tag "download.png", width: 64