summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-01-10 16:19:18 +0100
committerFrancisco Javier López <fjlopez@gitlab.com>2018-02-05 09:39:43 +0100
commit1f54892d375a07c3f083370183df0dc9783ff4a8 (patch)
tree17c349435d5f6749c2faa3e8dfd61b416406f608
parentcf887a8b3108edb715ee5618377f4ffab1824d85 (diff)
downloadgitlab-ce-1f54892d375a07c3f083370183df0dc9783ff4a8.tar.gz
Some monkey patches to make it work
-rw-r--r--config/initializers/gollum.rb73
-rw-r--r--lib/gitlab/git/wiki.rb12
2 files changed, 83 insertions, 2 deletions
diff --git a/config/initializers/gollum.rb b/config/initializers/gollum.rb
index 0b86cac51a7..0c9f3acf965 100644
--- a/config/initializers/gollum.rb
+++ b/config/initializers/gollum.rb
@@ -35,6 +35,79 @@ module Gollum
[]
end
end
+
+ def update_page(page, name, format, data, commit = {})
+ name = name.present? ? ::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
+
+ def rename_page(page, rename, commit = {})
+ return false if page.nil?
+ return false if rename.nil? or 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(/^\//, '')
+
+ # if the rename is a NOOP, abort
+ if source_dir == target_dir and 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_commiter(committer, source_dir, page.filename) ||
+ raw_data_in_commiter(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
+
+ def raw_data_in_commiter(committer, dir, filename)
+ committer.tree.dig(dir, filename)
+ end
end
module Git
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb
index ccdb8975342..0a0d9172984 100644
--- a/lib/gitlab/git/wiki.rb
+++ b/lib/gitlab/git/wiki.rb
@@ -48,7 +48,7 @@ module Gitlab
end
def update_page(page_path, title, format, content, commit_details)
- @repository.gitaly_migrate(:wiki_update_page) do |is_enabled|
+ @repository.gitaly_migrate(:wiki_update_page, status: Gitlab::GitalyClient::MigrationStatus::DISABLED) do |is_enabled|
if is_enabled
gitaly_update_page(page_path, title, format, content, commit_details)
gollum_wiki.clear_cache
@@ -210,7 +210,15 @@ module Gitlab
assert_type!(format, Symbol)
assert_type!(commit_details, CommitDetails)
- gollum_wiki.update_page(gollum_page_by_path(page_path), title, format, content, commit_details.to_h)
+ page = gollum_page_by_path(page_path)
+ committer = Gollum::Committer.new(page.wiki, commit_details.to_h)
+
+ # Instead of performing two renames if the title has changed,
+ # the update_page will only update the format and content and
+ # the rename_page will do anything related to moving/renaming
+ gollum_wiki.update_page(page, page.name, format, content, committer: committer)
+ gollum_wiki.rename_page(page, title, committer: committer)
+ committer.commit
nil
end