Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-07-12 14:28:04 +0300
committerJacob Vosmaer <jacob@gitlab.com>2018-07-12 14:28:04 +0300
commit0a8dfe349b353e9735611f6764feb7b59d67c367 (patch)
tree6a1586a20e07851f166b9be21b42c6af99c05fc5
parent8f5108a6837ca5e92dd28d7928818cdb4f815ece (diff)
Move git/wiki*.rb out of vendor
-rwxr-xr-x_support/vendor-gitlab-git4
-rw-r--r--ruby/lib/gitlab/git/wiki.rb174
-rw-r--r--ruby/lib/gitlab/git/wiki_file.rb (renamed from ruby/vendor/gitlab_git/lib/gitlab/git/wiki_file.rb)0
-rw-r--r--ruby/lib/gitlab/git/wiki_page.rb (renamed from ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page.rb)0
-rw-r--r--ruby/lib/gitlab/git/wiki_page_version.rb (renamed from ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page_version.rb)0
-rw-r--r--ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb182
6 files changed, 101 insertions, 259 deletions
diff --git a/_support/vendor-gitlab-git b/_support/vendor-gitlab-git
index 7e7510bab..8e4d768ed 100755
--- a/_support/vendor-gitlab-git
+++ b/_support/vendor-gitlab-git
@@ -20,6 +20,10 @@ EXCLUDE = %w[
lib/gitlab/git/storage/
lib/gitlab/git/storage.rb
lib/gitlab/git/tree.rb
+ lib/gitlab/git/wiki.rb
+ lib/gitlab/git/wiki_file.rb
+ lib/gitlab/git/wiki_page.rb
+ lib/gitlab/git/wiki_page_version.rb
].freeze
REMOTE = 'https://gitlab.com/gitlab-org/gitlab-ce'.freeze
diff --git a/ruby/lib/gitlab/git/wiki.rb b/ruby/lib/gitlab/git/wiki.rb
index b3711a6b9..c39f753f2 100644
--- a/ruby/lib/gitlab/git/wiki.rb
+++ b/ruby/lib/gitlab/git/wiki.rb
@@ -1,109 +1,90 @@
module Gitlab
module Git
class Wiki
- def write_page(name, format, content, commit_details)
- @repository.gitaly_migrate(:wiki_write_page) do |is_enabled|
- if is_enabled
- gitaly_write_page(name, format, content, commit_details)
- else
- gollum_write_page(name, format, content, commit_details)
- end
+ DuplicatePageError = Class.new(StandardError)
+ OperationError = Class.new(StandardError)
+
+ CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do
+ def to_h
+ { user_id: user_id, username: username, name: name, email: email, message: message }
end
end
+ PageBlob = Struct.new(:name)
- def update_page(page_path, title, format, content, commit_details)
- @repository.gitaly_migrate(:wiki_update_page) do |is_enabled|
- if is_enabled
- gitaly_update_page(page_path, title, format, content, commit_details)
- else
- gollum_update_page(page_path, title, format, content, commit_details)
- end
- end
+ attr_reader :repository
+
+ def self.default_ref
+ 'master'
+ end
+
+ # Initialize with a Gitlab::Git::Repository instance
+ def initialize(repository)
+ @repository = repository
+ end
+
+ def repository_exists?
+ @repository.exists?
+ end
+
+ def write_page(name, format, content, commit_details)
+ gollum_write_page(name, format, content, commit_details)
end
def delete_page(page_path, commit_details)
- @repository.gitaly_migrate(:wiki_delete_page) do |is_enabled|
- if is_enabled
- gitaly_delete_page(page_path, commit_details)
- else
- gollum_delete_page(page_path, commit_details)
- end
- end
+ gollum_delete_page(page_path, commit_details)
end
- def pages(limit: nil)
- @repository.gitaly_migrate(:wiki_get_all_pages) do |is_enabled|
- if is_enabled
- gitaly_get_all_pages
- else
- gollum_get_all_pages(limit: limit)
- end
- end
+ def update_page(page_path, title, format, content, commit_details)
+ gollum_update_page(page_path, title, format, content, commit_details)
end
+ def pages(limit: nil)
+ gollum_get_all_pages(limit: limit)
+ end
def page(title:, version: nil, dir: nil)
- @repository.gitaly_migrate(:wiki_find_page,
- status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
- if is_enabled
- gitaly_find_page(title: title, version: version, dir: dir)
- else
- gollum_find_page(title: title, version: version, dir: dir)
- end
- end
+ gollum_find_page(title: title, version: version, dir: dir)
end
def file(name, version)
- @repository.gitaly_migrate(:wiki_find_file) do |is_enabled|
- if is_enabled
- gitaly_find_file(name, version)
- else
- gollum_find_file(name, version)
- end
- end
+ gollum_find_file(name, version)
end
+ # options:
+ # :page - The Integer page number.
# :per_page - The number of items per page.
# :limit - Total number of items to return.
def page_versions(page_path, options = {})
- @repository.gitaly_migrate(:wiki_page_versions) do |is_enabled|
- if is_enabled
- versions = gitaly_wiki_client.page_versions(page_path, options)
-
- # 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
- versions[0..slice_bound]
- else
- current_page = gollum_page_by_path(page_path)
-
- commits_from_page(current_page, options).map do |gitlab_git_commit|
- gollum_page = gollum_wiki.page(current_page.title, gitlab_git_commit.id)
- Gitlab::Git::WikiPageVersion.new(gitlab_git_commit, gollum_page&.format)
- end
- end
-
- # 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
- versions[0..slice_bound]
+ current_page = gollum_page_by_path(page_path)
+
+ commits_from_page(current_page, options).map do |gitlab_git_commit|
+ gollum_page = gollum_wiki.page(current_page.title, gitlab_git_commit.id)
+ Gitlab::Git::WikiPageVersion.new(gitlab_git_commit, gollum_page&.format)
end
end
+ def count_page_versions(page_path)
+ @repository.count_commits(ref: 'HEAD', path: page_path)
+ 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
+ end
+
def page_formatted_data(title:, dir: nil, version: nil)
version = version&.id
- @repository.gitaly_migrate(:wiki_page_formatted_data, status: Gitlab::GitalyClient::MigrationStatus::OPT_OUT) do |is_enabled|
- if is_enabled
- gitaly_wiki_client.get_formatted_data(title: title, dir: dir, version: version)
- else
- # We don't use #page because if wiki_find_page feature is enabled, we would
- # get a page without formatted_data.
- gollum_find_page(title: title, dir: dir, version: version)&.formatted_data
- end
- end
+ # We don't use #page because if wiki_find_page feature is enabled, we would
+ # get a page without formatted_data.
+ gollum_find_page(title: title, dir: dir, version: version)&.formatted_data
end
def gollum_wiki
@@ -112,6 +93,44 @@ 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) }
+
+ if RequestStore.active?
+ RequestStore.fetch([:wiki_version_commit, commit_id]) { commit_find_proc.call }
+ else
+ commit_find_proc.call
+ end
+ end
+
+ def assert_type!(object, klass)
+ unless object.is_a?(klass)
+ raise ArgumentError, "expected a #{klass}, got #{object.inspect}"
+ end
+ end
+
+ def committer_with_hooks(commit_details)
+ Gitlab::Git::CommitterWithHooks.new(self, commit_details.to_h)
+ end
+
+ def with_committer_with_hooks(commit_details, &block)
+ committer = committer_with_hooks(commit_details)
+
+ yield committer
+
+ committer.commit
+
+ nil
+ end
+
# options:
# :page - The Integer page number.
# :per_page - The number of items per page.
@@ -197,6 +216,7 @@ module Gitlab
def gollum_get_all_pages(limit: nil)
gollum_wiki.pages(limit: limit).map { |gollum_page| new_page(gollum_page) }
end
+
end
end
end
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_file.rb b/ruby/lib/gitlab/git/wiki_file.rb
index 84335aca4..84335aca4 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_file.rb
+++ b/ruby/lib/gitlab/git/wiki_file.rb
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page.rb b/ruby/lib/gitlab/git/wiki_page.rb
index 669ae11a4..669ae11a4 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page.rb
+++ b/ruby/lib/gitlab/git/wiki_page.rb
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page_version.rb b/ruby/lib/gitlab/git/wiki_page_version.rb
index 55f1afedc..55f1afedc 100644
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki_page_version.rb
+++ b/ruby/lib/gitlab/git/wiki_page_version.rb
diff --git a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb b/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb
deleted file mode 100644
index 8ee46b598..000000000
--- a/ruby/vendor/gitlab_git/lib/gitlab/git/wiki.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-module Gitlab
- module Git
- class Wiki
- DuplicatePageError = Class.new(StandardError)
- OperationError = Class.new(StandardError)
-
- CommitDetails = Struct.new(:user_id, :username, :name, :email, :message) do
- def to_h
- { user_id: user_id, username: username, name: name, email: email, message: message }
- end
- end
- PageBlob = Struct.new(:name)
-
- attr_reader :repository
-
- def self.default_ref
- 'master'
- end
-
- # Initialize with a Gitlab::Git::Repository instance
- def initialize(repository)
- @repository = repository
- end
-
- def repository_exists?
- @repository.exists?
- end
-
- def write_page(name, format, content, commit_details)
- @repository.wrapped_gitaly_errors do
- gitaly_write_page(name, format, content, commit_details)
- end
- end
-
- def delete_page(page_path, commit_details)
- @repository.wrapped_gitaly_errors do
- gitaly_delete_page(page_path, commit_details)
- end
- end
-
- def update_page(page_path, title, format, content, commit_details)
- @repository.wrapped_gitaly_errors do
- gitaly_update_page(page_path, title, format, content, commit_details)
- end
- end
-
- def pages(limit: nil)
- @repository.wrapped_gitaly_errors do
- gitaly_get_all_pages
- end
- end
-
- def page(title:, version: nil, dir: nil)
- @repository.wrapped_gitaly_errors do
- gitaly_find_page(title: title, version: version, dir: dir)
- end
- end
-
- def file(name, version)
- @repository.wrapped_gitaly_errors do
- gitaly_find_file(name, version)
- end
- end
-
- # options:
- # :page - The Integer page number.
- # :per_page - The number of items per page.
- # :limit - Total number of items to return.
- def page_versions(page_path, options = {})
- versions = @repository.wrapped_gitaly_errors do
- gitaly_wiki_client.page_versions(page_path, options)
- end
-
- # 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
- versions[0..slice_bound]
- end
-
- def count_page_versions(page_path)
- @repository.count_commits(ref: 'HEAD', path: page_path)
- 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
- end
-
- def page_formatted_data(title:, dir: nil, version: nil)
- version = version&.id
-
- @repository.wrapped_gitaly_errors do
- gitaly_wiki_client.get_formatted_data(title: title, dir: dir, version: version)
- end
- end
-
- 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) }
-
- if RequestStore.active?
- RequestStore.fetch([:wiki_version_commit, commit_id]) { commit_find_proc.call }
- else
- commit_find_proc.call
- 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
-
- def gitaly_write_page(name, format, content, commit_details)
- gitaly_wiki_client.write_page(name, format, content, commit_details)
- end
-
- def gitaly_update_page(page_path, title, format, content, commit_details)
- gitaly_wiki_client.update_page(page_path, title, format, content, commit_details)
- end
-
- def gitaly_delete_page(page_path, commit_details)
- gitaly_wiki_client.delete_page(page_path, commit_details)
- end
-
- def gitaly_find_page(title:, version: nil, dir: nil)
- wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir)
- return unless wiki_page
-
- Gitlab::Git::WikiPage.new(wiki_page, version)
- end
-
- def gitaly_find_file(name, version)
- wiki_file = gitaly_wiki_client.find_file(name, version)
- return unless wiki_file
-
- Gitlab::Git::WikiFile.new(wiki_file)
- end
-
- def gitaly_get_all_pages
- gitaly_wiki_client.get_all_pages.map do |wiki_page, version|
- Gitlab::Git::WikiPage.new(wiki_page, version)
- end
- end
-
- def committer_with_hooks(commit_details)
- Gitlab::Git::CommitterWithHooks.new(self, commit_details.to_h)
- end
-
- def with_committer_with_hooks(commit_details, &block)
- committer = committer_with_hooks(commit_details)
-
- yield committer
-
- committer.commit
-
- nil
- end
- end
- end
-end