diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-04-13 13:17:52 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-13 13:17:52 +0000 |
commit | ef48664047881411ea849e02c5a675c06275b868 (patch) | |
tree | 0047ab15dc175ff808d6c474e7d8ae0c000c2842 | |
parent | 9ab4408bfa82602c54673a6fc1691d201a29c7cf (diff) | |
download | gitlab-ce-ef48664047881411ea849e02c5a675c06275b868.tar.gz |
Replacing gollum libs for custom gitlab ones
-rw-r--r-- | Gemfile | 13 | ||||
-rw-r--r-- | Gemfile.lock | 30 | ||||
-rw-r--r-- | changelogs/unreleased/fj-change-gollum-gems-to-custom-ones.yml | 5 | ||||
-rw-r--r-- | config/initializers/gollum.rb | 133 | ||||
-rw-r--r-- | spec/initializers/gollum_spec.rb | 62 |
5 files changed, 23 insertions, 220 deletions
@@ -82,16 +82,9 @@ gem 'net-ldap' # Git Wiki # Required manually in config/initializers/gollum.rb to control load order -# Before updating this gem, check if -# https://github.com/gollum/gollum-lib/pull/292 has been merged. -# If it has, then remove the monkey patch for update_page, rename_page and raw_data_in_committer -# in config/initializers/gollum.rb -gem 'gollum-lib', '~> 4.2', require: false - -# Before updating this gem, check if -# https://github.com/gollum/rugged_adapter/pull/28 has been merged. -# If it has, then remove the monkey patch for tree_entry in config/initializers/gollum.rb -gem 'gollum-rugged_adapter', '~> 0.4.4', require: false +gem 'gitlab-gollum-lib', '~> 4.2' + +gem 'gitlab-gollum-rugged_adapter', '~> 0.4.4', require: false # Language detection gem 'github-linguist', '~> 5.3.3', require: 'linguist' diff --git a/Gemfile.lock b/Gemfile.lock index 76e1a17155f..c3716baa762 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -298,11 +298,22 @@ GEM escape_utils (~> 1.1.0) mime-types (>= 1.19) rugged (>= 0.25.1) - github-markup (1.6.1) + github-markup (1.7.0) gitlab-flowdock-git-hook (1.0.1) flowdock (~> 0.7) gitlab-grit (>= 2.4.1) multi_json + gitlab-gollum-lib (4.2.7.1) + gemojione (~> 3.2) + github-markup (~> 1.6) + gollum-grit_adapter (~> 1.0) + nokogiri (>= 1.6.1, < 2.0) + rouge (~> 2.1) + sanitize (~> 2.1) + stringex (~> 2.6) + gitlab-gollum-rugged_adapter (0.4.4) + mime-types (>= 1.15) + rugged (~> 0.25) gitlab-grit (2.8.2) charlock_holmes (~> 0.6) diff-lcs (~> 1.1) @@ -325,17 +336,6 @@ GEM activesupport (>= 4.2, < 5.2) gollum-grit_adapter (1.0.1) gitlab-grit (~> 2.7, >= 2.7.1) - gollum-lib (4.2.7) - gemojione (~> 3.2) - github-markup (~> 1.6) - gollum-grit_adapter (~> 1.0) - nokogiri (>= 1.6.1, < 2.0) - rouge (~> 2.1) - sanitize (~> 2.1) - stringex (~> 2.6) - gollum-rugged_adapter (0.4.4) - mime-types (>= 1.15) - rugged (~> 0.25) gon (6.1.0) actionpack (>= 3.0) json @@ -910,7 +910,7 @@ GEM state_machines-activerecord (0.5.1) activerecord (>= 4.1, < 6.0) state_machines-activemodel (>= 0.5.0) - stringex (2.7.1) + stringex (2.8.4) sys-filesystem (1.1.6) ffi sysexits (1.2.0) @@ -1067,12 +1067,12 @@ DEPENDENCIES gitaly-proto (~> 0.94.0) github-linguist (~> 5.3.3) gitlab-flowdock-git-hook (~> 1.0.1) + gitlab-gollum-lib (~> 4.2) + gitlab-gollum-rugged_adapter (~> 0.4.4) gitlab-markup (~> 1.6.2) gitlab-styles (~> 2.3) gitlab_omniauth-ldap (~> 2.0.4) goldiloader (~> 2.0) - gollum-lib (~> 4.2) - gollum-rugged_adapter (~> 0.4.4) gon (~> 6.1.0) google-api-client (~> 0.19.8) google-protobuf (= 3.5.1) diff --git a/changelogs/unreleased/fj-change-gollum-gems-to-custom-ones.yml b/changelogs/unreleased/fj-change-gollum-gems-to-custom-ones.yml new file mode 100644 index 00000000000..53883e8d907 --- /dev/null +++ b/changelogs/unreleased/fj-change-gollum-gems-to-custom-ones.yml @@ -0,0 +1,5 @@ +--- +title: Replacing gollum libraries for gitlab custom libs +merge_request: 18343 +author: +type: other diff --git a/config/initializers/gollum.rb b/config/initializers/gollum.rb index 6dfaceb8427..81e0577a7c9 100644 --- a/config/initializers/gollum.rb +++ b/config/initializers/gollum.rb @@ -7,139 +7,6 @@ module Gollum end require "gollum-lib" -module Gollum - class Committer - # Patch for UTF-8 path - def method_missing(name, *args) - index.send(name, *args) - end - end - - class Wiki - def pages(treeish = nil, limit: nil) - tree_list((treeish || @ref), limit: limit) - end - - def tree_list(ref, limit: nil) - if (sha = @access.ref_to_sha(ref)) - commit = @access.commit(sha) - tree_map_for(sha).inject([]) do |list, entry| - next list unless @page_class.valid_page_name?(entry.name) - - list << entry.page(self, commit) - break list if limit && list.size >= limit - - list - end - else - [] - end - end - - # Remove if https://github.com/gollum/gollum-lib/pull/292 has been merged - def update_page(page, name, format, data, commit = {}) - name = name ? ::File.basename(name) : page.name - format ||= page.format - dir = ::File.dirname(page.path) - dir = '' if dir == '.' - filename = (rename = page.name != name) ? Gollum::Page.cname(name) : page.filename_stripped - - multi_commit = !!commit[:committer] - committer = multi_commit ? commit[:committer] : Committer.new(self, commit) - - if !rename && page.format == format - committer.add(page.path, normalize(data)) - else - committer.delete(page.path) - committer.add_to_index(dir, filename, format, data) - end - - committer.after_commit do |index, _sha| - @access.refresh - index.update_working_dir(dir, page.filename_stripped, page.format) - index.update_working_dir(dir, filename, format) - end - - multi_commit ? committer : committer.commit - end - - # Remove if https://github.com/gollum/gollum-lib/pull/292 has been merged - def rename_page(page, rename, commit = {}) - return false if page.nil? - return false if rename.nil? || rename.empty? - - (target_dir, target_name) = ::File.split(rename) - (source_dir, source_name) = ::File.split(page.path) - source_name = page.filename_stripped - - # File.split gives us relative paths with ".", commiter.add_to_index doesn't like that. - target_dir = '' if target_dir == '.' - source_dir = '' if source_dir == '.' - target_dir = target_dir.gsub(/^\//, '') # rubocop:disable Style/RegexpLiteral - - # if the rename is a NOOP, abort - if source_dir == target_dir && source_name == target_name - return false - end - - multi_commit = !!commit[:committer] - committer = multi_commit ? commit[:committer] : Committer.new(self, commit) - - # This piece only works for multi_commit - # If we are in a commit batch and one of the previous operations - # has updated the page, any information we ask to the page can be outdated. - # Therefore, we should ask first to the current committer tree to see if - # there is any updated change. - raw_data = raw_data_in_committer(committer, source_dir, page.filename) || - raw_data_in_committer(committer, source_dir, "#{target_name}.#{Page.format_to_ext(page.format)}") || - page.raw_data - - committer.delete(page.path) - committer.add_to_index(target_dir, target_name, page.format, raw_data) - - committer.after_commit do |index, _sha| - @access.refresh - index.update_working_dir(source_dir, source_name, page.format) - index.update_working_dir(target_dir, target_name, page.format) - end - - multi_commit ? committer : committer.commit - end - - # Remove if https://github.com/gollum/gollum-lib/pull/292 has been merged - def raw_data_in_committer(committer, dir, filename) - data = nil - - [*dir.split(::File::SEPARATOR), filename].each do |key| - data = data ? data[key] : committer.tree[key] - break unless data - end - - data - end - end - - module Git - class Git - def tree_entry(commit, path) - pathname = Pathname.new(path) - tmp_entry = nil - - pathname.each_filename do |dir| - tmp_entry = if tmp_entry.nil? - commit.tree[dir] - else - @repo.lookup(tmp_entry[:oid])[dir] - end - - return nil unless tmp_entry - end - tmp_entry - end - end - end -end - Rails.application.configure do config.after_initialize do Gollum::Page.per_page = Kaminari.config.default_per_page diff --git a/spec/initializers/gollum_spec.rb b/spec/initializers/gollum_spec.rb deleted file mode 100644 index adf824a8947..00000000000 --- a/spec/initializers/gollum_spec.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'spec_helper' - -describe 'gollum' do - let(:project) { create(:project) } - let(:user) { project.owner } - let(:wiki) { ProjectWiki.new(project, user) } - let(:gollum_wiki) { Gollum::Wiki.new(wiki.repository.path) } - - before do - create_page(page_name, 'content1') - end - - after do - destroy_page(page_name) - end - - context 'with simple paths' do - let(:page_name) { 'page1' } - - it 'returns the entry hash if it matches the file name' do - expect(tree_entry(page_name)).not_to be_nil - end - - it 'returns nil if the path does not fit completely' do - expect(tree_entry("foo/#{page_name}")).to be_nil - end - end - - context 'with complex paths' do - let(:page_name) { '/foo/bar/page2' } - - it 'returns the entry hash if it matches the file name' do - expect(tree_entry(page_name)).not_to be_nil - end - - it 'returns nil if the path does not fit completely' do - expect(tree_entry("foo1/bar/page2")).to be_nil - expect(tree_entry("foo/bar1/page2")).to be_nil - end - end - - def tree_entry(name) - gollum_wiki.repo.git.tree_entry(wiki_commits[0].commit, name + '.md') - end - - def wiki_commits - gollum_wiki.repo.commits - end - - def commit_details - Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "test commit") - end - - def create_page(name, content) - wiki.wiki.write_page(name, :markdown, content, commit_details) - end - - def destroy_page(name) - page = wiki.find_page(name).page - wiki.delete_page(page, "test commit") - end -end |