diff options
author | Z.J. van de Weg <zegerjan@gitlab.com> | 2016-07-20 17:51:04 +0200 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-12-01 13:54:02 +0100 |
commit | e038928234db133bb9dcb214b124a32027a13b27 (patch) | |
tree | ef3f2e7c003963dd7777eccf1a487067a9b17e71 | |
parent | 43c8788e7bd4c705bc8215ea2409b21a19d090f7 (diff) | |
download | gitlab-ce-commit-patch-diff-workhorse.tar.gz |
Workhorse now sents raw commit diffs and patchescommit-patch-diff-workhorse
-rw-r--r-- | app/controllers/projects/commit_controller.rb | 8 | ||||
-rw-r--r-- | app/helpers/workhorse_helper.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/diff/diff_refs.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/workhorse.rb | 21 | ||||
-rw-r--r-- | spec/controllers/projects/commit_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 1 |
6 files changed, 37 insertions, 37 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index cdfc1ba7b92..f1b1d2c4302 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -23,8 +23,12 @@ class Projects::CommitController < Projects::ApplicationController respond_to do |format| format.html - format.diff { render text: @commit.to_diff } - format.patch { render text: @commit.to_patch } + format.diff do + send_git_commit @project.repository, @commit.id + end + format.patch do + send_git_commit @project.repository, @commit.id, format: :email + end end end diff --git a/app/helpers/workhorse_helper.rb b/app/helpers/workhorse_helper.rb index 88f374be1e5..f7a621082be 100644 --- a/app/helpers/workhorse_helper.rb +++ b/app/helpers/workhorse_helper.rb @@ -23,6 +23,13 @@ module WorkhorseHelper head :ok end + # Sends a single commit through Workhorse + def send_git_commit(repository, sha, format: :diff) + headers.store(*Gitlab::Workhorse.send_git_commit(repository, sha, format: format)) + headers['Content-Disposition'] = 'inline' + head :ok + end + # Archive a Git repository and send it through Workhorse def send_git_archive(repository, ref:, format:) headers.store(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format)) diff --git a/lib/gitlab/diff/diff_refs.rb b/lib/gitlab/diff/diff_refs.rb index 8406ca4269c..30310351bde 100644 --- a/lib/gitlab/diff/diff_refs.rb +++ b/lib/gitlab/diff/diff_refs.rb @@ -26,7 +26,7 @@ module Gitlab # `DiffRefs` are "complete" when they have `start_sha` and `head_sha`, # because `base_sha` can always be derived from this, to return an actual # sha, or `nil`. - # We have `base_sha` directly available on `DiffRefs` because it's faster# + # We have `base_sha` directly available on `DiffRefs` because it's faster # than having to look it up in the repo every time. def complete? start_sha && head_sha diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb index 594439a5d4b..d9a6401aee7 100644 --- a/lib/gitlab/workhorse.rb +++ b/lib/gitlab/workhorse.rb @@ -58,8 +58,8 @@ module Gitlab end def send_git_diff(repository, diff_refs) - params = { - 'RepoPath' => repository.path_to_repo, + params = { + 'RepoPath' => repository.path_to_repo, 'ShaFrom' => diff_refs.base_sha, 'ShaTo' => diff_refs.head_sha } @@ -71,8 +71,8 @@ module Gitlab end def send_git_patch(repository, diff_refs) - params = { - 'RepoPath' => repository.path_to_repo, + params = { + 'RepoPath' => repository.path_to_repo, 'ShaFrom' => diff_refs.base_sha, 'ShaTo' => diff_refs.head_sha } @@ -83,6 +83,19 @@ module Gitlab ] end + def send_git_commit(repository, sha, format:) + params = { + 'RepoPath' => repository.path_to_repo, + 'Sha' => sha, + 'Format' => format + } + + [ + SEND_DATA_HEADER, + "git-show-commit:#{encode(params)}" + ] + end + def send_artifacts_entry(build, entry) params = { 'Archive' => build.artifacts_file.path, diff --git a/spec/controllers/projects/commit_controller_spec.rb b/spec/controllers/projects/commit_controller_spec.rb index 646b097d74e..8da5bfe1d7a 100644 --- a/spec/controllers/projects/commit_controller_spec.rb +++ b/spec/controllers/projects/commit_controller_spec.rb @@ -79,41 +79,18 @@ describe Projects::CommitController do end describe "as diff" do - include_examples "export as", :diff - let(:format) { :diff } + it "triggers workhorse to serve the request" do + go(id: commit.id, format: :diff) - it "should really only be a git diff" do - go(id: '66eceea0db202bb39c4e445e8ca28689645366c5', format: format) - - expect(response.body).to start_with("diff --git") - end - - it "is only be a git diff without whitespace changes" do - go(id: '66eceea0db202bb39c4e445e8ca28689645366c5', format: format, w: 1) - - expect(response.body).to start_with("diff --git") - - # without whitespace option, there are more than 2 diff_splits for other formats - diff_splits = assigns(:diffs).diff_files.first.diff.diff.split("\n") - expect(diff_splits.length).to be <= 2 + expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-show-commit:") end end describe "as patch" do - include_examples "export as", :patch - let(:format) { :patch } - let(:commit2) { project.commit('498214de67004b1da3d820901307bed2a68a8ef6') } - - it "is a git email patch" do - go(id: commit2.id, format: format) - - expect(response.body).to start_with("From #{commit2.id}") - end - - it "contains a git diff" do - go(id: commit2.id, format: format) + it "triggers workhorse to serve the request" do + go(id: commit.id, format: :patch) - expect(response.body).to match(/^diff --git/) + expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-show-commit:") end end diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index e3bb3482d67..75c2e6ac7a7 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -120,7 +120,6 @@ eos it { is_expected.to respond_to(:diffs) } it { is_expected.to respond_to(:tree) } it { is_expected.to respond_to(:id) } - it { is_expected.to respond_to(:to_patch) } end describe '#closes_issues' do |