diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-04-04 12:29:43 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-04-04 12:32:55 +0300 |
commit | 4c8ffa6de4251e972c91aa029409943827a65b96 (patch) | |
tree | ec1a0bf0e4f11d8ca66d543cd8828d6d08189ce0 | |
parent | 2df9fefb12f5d07d9927994ef946e8342c972fda (diff) |
Remove RawDiffChange
Was ported in: https://gitlab.com/gitlab-org/gitaly/merge_requests/1026
Now its safe to remove the Ruby implementation.
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/raw_diff_change.rb | 66 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 49 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb | 68 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_spec.rb | 72 |
5 files changed, 1 insertions, 255 deletions
@@ -16,6 +16,7 @@ MAKEGEN = $(BUILD_DIR)/makegen export GOPATH := $(CURDIR)/$(BUILD_DIR) export PATH := $(GOPATH)/bin:$(PATH) export TEST_REPO_STORAGE_PATH := $(CURDIR)/internal/testhelper/testdata/data +export GO111MODULE := off all: build diff --git a/ruby/lib/gitlab/git/raw_diff_change.rb b/ruby/lib/gitlab/git/raw_diff_change.rb deleted file mode 100644 index e27b277a3..000000000 --- a/ruby/lib/gitlab/git/raw_diff_change.rb +++ /dev/null @@ -1,66 +0,0 @@ -# TODO: remove after 11.8 because of https://gitlab.com/gitlab-org/gitaly/merge_requests/1026 - -module Gitlab - module Git - class RawDiffChange - attr_reader :blob_id, :blob_size, :old_path, :new_path, :operation, :old_mode, :new_mode - - def initialize(raw_change, old_mode, new_mode) - parse(raw_change) - - @old_mode = old_mode - @new_mode = new_mode - end - - private - - # Input data has the following format: - # - # When a file has been modified: - # 7e3e39ebb9b2bf433b4ad17313770fbe4051649c 669 M\tfiles/ruby/popen.rb - # - # When a file has been renamed: - # 85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee - def parse(raw_change) - @blob_id, @blob_size, @raw_operation, raw_paths = raw_change.split(' ', 4) - @blob_size = @blob_size.to_i - @operation = extract_operation - @old_path, @new_path = extract_paths(raw_paths) - end - - def extract_paths(file_path) - case operation - when :copied, :renamed - file_path.split(/\t/) - when :deleted - [file_path, nil] - when :added - [nil, file_path] - else - [file_path, file_path] - end - end - - def extract_operation - return :unknown unless @raw_operation - - case @raw_operation[0] - when 'A' - :added - when 'C' - :copied - when 'D' - :deleted - when 'M' - :modified - when 'R' - :renamed - when 'T' - :type_changed - else - :unknown - end - end - end - end -end diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 1a0b7d044..7c312afce 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -260,55 +260,6 @@ module Gitlab false end - # TODO: remove after 11.8 because of https://gitlab.com/gitlab-org/gitaly/merge_requests/1026 - def raw_changes_between(old_rev, new_rev) - @raw_changes_between ||= {} - - @raw_changes_between[[old_rev, new_rev]] ||= - begin - return [] if new_rev.blank? || new_rev == Gitlab::Git::BLANK_SHA - - result = [] - - Open3.popen3(*git_diff_cmd(old_rev, new_rev)) do |_stdin, stdout, _stderr, wait_thr| - cat_stdin, cat_stdout, cat_stderr, cat_wait_thr = Open3.popen3(*git_cat_file_cmd) - - stdout.each_line do |line| - old_mode, new_mode, blob_id, rest = parse_raw_diff_line(line) - cat_stdin.puts("#{blob_id} #{rest}") - result << ::Gitlab::Git::RawDiffChange.new(cat_stdout.gets.chomp, old_mode, new_mode) - end - - cat_stdin.close - cat_stdout.close - cat_stderr.close - - raise ::Gitlab::Git::Repository::GitError, "Unabled to obtain changes between #{old_rev} and #{new_rev}" unless [cat_wait_thr, wait_thr].all? { |waiter| waiter.value&.success? } - end - - result - end - rescue ArgumentError => e - raise Gitlab::Git::Repository::GitError, e.to_s - end - - # TODO: remove after 11.8 because of https://gitlab.com/gitlab-org/gitaly/merge_requests/1026 - def parse_raw_diff_line(line) - old_mode, new_mode, old_blob_id, new_blob_id, rest = line.split(/\s/, 5) - - # If the last element got a value we should be good - raise ArgumentError, "Invalid diff line: #{line}" unless rest - - old_mode.gsub!(/\A:/, '') - old_blob_id.gsub!(/[^\h]/, '') - new_blob_id.gsub!(/[^\h]/, '') - - # We can't pass '0000000...' to `git cat-file` given it will not return info about the deleted file - blob_id = new_blob_id.match?(/\A0+\z/) ? old_blob_id : new_blob_id - - [old_mode, new_mode, blob_id, rest] - end - def add_tag(tag_name, user:, target:, message: nil) target_object = Ref.dereference_object(lookup(target)) raise InvalidRef, "target not found: #{target}" unless target_object diff --git a/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb b/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb deleted file mode 100644 index 071b9a21c..000000000 --- a/ruby/spec/lib/gitlab/git/raw_diff_change_spec.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::RawDiffChange do - let(:raw_change) {} - let(:old_mode) { 0o100644 } - let(:new_mode) { 0o100644 } - let(:change) { described_class.new(raw_change, old_mode, new_mode) } - - context 'bad input' do - let(:raw_change) { 'foo' } - - it 'does not set most of the attrs' do - expect(change.blob_id).to eq('foo') - expect(change.operation).to eq(:unknown) - expect(change.old_path).to be_blank - expect(change.new_path).to be_blank - expect(change.blob_size).to eq(0) - end - end - - context 'adding a file' do - let(:raw_change) { '93e123ac8a3e6a0b600953d7598af629dec7b735 59 A bar/branch-test.txt' } - - it 'initialize the proper attrs' do - expect(change.operation).to eq(:added) - expect(change.old_path).to be_blank - expect(change.new_path).to eq('bar/branch-test.txt') - expect(change.blob_id).to be_present - expect(change.blob_size).to be_present - end - end - - context 'renaming a file' do - let(:raw_change) { "85bc2f9753afd5f4fc5d7c75f74f8d526f26b4f3 107 R060\tfiles/js/commit.js.coffee\tfiles/js/commit.coffee" } - - it 'initialize the proper attrs' do - expect(change.operation).to eq(:renamed) - expect(change.old_path).to eq('files/js/commit.js.coffee') - expect(change.new_path).to eq('files/js/commit.coffee') - expect(change.blob_id).to be_present - expect(change.blob_size).to be_present - end - end - - context 'modifying a file' do - let(:raw_change) { 'c60514b6d3d6bf4bec1030f70026e34dfbd69ad5 824 M README.md' } - - it 'initialize the proper attrs' do - expect(change.operation).to eq(:modified) - expect(change.old_path).to eq('README.md') - expect(change.new_path).to eq('README.md') - expect(change.blob_id).to be_present - expect(change.blob_size).to be_present - end - end - - context 'deleting a file' do - let(:raw_change) { '60d7a906c2fd9e4509aeb1187b98d0ea7ce827c9 15364 D files/.DS_Store' } - - it 'initialize the proper attrs' do - expect(change.operation).to eq(:deleted) - expect(change.old_path).to eq('files/.DS_Store') - expect(change.new_path).to be_nil - expect(change.blob_id).to be_present - expect(change.blob_size).to be_present - end - end -end diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb index 4364b8818..962be8fc6 100644 --- a/ruby/spec/lib/gitlab/git/repository_spec.rb +++ b/ruby/spec/lib/gitlab/git/repository_spec.rb @@ -200,42 +200,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength end end - describe '#raw_changes_between' do - let(:changes) { repository.raw_changes_between(old_rev, new_rev) } - - context 'initial commit' do - let(:old_rev) { Gitlab::Git::BLANK_SHA } - let(:new_rev) { '1a0b36b3cdad1d2ee32457c102a8c0b7056fa863' } - - it 'returns the changes' do - expect(changes).to be_present - expect(changes.size).to eq(3) - end - end - - context 'with an invalid rev' do - let(:old_rev) { 'foo' } - let(:new_rev) { 'bar' } - - it 'returns an error' do - expect { changes }.to raise_error(Gitlab::Git::Repository::GitError) - end - end - - context 'with valid revs' do - let(:old_rev) { 'fa1b1e6c004a68b7d8763b86455da9e6b23e36d6' } - let(:new_rev) { '4b4918a572fa86f9771e5ba40fbd48e1eb03e2c6' } - - it 'returns the changes' do - expect(changes.size).to eq(9) - expect(changes.first.operation).to eq(:modified) - expect(changes.first.new_path).to eq('.gitmodules') - expect(changes.last.operation).to eq(:added) - expect(changes.last.new_path).to eq('files/lfs/picture-invalid.png') - end - end - end - describe '#merge_base' do where(:from, :to, :result) do '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' | '40f4a7a617393735a95a0bb67b08385bc1e7c66d' | '570e7b2abdd848b95f2f578043fc23bd6f6fd24d' @@ -764,42 +728,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength end end - describe '#parse_raw_diff_line' do - let(:diff_data) { repository.parse_raw_diff_line(diff_line) } - - context 'valid diff line' do - let(:diff_line) { ":100644 100644 454bade 2b75299 M\tmodified-file.txt" } - - it 'returns the diff data' do - expect(diff_data).to eq(["100644", "100644", "2b75299", "M\tmodified-file.txt"]) - end - - context 'added file' do - let(:diff_line) { ":000000 100644 0000000 5579569 A\tnew-file.txt" } - - it 'returns the new blob id' do - expect(diff_data[2]).to eq('5579569') - end - end - - context 'deleted file' do - let(:diff_line) { ":100644 000000 26b5bd5 0000000 D\tremoved-file.txt" } - - it 'returns the old blob id' do - expect(diff_data[2]).to eq('26b5bd5') - end - end - end - - context 'invalid diff line' do - let(:diff_line) { '' } - - it 'raises an ArgumentError' do - expect { diff_data }.to raise_error(ArgumentError) - end - end - end - describe "#commit_patches" do let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } let(:testdata_dir) { File.join(File.dirname(__FILE__), '../../../../../internal/service/operations/testdata') } |