diff options
author | Johan Sørensen <johan@johansorensen.com> | 2009-10-29 14:54:56 +0100 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-11-04 15:23:44 +0100 |
commit | 1a7b3a0ba79414fc91a3ca117f1c0e1ebbe80a6d (patch) | |
tree | b76d7cbdd744ea2d6bf4e8fa2b5c77a4365c6dbd | |
parent | ddd8531a039db5d1b8efd9078ada80d93ce7d4ba (diff) | |
download | gitorious-mainline-outdated-1a7b3a0ba79414fc91a3ca117f1c0e1ebbe80a6d.zip gitorious-mainline-outdated-1a7b3a0ba79414fc91a3ca117f1c0e1ebbe80a6d.tar.gz gitorious-mainline-outdated-1a7b3a0ba79414fc91a3ca117f1c0e1ebbe80a6d.tar.bz2 |
Make sure we re-render the diff correctly when commenting on single commit
-rw-r--r-- | app/controllers/comments_controller.rb | 21 | ||||
-rw-r--r-- | app/views/merge_request_versions/_comments.erb | 4 | ||||
-rw-r--r-- | public/javascripts/diff_browser.js | 3 |
3 files changed, 20 insertions, 8 deletions
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 63c37ef..a980856 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -76,17 +76,19 @@ class CommentsController < ApplicationController if @comment.sha1.blank? redirect_to_repository_or_target else - redirect_to repo_owner_path(@repository, :project_repository_commit_path, @project, @repository, @comment.sha1) + redirect_to repo_owner_path(@repository, + :project_repository_commit_path, @project, @repository, @comment.sha1) end end format.js do - @diffs = @target.diffs(@comment.sha_range). - select{|d|d.a_path == @comment.path} + @diffs = @target.diffs(range_or_string(@comment.sha1)).select{|d| + d.a_path == @comment.path + } render :partial => "merge_request_versions/comments", :status => :created end else format.html { render :action => "new" } - format.js {render :nothing => true, :status => :not_acceptable} + format.js { render :nothing => true, :status => :not_acceptable } end end end @@ -96,8 +98,17 @@ class CommentsController < ApplicationController end protected + def range_or_string(str) + if match = /^([a-z0-9]*)-([a-z0-9]*)$/.match(str) + @sha_range = Range.new(match[1],match[2]) + else + @sha_range = str + end + end + def find_repository - @repository = @owner.repositories.find_by_name_in_project!(params[:repository_id], @containing_project) + @repository = @owner.repositories.find_by_name_in_project!(params[:repository_id], + @containing_project) end def find_polymorphic_parent diff --git a/app/views/merge_request_versions/_comments.erb b/app/views/merge_request_versions/_comments.erb index 5c897f8..4c43819 100644 --- a/app/views/merge_request_versions/_comments.erb +++ b/app/views/merge_request_versions/_comments.erb @@ -17,4 +17,6 @@ #++ %> -<%= render_inline_diffs_with_stats(@diffs, :open){|file| @target.comments_for_path_and_sha(file.a_path, @comment.sha_range)} -%> +<%= render_inline_diffs_with_stats(@diffs, :open) do |file| + @target.comments_for_path_and_sha(file.a_path, @sha_range || @comment.sha_range) + end -%> diff --git a/public/javascripts/diff_browser.js b/public/javascripts/diff_browser.js index ae94130..3b78ad1 100644 --- a/public/javascripts/diff_browser.js +++ b/public/javascripts/diff_browser.js @@ -366,9 +366,8 @@ Gitorious.MergeRequestController = function() { spec.summarizeHtml(); NotificationCenter.notifyObservers("DiffBrowserDidReloadDiffs", this); - if (callback) { + if (callback) callback.apply(caller); - } } this.diffsReceivedWithError = function(xhr, statusText, errorThrown) { jQuery("#merge_request_diff").html( |