diff options
author | Nick Thomas <nick@gitlab.com> | 2018-10-15 18:00:59 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-10-16 12:53:30 +0100 |
commit | c7be9f5cacadf196754159515a20d4ec31cff5f1 (patch) | |
tree | 1be69619aa281818b48bd48f895f9a86d9b8b24f | |
parent | 27e9ed7a4ce2b1d97b7b8093ecde02f7c591349b (diff) | |
download | gitlab-ce-c7be9f5cacadf196754159515a20d4ec31cff5f1.tar.gz |
Remove a dependency on gitlab-gollum-lib
Removing this dependency also allows us to remove a transitive
dependency on gitlab_grit - which is the whole point of this exercise.
I don't think we can EOL gitlab_grit until it's removed as a dependency
from gitaly-ruby, but this at least gets it out of gitlab-ce.
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Gemfile.lock | 18 | ||||
-rw-r--r-- | Gemfile.rails5.lock | 18 | ||||
-rw-r--r-- | lib/gitlab/git/wiki.rb | 47 |
4 files changed, 33 insertions, 54 deletions
@@ -79,10 +79,6 @@ gem 'gpgme' gem 'gitlab_omniauth-ldap', '~> 2.0.4', require: 'omniauth-ldap' gem 'net-ldap' -# Git Wiki -# Only used to compute wiki page slugs -gem 'gitlab-gollum-lib', '~> 4.2', require: false - # API gem 'grape', '~> 1.1' gem 'grape-entity', '~> 0.7.1' diff --git a/Gemfile.lock b/Gemfile.lock index e0c098c3d8d..ccddf288f01 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -278,19 +278,6 @@ GEM google-protobuf (~> 3.1) grpc (~> 1.10) github-markup (1.7.0) - gitlab-gollum-lib (4.2.7.5) - gemojione (~> 3.2) - github-markup (~> 1.6) - gollum-grit_adapter (~> 1.0) - nokogiri (>= 1.6.1, < 2.0) - rouge (~> 3.1) - sanitize (~> 4.6.4) - stringex (~> 2.6) - gitlab-grit (2.8.2) - charlock_holmes (~> 0.6) - diff-lcs (~> 1.1) - mime-types (>= 1.16) - posix-spawn (~> 0.3) gitlab-markup (1.6.4) gitlab-sidekiq-fetcher (0.3.0) sidekiq (~> 5) @@ -305,8 +292,6 @@ GEM rubyntlm (~> 0.5) globalid (0.4.1) activesupport (>= 4.2.0) - gollum-grit_adapter (1.0.1) - gitlab-grit (~> 2.7, >= 2.7.1) gon (6.2.0) actionpack (>= 3.0) multi_json @@ -596,7 +581,6 @@ GEM pg (0.18.4) po_to_json (1.0.1) json (>= 1.6.0) - posix-spawn (0.3.13) powerpack (0.1.1) premailer (1.10.4) addressable @@ -867,7 +851,6 @@ GEM state_machines-activerecord (0.5.1) activerecord (>= 4.1, < 6.0) state_machines-activemodel (>= 0.5.0) - stringex (2.8.4) sys-filesystem (1.1.6) ffi sysexits (1.2.0) @@ -1022,7 +1005,6 @@ DEPENDENCIES gettext_i18n_rails_js (~> 1.3) gitaly-proto (~> 0.118.1) github-markup (~> 1.7.0) - gitlab-gollum-lib (~> 4.2) gitlab-markup (~> 1.6.4) gitlab-sidekiq-fetcher gitlab-styles (~> 2.4) diff --git a/Gemfile.rails5.lock b/Gemfile.rails5.lock index 56db3b4c9de..59dc829cb48 100644 --- a/Gemfile.rails5.lock +++ b/Gemfile.rails5.lock @@ -281,19 +281,6 @@ GEM google-protobuf (~> 3.1) grpc (~> 1.10) github-markup (1.7.0) - gitlab-gollum-lib (4.2.7.5) - gemojione (~> 3.2) - github-markup (~> 1.6) - gollum-grit_adapter (~> 1.0) - nokogiri (>= 1.6.1, < 2.0) - rouge (~> 3.1) - sanitize (~> 4.6.4) - stringex (~> 2.6) - gitlab-grit (2.8.2) - charlock_holmes (~> 0.6) - diff-lcs (~> 1.1) - mime-types (>= 1.16) - posix-spawn (~> 0.3) gitlab-markup (1.6.4) gitlab-sidekiq-fetcher (0.3.0) sidekiq (~> 5) @@ -308,8 +295,6 @@ GEM rubyntlm (~> 0.5) globalid (0.4.1) activesupport (>= 4.2.0) - gollum-grit_adapter (1.0.1) - gitlab-grit (~> 2.7, >= 2.7.1) gon (6.2.0) actionpack (>= 3.0) multi_json @@ -600,7 +585,6 @@ GEM pg (0.18.4) po_to_json (1.0.1) json (>= 1.6.0) - posix-spawn (0.3.13) powerpack (0.1.1) premailer (1.10.4) addressable @@ -875,7 +859,6 @@ GEM state_machines-activerecord (0.5.1) activerecord (>= 4.1, < 6.0) state_machines-activemodel (>= 0.5.0) - stringex (2.8.4) sys-filesystem (1.1.6) ffi sysexits (1.2.0) @@ -1031,7 +1014,6 @@ DEPENDENCIES gettext_i18n_rails_js (~> 1.3) gitaly-proto (~> 0.118.1) github-markup (~> 1.7.0) - gitlab-gollum-lib (~> 4.2) gitlab-markup (~> 1.6.4) gitlab-sidekiq-fetcher gitlab-styles (~> 2.4) diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 072019dfb0a..563712c5d63 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -1,8 +1,3 @@ -# 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 @@ -18,6 +13,38 @@ module Gitlab end PageBlob = Struct.new(:name) + # GollumSlug inlines just enough knowledge from Gollum::Page to generate a + # slug, which is used when previewing pages that haven't been persisted + class GollumSlug + class << self + def format_to_ext(format) + format == :markdown ? 'md' : format.to_s + end + + def cname(name, char_white_sub = '-', char_other_sub = '-') + if name.respond_to?(:gsub) + name.gsub(/\s/, char_white_sub).gsub(/[<>+]/, char_other_sub) + else + '' + end + end + + def generate(title, format) + name = cname(title) + '.' + format_to_ext(format) + blob = PageBlob.new(name) + + path = + if blob.name.include?('/') + blob.name.sub(%r{/[^/]+$}, '/') + else + '' + end + + path + cname(name) + end + end + end + attr_reader :repository def self.default_ref @@ -90,15 +117,7 @@ module Gitlab end def preview_slug(title, format) - # Adapted from gollum gem (Gollum::Wiki#preview_page) to avoid - # using Rugged through a Gollum::Wiki instance - page_class = Gollum::Page - page = page_class.new(nil) - ext = page_class.format_to_ext(format.to_sym) - name = page_class.cname(title) + '.' + ext - blob = PageBlob.new(name) - page.populate(blob) - page.url_path + GollumSlug.generate(title, format) end def page_formatted_data(title:, dir: nil, version: nil) |