summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-05-12 20:50:49 +0200
committerZ.J. van de Weg <zegerjan@gitlab.com>2016-06-03 18:43:22 +0200
commit01e1139f68066e46b86ef92749513377eee63f5b (patch)
treeb5ca525894fa2c548dce2b357f0b5419ee719388
parentca3c5c295ed653b483fe81c3918ffe60f46666b9 (diff)
downloadgitlab-ce-01e1139f68066e46b86ef92749513377eee63f5b.tar.gz
Workhorse to serve raw diffs
-rw-r--r--app/controllers/projects/merge_requests_controller.rb13
-rw-r--r--app/models/merge_request.rb7
-rw-r--r--features/project/merge_requests.feature12
-rw-r--r--lib/gitlab/workhorse.rb17
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb9
5 files changed, 28 insertions, 30 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 3142fe5c767..fe811f30c03 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -57,9 +57,16 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format|
format.html
- format.json { render json: @merge_request }
- format.diff { render text: @merge_request.to_diff }
- format.patch { render text: @merge_request.to_patch }
+ format.json { render json: @merge_request }
+ format.patch { render text: @merge_request.to_patch }
+ format.diff do
+ headers.store(*Gitlab::Workhorse.send_git_diff(@project.repository,
+ @merge_request.diff_base_commit.id,
+ @merge_request.last_commit.id))
+ headers['Content-Disposition'] = 'inline'
+
+ head :ok
+ end
end
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 722c258244c..22505363654 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -313,13 +313,6 @@ class MergeRequest < ActiveRecord::Base
)
end
- # Returns the raw diff for this merge request
- #
- # see "git diff"
- def to_diff
- target_project.repository.diff_text(diff_base_commit.sha, source_sha)
- end
-
# Returns the commit as a series of email patches.
#
# see "git format-patch"
diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature
index ecda4ea8240..cc04ea7fe48 100644
--- a/features/project/merge_requests.feature
+++ b/features/project/merge_requests.feature
@@ -76,18 +76,6 @@ Feature: Project Merge Requests
And I submit new merge request "Wiki Feature"
Then I should see merge request "Wiki Feature"
- Scenario: I download a diff on a public merge request
- Given public project "Community"
- And "John Doe" owns public project "Community"
- And project "Community" has "Bug CO-01" open merge request with diffs inside
- Given I logout directly
- And I visit merge request page "Bug CO-01"
- And I click on "Email Patches"
- Then I should see a patch diff
- And I visit merge request page "Bug CO-01"
- And I click on "Plain Diff"
- Then I should see a patch diff
-
@javascript
Scenario: I comment on a merge request
Given I visit merge request page "Bug NS-04"
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index c3ddd4c2680..7f6ef71b303 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -29,9 +29,22 @@ module Gitlab
"git-archive:#{encode(params)}",
]
end
-
+
+ def send_git_diff(repository, from, to)
+ params = {
+ 'RepoPath' => repository.path_to_repo,
+ 'ShaFrom' => from,
+ 'ShaTo' => to
+ }
+
+ [
+ SEND_DATA_HEADER,
+ "git-diff:#{encode(params)}"
+ ]
+ end
+
protected
-
+
def encode(hash)
Base64.urlsafe_encode64(JSON.dump(hash))
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 8499bf07e9f..368fd498928 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -84,17 +84,14 @@ describe Projects::MergeRequestsController do
end
describe "as diff" do
- include_examples "export merge as", :diff
- let(:format) { :diff }
-
- it "should really only be a git diff" do
+ it "triggers workhorse to serve the request" do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
- format: format)
+ format: :diff)
- expect(response.body).to start_with("diff --git")
+ expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-diff:")
end
end