parent
bd7a387b43
commit
1c0437d95e
|
@ -76,9 +76,9 @@ class Projects::WikisController < Projects::ApplicationController
|
||||||
@page = @project_wiki.find_page(params[:id])
|
@page = @project_wiki.find_page(params[:id])
|
||||||
|
|
||||||
if @page
|
if @page
|
||||||
@page_versions = Kaminari.paginate_array(@page.versions(page: params[:page]),
|
@page_versions = Kaminari.paginate_array(@page.versions(page: params[:page].to_i),
|
||||||
total_count: @page.count_versions)
|
total_count: @page.count_versions)
|
||||||
.page(params[:page])
|
.page(params[:page])
|
||||||
else
|
else
|
||||||
redirect_to(
|
redirect_to(
|
||||||
project_wiki_path(@project, :home),
|
project_wiki_path(@project, :home),
|
||||||
|
|
|
@ -93,11 +93,23 @@ module Gitlab
|
||||||
# :per_page - The number of items per page.
|
# :per_page - The number of items per page.
|
||||||
# :limit - Total number of items to return.
|
# :limit - Total number of items to return.
|
||||||
def page_versions(page_path, options = {})
|
def page_versions(page_path, options = {})
|
||||||
current_page = gollum_page_by_path(page_path)
|
puts '-' * 80
|
||||||
|
puts options
|
||||||
|
puts '-' * 80
|
||||||
|
puts
|
||||||
|
|
||||||
commits_from_page(current_page, options).map do |gitlab_git_commit|
|
byebug
|
||||||
gollum_page = gollum_wiki.page(current_page.title, gitlab_git_commit.id)
|
@repository.gitaly_migrate(:wiki_page_versions) do |is_enabled|
|
||||||
Gitlab::Git::WikiPageVersion.new(gitlab_git_commit, gollum_page&.format)
|
if is_enabled
|
||||||
|
gitaly_wiki_client.page_versions(page_path, pagination_params(options))
|
||||||
|
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
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,15 +136,21 @@ module Gitlab
|
||||||
# :per_page - The number of items per page.
|
# :per_page - The number of items per page.
|
||||||
# :limit - Total number of items to return.
|
# :limit - Total number of items to return.
|
||||||
def commits_from_page(gollum_page, options = {})
|
def commits_from_page(gollum_page, options = {})
|
||||||
unless options[:limit]
|
pagination_options = pagination_params(options)
|
||||||
options[:offset] = ([1, options.delete(:page).to_i].max - 1) * Gollum::Page.per_page
|
|
||||||
options[:limit] = (options.delete(:per_page) || Gollum::Page.per_page).to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
@repository.log(ref: gollum_page.last_version.id,
|
@repository.log(ref: gollum_page.last_version.id,
|
||||||
path: gollum_page.path,
|
path: gollum_page.path,
|
||||||
limit: options[:limit],
|
limit: pagination_options[:limit],
|
||||||
offset: options[:offset])
|
offset: pagination_options[:offset])
|
||||||
|
end
|
||||||
|
|
||||||
|
def pagination_params(options)
|
||||||
|
return options if options[:limit]
|
||||||
|
|
||||||
|
options = options.dup
|
||||||
|
options[:offset] = ([1, options.delete(:page).to_i].max - 1) * Gollum::Page.per_page
|
||||||
|
options[:limit] = (options.delete(:per_page) || Gollum::Page.per_page).to_i
|
||||||
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def gollum_wiki
|
def gollum_wiki
|
||||||
|
|
|
@ -101,6 +101,48 @@ module Gitlab
|
||||||
pages
|
pages
|
||||||
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)
|
||||||
|
request = Gitaly::WikiGetPageVersionsRequest.new(
|
||||||
|
repository: @gitaly_repo,
|
||||||
|
page_path: encode_binary(page_path)
|
||||||
|
)
|
||||||
|
|
||||||
|
min_index = options[:offset].to_i
|
||||||
|
max_index = min_index + options[:limit].to_i
|
||||||
|
byebug
|
||||||
|
|
||||||
|
stream = GitalyClient.call(@repository.storage, :wiki_service, :wiki_get_page_versions, request)
|
||||||
|
|
||||||
|
version_index = 0
|
||||||
|
versions = []
|
||||||
|
|
||||||
|
# Allow limit and offset to be send to Gitaly: TODO
|
||||||
|
stream.each do |message|
|
||||||
|
puts '§' * 80
|
||||||
|
puts version_index
|
||||||
|
|
||||||
|
message.versions.each do |version|
|
||||||
|
case version_index
|
||||||
|
when min_index...max_index
|
||||||
|
versions << new_wiki_page_version(version)
|
||||||
|
when max_index..Float::INFINITY
|
||||||
|
return versions
|
||||||
|
end
|
||||||
|
|
||||||
|
version_index += 1
|
||||||
|
puts version_index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# when we're requesting page 99 but the stream doesn't go that far, whatever
|
||||||
|
# is fetched thus far
|
||||||
|
versions
|
||||||
|
end
|
||||||
|
|
||||||
def find_file(name, revision)
|
def find_file(name, revision)
|
||||||
request = Gitaly::WikiFindFileRequest.new(
|
request = Gitaly::WikiFindFileRequest.new(
|
||||||
repository: @gitaly_repo,
|
repository: @gitaly_repo,
|
||||||
|
@ -129,7 +171,7 @@ module Gitlab
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# If a block is given and the yielded value is true, iteration will be
|
# If a block is given and the yielded value is truthy, iteration will be
|
||||||
# stopped early at that point; else the iterator is consumed entirely.
|
# stopped early at that point; else the iterator is consumed entirely.
|
||||||
# The iterator is traversed with `next` to allow resuming the iteration.
|
# The iterator is traversed with `next` to allow resuming the iteration.
|
||||||
def wiki_page_from_iterator(iterator)
|
def wiki_page_from_iterator(iterator)
|
||||||
|
@ -146,10 +188,7 @@ module Gitlab
|
||||||
else
|
else
|
||||||
wiki_page = GitalyClient::WikiPage.new(page.to_h)
|
wiki_page = GitalyClient::WikiPage.new(page.to_h)
|
||||||
|
|
||||||
version = Gitlab::Git::WikiPageVersion.new(
|
version = new_wiki_page_version(page.version)
|
||||||
Gitlab::Git::Commit.decorate(@repository, page.version.commit),
|
|
||||||
page.version.format
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -158,6 +197,13 @@ module Gitlab
|
||||||
[wiki_page, version]
|
[wiki_page, version]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_wiki_page_version(version)
|
||||||
|
Gitlab::Git::WikiPageVersion.new(
|
||||||
|
Gitlab::Git::Commit.decorate(@repository, version.commit),
|
||||||
|
version.format
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def gitaly_commit_details(commit_details)
|
def gitaly_commit_details(commit_details)
|
||||||
Gitaly::WikiCommitDetails.new(
|
Gitaly::WikiCommitDetails.new(
|
||||||
name: encode_binary(commit_details.name),
|
name: encode_binary(commit_details.name),
|
||||||
|
|
|
@ -252,18 +252,34 @@ describe WikiPage do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#versions" do
|
describe "#versions" do
|
||||||
before do
|
shared_examples 'wiki page versions' do
|
||||||
create_page("Update", "content")
|
let(:page) { wiki.find_page("Update") }
|
||||||
@page = wiki.find_page("Update")
|
|
||||||
|
before do
|
||||||
|
create_page("Update", "content")
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
destroy_page("Update")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an array of all commits for the page" do
|
||||||
|
3.times { |i| page.update(content: "content #{i}") }
|
||||||
|
|
||||||
|
expect(page.versions.count).to eq(4)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns instances of WikiPageVersion' do
|
||||||
|
expect(page.versions).to all( be_a(Gitlab::Git::WikiPageVersion) )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
context 'when Gitaly is enabled' do
|
||||||
destroy_page("Update")
|
it_behaves_like 'wiki page versions'
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns an array of all commits for the page" do
|
context 'when Gitaly is disabled', :disable_gitaly do
|
||||||
3.times { |i| @page.update(content: "content #{i}") }
|
it_behaves_like 'wiki page versions'
|
||||||
expect(@page.versions.count).to eq(4)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue