diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2018-08-17 17:43:20 +0200 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-09-20 10:48:51 +0200 |
commit | 860571e52d04ff458331bdbc703d0ee4a8cc1998 (patch) | |
tree | 725a1e7df64f8937f1ab0d4641c5e465e97c9572 | |
parent | 8acbb7d0a76443a6d69ac3633af841da5ae84e51 (diff) | |
download | gitlab-ce-jv-wiki-page-fields-encoding.tar.gz |
Clean up wiki classesjv-wiki-page-fields-encoding
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 5 | ||||
-rw-r--r-- | Gemfile.rails5.lock | 5 | ||||
-rw-r--r-- | config/initializers/gollum.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/git/wiki.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/git/wiki_file.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/git/wiki_page.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/git/wiki_page_version.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/wiki_service.rb | 2 | ||||
-rw-r--r-- | spec/features/markdown/markdown_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/wiki_service_spec.rb | 4 |
11 files changed, 34 insertions, 93 deletions
@@ -80,11 +80,9 @@ gem 'gitlab_omniauth-ldap', '~> 2.0.4', require: 'omniauth-ldap' gem 'net-ldap' # Git Wiki -# Required manually in config/initializers/gollum.rb to control load order +# Only used to compute wiki page slugs gem 'gitlab-gollum-lib', '~> 4.2', require: false -gem 'gitlab-gollum-rugged_adapter', '~> 0.4.4', require: false - # Language detection gem 'github-linguist', '~> 5.3.3', require: 'linguist' @@ -137,6 +135,7 @@ gem 'seed-fu', '~> 2.3.7' gem 'html-pipeline', '~> 2.8' gem 'deckar01-task_list', '2.0.0' gem 'gitlab-markup', '~> 1.6.4' +gem 'github-markup', '~> 1.7.0', require: 'github/markup' gem 'redcarpet', '~> 3.4' gem 'commonmarker', '~> 0.17' gem 'RedCloth', '~> 4.3.2' diff --git a/Gemfile.lock b/Gemfile.lock index 328cc55cb8c..c2a3c07ef7e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -297,9 +297,6 @@ GEM rouge (~> 3.1) sanitize (~> 4.6.4) stringex (~> 2.6) - gitlab-gollum-rugged_adapter (0.4.4.1) - mime-types (>= 1.15) - rugged (~> 0.25) gitlab-grit (2.8.2) charlock_holmes (~> 0.6) diff-lcs (~> 1.1) @@ -1035,9 +1032,9 @@ DEPENDENCIES gettext_i18n_rails_js (~> 1.3) gitaly-proto (~> 0.117.0) github-linguist (~> 5.3.3) + github-markup (~> 1.7.0) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-gollum-lib (~> 4.2) - gitlab-gollum-rugged_adapter (~> 0.4.4) gitlab-markup (~> 1.6.4) gitlab-styles (~> 2.4) gitlab_omniauth-ldap (~> 2.0.4) diff --git a/Gemfile.rails5.lock b/Gemfile.rails5.lock index aa6a32fa84e..86992a25b71 100644 --- a/Gemfile.rails5.lock +++ b/Gemfile.rails5.lock @@ -300,9 +300,6 @@ GEM rouge (~> 3.1) sanitize (~> 4.6.4) stringex (~> 2.6) - gitlab-gollum-rugged_adapter (0.4.4.1) - mime-types (>= 1.15) - rugged (~> 0.25) gitlab-grit (2.8.2) charlock_holmes (~> 0.6) diff-lcs (~> 1.1) @@ -1044,9 +1041,9 @@ DEPENDENCIES gettext_i18n_rails_js (~> 1.3) gitaly-proto (~> 0.117.0) github-linguist (~> 5.3.3) + github-markup (~> 1.7.0) gitlab-flowdock-git-hook (~> 1.0.1) gitlab-gollum-lib (~> 4.2) - gitlab-gollum-rugged_adapter (~> 0.4.4) gitlab-markup (~> 1.6.4) gitlab-styles (~> 2.4) gitlab_omniauth-ldap (~> 2.0.4) diff --git a/config/initializers/gollum.rb b/config/initializers/gollum.rb deleted file mode 100644 index ea9cc151a57..00000000000 --- a/config/initializers/gollum.rb +++ /dev/null @@ -1,28 +0,0 @@ -# WARNING changes in this file must be manually propagated to gitaly-ruby. -# -# https://gitlab.com/gitlab-org/gitaly/blob/master/ruby/lib/gitlab/gollum.rb - -module Gollum - GIT_ADAPTER = "rugged".freeze -end -require "gollum-lib" - -module Gollum - class Page - def text_data(encoding = nil) - data = if raw_data.respond_to?(:encoding) - raw_data.force_encoding(encoding || Encoding::UTF_8) - else - raw_data - end - - Gitlab::EncodingHelper.encode!(data) - end - end -end - -Rails.application.configure do - config.after_initialize do - Gollum::Page.per_page = Kaminari.config.default_per_page - end -end diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index ae92a624e05..66abd070495 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -1,8 +1,14 @@ +# We only need Gollum::Page so let's not load all of gollum-lib. +require 'gollum-lib/pagination' +require 'gollum-lib/wiki' +require 'gollum-lib/page' + module Gitlab module Git class Wiki DuplicatePageError = Class.new(StandardError) OperationError = Class.new(StandardError) + DEFAULT_PAGINATION = Kaminari.config.default_per_page CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do def to_h @@ -74,7 +80,7 @@ module Gitlab # Gitaly uses gollum-lib to get the versions. Gollum defaults to 20 # per page, but also fetches 20 if `limit` or `per_page` < 20. # Slicing returns an array with the expected number of items. - slice_bound = options[:limit] || options[:per_page] || Gollum::Page.per_page + slice_bound = options[:limit] || options[:per_page] || DEFAULT_PAGINATION versions[0..slice_bound] end @@ -104,14 +110,6 @@ module Gitlab private - def new_page(gollum_page) - Gitlab::Git::WikiPage.new(gollum_page, new_version(gollum_page, gollum_page.version.id)) - end - - def new_version(gollum_page, commit_id) - Gitlab::Git::WikiPageVersion.new(version(commit_id), gollum_page&.format) - end - def version(commit_id) commit_find_proc = -> { Gitlab::Git::Commit.find(@repository, commit_id) } @@ -122,12 +120,6 @@ module Gitlab end end - def assert_type!(object, klass) - unless object.is_a?(klass) - raise ArgumentError, "expected a #{klass}, got #{object.inspect}" - end - end - def gitaly_wiki_client @gitaly_wiki_client ||= Gitlab::GitalyClient::WikiService.new(@repository) end diff --git a/lib/gitlab/git/wiki_file.rb b/lib/gitlab/git/wiki_file.rb index 84335aca4bc..64313bb04e8 100644 --- a/lib/gitlab/git/wiki_file.rb +++ b/lib/gitlab/git/wiki_file.rb @@ -3,17 +3,12 @@ module Gitlab class WikiFile attr_reader :mime_type, :raw_data, :name, :path - # This class is meant to be serializable so that it can be constructed - # by Gitaly and sent over the network to GitLab. - # - # Because Gollum::File is not serializable we must get all the data from - # 'gollum_file' during initialization, and NOT store it in an instance - # variable. - def initialize(gollum_file) - @mime_type = gollum_file.mime_type - @raw_data = gollum_file.raw_data - @name = gollum_file.name - @path = gollum_file.path + # This class wraps Gitlab::GitalyClient::WikiFile + def initialize(gitaly_file) + @mime_type = gitaly_file.mime_type + @raw_data = gitaly_file.raw_data + @name = gitaly_file.name + @path = gitaly_file.path end end end diff --git a/lib/gitlab/git/wiki_page.rb b/lib/gitlab/git/wiki_page.rb index 669ae11a423..c4087c9ebdc 100644 --- a/lib/gitlab/git/wiki_page.rb +++ b/lib/gitlab/git/wiki_page.rb @@ -3,25 +3,15 @@ module Gitlab class WikiPage attr_reader :url_path, :title, :format, :path, :version, :raw_data, :name, :text_data, :historical, :formatted_data - # This class is meant to be serializable so that it can be constructed - # by Gitaly and sent over the network to GitLab. - # - # Because Gollum::Page is not serializable we must get all the data from - # 'gollum_page' during initialization, and NOT store it in an instance - # variable. - # - # Note that 'version' is a WikiPageVersion instance which it itself - # serializable. That means it's OK to store 'version' in an instance - # variable. - def initialize(gollum_page, version) - @url_path = gollum_page.url_path - @title = gollum_page.title - @format = gollum_page.format - @path = gollum_page.path - @raw_data = gollum_page.raw_data - @name = gollum_page.name - @historical = gollum_page.historical? - @formatted_data = gollum_page.formatted_data if gollum_page.is_a?(Gollum::Page) + # This class abstracts away Gitlab::GitalyClient::WikiPage + def initialize(gitaly_page, version) + @url_path = gitaly_page.url_path + @title = gitaly_page.title + @format = gitaly_page.format + @path = gitaly_page.path + @raw_data = gitaly_page.raw_data + @name = gitaly_page.name + @historical = gitaly_page.historical? @version = version end diff --git a/lib/gitlab/git/wiki_page_version.rb b/lib/gitlab/git/wiki_page_version.rb index 55f1afedcab..d5e7e70fd31 100644 --- a/lib/gitlab/git/wiki_page_version.rb +++ b/lib/gitlab/git/wiki_page_version.rb @@ -3,11 +3,6 @@ module Gitlab class WikiPageVersion attr_reader :commit, :format - # This class is meant to be serializable so that it can be constructed - # by Gitaly and sent over the network to GitLab. - # - # Both 'commit' (a Gitlab::Git::Commit) and 'format' (a string) are - # serializable. def initialize(commit, format) @commit = commit @format = format diff --git a/lib/gitlab/gitaly_client/wiki_service.rb b/lib/gitlab/gitaly_client/wiki_service.rb index 75be7d1f5a0..7c2c228ad01 100644 --- a/lib/gitlab/gitaly_client/wiki_service.rb +++ b/lib/gitlab/gitaly_client/wiki_service.rb @@ -110,7 +110,7 @@ module Gitlab repository: @gitaly_repo, page_path: encode_binary(page_path), page: options[:page] || 1, - per_page: options[:per_page] || Gollum::Page.per_page + per_page: options[:per_page] || Gitlab::Git::Wiki::DEFAULT_PAGINATION ) stream = GitalyClient.call(@repository.storage, :wiki_service, :wiki_get_page_versions, request, timeout: GitalyClient.medium_timeout) diff --git a/spec/features/markdown/markdown_spec.rb b/spec/features/markdown/markdown_spec.rb index cac8a5068ec..3b37ede8579 100644 --- a/spec/features/markdown/markdown_spec.rb +++ b/spec/features/markdown/markdown_spec.rb @@ -264,9 +264,9 @@ describe 'GitLab Markdown', :aggregate_failures do @project_wiki = @feat.project_wiki @project_wiki_page = @feat.project_wiki_page - file = Gollum::File.new(@project_wiki.wiki) - expect(file).to receive(:path).and_return('images/example.jpg') - expect(@project_wiki).to receive(:find_file).with('images/example.jpg').and_return(file) + path = 'images/example.jpg' + gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) + expect(@project_wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) allow(@project_wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } @html = markdown(@feat.raw_markdown, { pipeline: :wiki, project_wiki: @project_wiki, page_slug: @project_wiki_page.slug }) diff --git a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb index 5f67fe6b952..d82c9c28da0 100644 --- a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb @@ -39,6 +39,10 @@ describe Gitlab::GitalyClient::WikiService do expect(wiki_page.title).to eq('My Page') expect(wiki_page.raw_data).to eq('ab') expect(wiki_page_version.format).to eq('markdown') + + expect(wiki_page.title).to be_utf8 + expect(wiki_page.path).to be_utf8 + expect(wiki_page.name).to be_utf8 end end |