diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index 34c8c6f0f..f1b0139d4 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -128,16 +128,15 @@ class Projects::PullRequestsController < Projects::BaseController end def load_diff_commits_data - @repo = Grit::Repo.new(@pull.path) @base_commit = @pull.common_ancestor - @head_commit = @repo.commits(@pull.head_branch).first + @head_commit = @pull.repo.commits(@pull.head_branch).first - @commits = @repo.commits_between(@repo.commits(@pull.to_ref).first, @head_commit) + @commits = @pull.repo.commits_between(@pull.repo.commits(@pull.to_ref).first, @head_commit) @total_commits = @commits.count @commits = @commits.last(100) - @diff = @pull.diff @repo, @base_commit, @head_commit - @stats = @pull.diff_stats @repo, @base_commit, @head_commit + @diff = @pull.diff @pull.repo, @base_commit, @head_commit + @stats = @pull.diff_stats @pull.repo, @base_commit, @head_commit @comments = @issue.comments @commentable = @issue end diff --git a/app/models/comment.rb b/app/models/comment.rb index ff1e0f802..61aabdef9 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -93,10 +93,8 @@ class Comment < ActiveRecord::Base return true if params[:path].blank? && params[:line].blank? # not inline comment self.data = {:path => params[:path], :line => params[:line]} if commentable.class == Issue && pull = commentable.pull_request - repo = Grit::Repo.new(pull.path) - to_commit, from_commit = pull.common_ancestor, repo.commits(pull.head_branch).first - - diff = pull.diff repo, to_commit, from_commit + to_commit, from_commit = pull.common_ancestor, pull.repo.commits(pull.head_branch).first + diff = pull.diff pull.repo, to_commit, from_commit diff_path = diff.select {|d| d.a_path == params[:path]} return false unless actual_inline_comment?(diff, true) diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 41f1e8c5c..d6148580a 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -96,7 +96,6 @@ class PullRequest < ActiveRecord::Base def common_ancestor return @common_ancestor if @common_ancestor - repo = Grit::Repo.new(path) base_commit = repo.commits(to_ref).first head_commit = repo.commits(head_branch).first @common_ancestor = repo.commit(repo.git.merge_base({}, base_commit, head_commit)) || base_commit @@ -147,6 +146,10 @@ class PullRequest < ActiveRecord::Base end end + def repo + return @repo if @repo.present? #&& !id_changed? + @repo = Grit::Repo.new path + end protected def merge @@ -204,8 +207,7 @@ class PullRequest < ActiveRecord::Base def update_inline_comments if self.comments.count > 0 - repo = Grit::Repo.new self.path - diff = self.diff repo, self.common_ancestor, repo.commits(self.head_branch).first + diff = self.diff self.repo, self.common_ancestor, repo.commits(self.head_branch).first end self.comments.each do |c| if c.data.present? # maybe need add new column 'actual'? diff --git a/app/views/projects/pull_requests/_pull_diff.html.haml b/app/views/projects/pull_requests/_pull_diff.html.haml index dc707a042..931084e7e 100644 --- a/app/views/projects/pull_requests/_pull_diff.html.haml +++ b/app/views/projects/pull_requests/_pull_diff.html.haml @@ -6,5 +6,5 @@ - if pull_diff.b_path.present? .r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, pull_diff.b_path) .clear - -if pull_diff.diff.present? && !(Grit::Repo.new(@pull.path).tree(commit_id) / pull_diff.b_path).binary? + -if pull_diff.diff.present? && !(@pull.repo.tree(commit_id) / pull_diff.b_path).binary? .diff_data=render_diff(pull_diff, pull_diff_counter, @comments)