summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-15 15:06:12 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-15 15:06:12 +0200
commitf19cdee8cc1e85066154d008ee2653d845c9f3cd (patch)
tree3a9845a6e961903632475a4e3384d425d4e4fe88
parent8bfc62fb8b02bde7da97958deb8aeda63581bfce (diff)
downloadgitlab-ce-f19cdee8cc1e85066154d008ee2653d845c9f3cd.tar.gz
Remove commit_load_context.rb
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/contexts/commit_load_context.rb34
-rw-r--r--app/controllers/projects/commit_controller.rb35
-rw-r--r--lib/api/repositories.rb6
3 files changed, 23 insertions, 52 deletions
diff --git a/app/contexts/commit_load_context.rb b/app/contexts/commit_load_context.rb
deleted file mode 100644
index 0c684976b64..00000000000
--- a/app/contexts/commit_load_context.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-class CommitLoadContext < BaseContext
- def execute
- result = {
- commit: nil,
- suppress_diff: false,
- line_notes: [],
- notes_count: 0,
- note: nil,
- status: :ok
- }
-
- commit = project.repository.commit(params[:id])
-
- if commit
- line_notes = project.notes.for_commit_id(commit.id).inline
-
- result[:commit] = commit
- result[:note] = project.build_commit_note(commit)
- result[:line_notes] = line_notes
- result[:notes_count] = project.notes.for_commit_id(commit.id).count
- result[:branches] = project.repository.branch_names_contains(commit.id)
-
- begin
- result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff]
- result[:force_suppress_diff] = commit.diff_force_suppress?
- rescue Grit::Git::GitTimeout
- result[:suppress_diff] = true
- result[:status] = :huge_commit
- end
- end
-
- result
- end
-end
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index 65b8a7283a7..687026ed360 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -6,30 +6,31 @@ class Projects::CommitController < Projects::ApplicationController
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
+ before_filter :commit
def show
- result = CommitLoadContext.new(project, current_user, params).execute
+ return git_not_found! unless @commit
- @commit = result[:commit]
+ @line_notes = project.notes.for_commit_id(commit.id).inline
+ @branches = project.repository.branch_names_contains(commit.id)
- if @commit.nil?
- git_not_found!
- return
+ begin
+ @suppress_diff = true if commit.diff_suppress? && !params[:force_show_diff]
+ @force_suppress_diff = commit.diff_force_suppress?
+ rescue Grit::Git::GitTimeout
+ @suppress_diff = true
+ @status = :huge_commit
end
- @suppress_diff = result[:suppress_diff]
- @force_suppress_diff = result[:force_suppress_diff]
-
- @note = result[:note]
- @line_notes = result[:line_notes]
- @branches = result[:branches]
- @notes_count = result[:notes_count]
+ @note = project.build_commit_note(commit)
+ @notes_count = project.notes.for_commit_id(commit.id).count
@notes = project.notes.for_commit_id(@commit.id).not_inline.fresh
@noteable = @commit
-
@comments_allowed = @reply_allowed = true
- @comments_target = { noteable_type: 'Commit',
- commit_id: @commit.id }
+ @comments_target = {
+ noteable_type: 'Commit',
+ commit_id: @commit.id
+ }
respond_to do |format|
format.html do
@@ -42,4 +43,8 @@ class Projects::CommitController < Projects::ApplicationController
format.patch { render text: @commit.to_patch }
end
end
+
+ def commit
+ @commit ||= project.repository.commit(params[:id])
+ end
end
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index c99c8f7bdfb..af958f06c64 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -124,9 +124,9 @@ module API
# GET /projects/:id/repository/commits/:sha/diff
get ":id/repository/commits/:sha/diff" do
sha = params[:sha]
- result = CommitLoadContext.new(user_project, current_user, {id: sha}).execute
- not_found! "Commit" unless result[:commit]
- result[:commit].diffs
+ commit = user_project.repository.commit(sha)
+ not_found! "Commit" unless commit
+ commit.diffs
end
# Get a project repository tree