diff options
author | Robert Speicher <robert@gitlab.com> | 2016-06-29 02:26:38 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-06-29 02:26:38 +0000 |
commit | 5423e6e2d5f47ea72958086c545fb9f55ce320cb (patch) | |
tree | 774d00d6e81a55020537854bb9557787a0dbfc18 | |
parent | d171ff17beb82c2378c1eae52dada91481a48239 (diff) | |
parent | db0a6c10edff0eebe81297763dd9e0a9965c507f (diff) | |
download | gitlab-ce-5423e6e2d5f47ea72958086c545fb9f55ce320cb.tar.gz |
Merge branch 'zj-workhorse-format-patch' into 'master'
Workhorse to serve email diffs
See merge request !4590
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | GITLAB_WORKHORSE_VERSION | 2 | ||||
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 8 | ||||
-rw-r--r-- | app/models/merge_request.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/workhorse.rb | 13 | ||||
-rw-r--r-- | spec/controllers/projects/merge_requests_controller_spec.rb | 18 |
6 files changed, 25 insertions, 24 deletions
diff --git a/CHANGELOG b/CHANGELOG index 979c9e6e30d..5c735bd1420 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ v 8.10.0 (unreleased) - Wrap code blocks on Activies and Todos page. !4783 (winniehell) - Display last commit of deleted branch in push events !4699 (winniehell) - Add Sidekiq queue duration to transaction metrics. + - Let Workhorse serve format-patch diffs - Make images fit to the size of the viewport !4810 - Fix check for New Branch button on Issue page !4630 (winniehell) - Fix MR-auto-close text added to description. !4836 diff --git a/GITLAB_WORKHORSE_VERSION b/GITLAB_WORKHORSE_VERSION index 8bd6ba8c5c3..879be8a98fc 100644 --- a/GITLAB_WORKHORSE_VERSION +++ b/GITLAB_WORKHORSE_VERSION @@ -1 +1 @@ -0.7.5 +0.7.7 diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 39c8ba40ca2..dd86b940a08 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -59,7 +59,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController respond_to do |format| format.html format.json { render json: @merge_request } - format.patch { render text: @merge_request.to_patch } + format.patch do + headers.store(*Gitlab::Workhorse.send_git_patch(@project.repository, + @merge_request.diff_base_commit.id, + @merge_request.last_commit.id)) + headers['Content-Disposition'] = 'inline' + head :ok + end format.diff do return render_404 unless @merge_request.diff_refs diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index f5c5b7c1306..53d9aa588af 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -319,13 +319,6 @@ class MergeRequest < ActiveRecord::Base ) end - # Returns the commit as a series of email patches. - # - # see "git format-patch" - def to_patch - target_project.repository.format_patch(diff_base_commit.sha, source_sha) - end - def hook_attrs attrs = { source: source_project.try(:hook_attrs), diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 40e8299c36b..ef1241f8600 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -52,6 +52,19 @@ module Gitlab ] end + def send_git_patch(repository, from, to) + params = { + 'RepoPath' => repository.path_to_repo, + 'ShaFrom' => from, + 'ShaTo' => to + } + + [ + SEND_DATA_HEADER, + "git-format-patch:#{encode(params)}" + ] + end + protected def encode(hash) diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 1cc35c66c8f..74c050f48f1 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -96,26 +96,14 @@ describe Projects::MergeRequestsController do end describe "as patch" do - include_examples "export merge as", :patch - let(:format) { :patch } - - it "should really be a git email patch with commit" do - get(:show, - namespace_id: project.namespace.to_param, - project_id: project.to_param, - id: merge_request.iid, format: format) - - expect(response.body[0..100]).to start_with("From #{merge_request.commits.last.id}") - end - - it "should contain git diffs" 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: :patch) - expect(response.body).to match(/^diff --git/) + expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-format-patch:") end end end |