summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2011-10-14 19:30:31 +0300
committerDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2011-10-14 19:30:31 +0300
commit06ba82817602532c50c139e12efbef2a7ed84905 (patch)
tree52efd9c0ca3be5ee5e36a720e599b0f4a72390ee /app/controllers
parentf51a401613a9bf0f71ef5012705dc6938b3ec275 (diff)
downloadgitlab-ce-06ba82817602532c50c139e12efbef2a7ed84905.tar.gz
refactoring + remove unnecessary feature
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application_controller.rb28
-rw-r--r--app/controllers/commits_controller.rb14
-rw-r--r--app/controllers/projects_controller.rb21
3 files changed, 31 insertions, 32 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 8d308767374..f8eb238b1d2 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -42,15 +42,23 @@ class ApplicationController < ActionController::Base
end
end
- def refs_from_cookie
- if @project && session[:ui] &&
- session[:ui][@project.id]
- project_session = session[:ui][@project.id]
- project_session[:branch] = nil if params[:tag]
- params[:branch] ||= project_session[:branch]
- params[:tag] ||= project_session[:tag]
- end
- rescue
- session[:ui] = nil
+ def load_refs
+ @branch = unless params[:branch].blank?
+ params[:branch]
+ else
+ nil
+ end
+
+ @tag = unless params[:tag].blank?
+ params[:tag]
+ else
+ nil
+ end
+
+ @ref = @branch || @tag || "master"
+ end
+
+ def render_404
+ render :file => File.join(Rails.root, "public", "404"), :layout => false, :status => "404"
end
end
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 61a1a54f84d..fe46ddcefb7 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -8,20 +8,14 @@ class CommitsController < ApplicationController
before_filter :authorize_read_project!
def index
- refs_from_cookie
+ load_refs # load @branch, @tag & @ref
+
@repo = project.repo
- @branch = if !params[:branch].blank?
- params[:branch]
- elsif !params[:tag].blank?
- params[:tag]
- else
- "master"
- end
if params[:path]
- @commits = @repo.log(@branch, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0)
+ @commits = @repo.log(@ref, params[:path], :max_count => params[:limit] || 100, :skip => params[:offset] || 0)
else
- @commits = @repo.commits(@branch, params[:limit] || 100, params[:offset] || 0)
+ @commits = @repo.commits(@ref, params[:limit] || 100, params[:offset] || 0)
end
respond_to do |format|
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index f9f4226f6f0..09856803e78 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -16,7 +16,6 @@ class ProjectsController < ApplicationController
end
def show
- refs_from_cookie
@repo = project.repo
@commit = @repo.commits.first
@tree = @commit.tree
@@ -33,34 +32,30 @@ class ProjectsController < ApplicationController
end
def tree
- refs_from_cookie
+ load_refs # load @branch, @tag & @ref
+
@repo = project.repo
- @branch = if !params[:branch].blank?
- params[:branch]
- elsif !params[:tag].blank?
- params[:tag]
- else
- "master"
- end
if params[:commit_id]
@commit = @repo.commits(params[:commit_id]).first
else
- @commit = @repo.commits(@branch || "master").first
+ @commit = @repo.commits(@ref || "master").first
end
+
@tree = @commit.tree
@tree = @tree / params[:path] if params[:path]
respond_to do |format|
format.html # show.html.erb
format.js do
- # temp solution
+ # diasbale cache to allow back button works
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
- format.json { render json: project }
end
+ rescue
+ return render_404
end
def blob
@@ -73,6 +68,8 @@ class ProjectsController < ApplicationController
else
head(404)
end
+ rescue
+ return render_404
end
def new