Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
1c0437d9
Commit
1c0437d9
authored
Jan 02, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client implementation for WikiPageVerion
Part of gitlab-org/gitaly#639
parent
bd7a387b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
25 deletions
+105
-25
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+2
-2
lib/gitlab/git/wiki.rb
lib/gitlab/git/wiki.rb
+28
-10
lib/gitlab/gitaly_client/wiki_service.rb
lib/gitlab/gitaly_client/wiki_service.rb
+51
-5
spec/models/wiki_page_spec.rb
spec/models/wiki_page_spec.rb
+24
-8
No files found.
app/controllers/projects/wikis_controller.rb
View file @
1c0437d9
...
...
@@ -76,9 +76,9 @@ class Projects::WikisController < Projects::ApplicationController
@page
=
@project_wiki
.
find_page
(
params
[
:id
])
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
)
.
page
(
params
[
:page
])
.
page
(
params
[
:page
])
else
redirect_to
(
project_wiki_path
(
@project
,
:home
),
...
...
lib/gitlab/git/wiki.rb
View file @
1c0437d9
...
...
@@ -93,11 +93,23 @@ module Gitlab
# :per_page - The number of items per page.
# :limit - Total number of items to return.
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
|
gollum_page
=
gollum_wiki
.
page
(
current_page
.
title
,
gitlab_git_commit
.
id
)
Gitlab
::
Git
::
WikiPageVersion
.
new
(
gitlab_git_commit
,
gollum_page
&
.
format
)
byebug
@repository
.
gitaly_migrate
(
:wiki_page_versions
)
do
|
is_enabled
|
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
...
...
@@ -124,15 +136,21 @@ module Gitlab
# :per_page - The number of items per page.
# :limit - Total number of items to return.
def
commits_from_page
(
gollum_page
,
options
=
{})
unless
options
[
:limit
]
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
pagination_options
=
pagination_params
(
options
)
@repository
.
log
(
ref:
gollum_page
.
last_version
.
id
,
path:
gollum_page
.
path
,
limit:
options
[
:limit
],
offset:
options
[
:offset
])
limit:
pagination_options
[
:limit
],
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
def
gollum_wiki
...
...
lib/gitlab/gitaly_client/wiki_service.rb
View file @
1c0437d9
...
...
@@ -101,6 +101,48 @@ module Gitlab
pages
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
)
request
=
Gitaly
::
WikiFindFileRequest
.
new
(
repository:
@gitaly_repo
,
...
...
@@ -129,7 +171,7 @@ module Gitlab
private
# If a block is given and the yielded value is tru
e
, iteration will be
# If a block is given and the yielded value is tru
thy
, iteration will be
# stopped early at that point; else the iterator is consumed entirely.
# The iterator is traversed with `next` to allow resuming the iteration.
def
wiki_page_from_iterator
(
iterator
)
...
...
@@ -146,10 +188,7 @@ module Gitlab
else
wiki_page
=
GitalyClient
::
WikiPage
.
new
(
page
.
to_h
)
version
=
Gitlab
::
Git
::
WikiPageVersion
.
new
(
Gitlab
::
Git
::
Commit
.
decorate
(
@repository
,
page
.
version
.
commit
),
page
.
version
.
format
)
version
=
new_wiki_page_version
(
page
.
version
)
end
end
...
...
@@ -158,6 +197,13 @@ module Gitlab
[
wiki_page
,
version
]
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
)
Gitaly
::
WikiCommitDetails
.
new
(
name:
encode_binary
(
commit_details
.
name
),
...
...
spec/models/wiki_page_spec.rb
View file @
1c0437d9
...
...
@@ -252,18 +252,34 @@ describe WikiPage do
end
describe
"#versions"
do
before
do
create_page
(
"Update"
,
"content"
)
@page
=
wiki
.
find_page
(
"Update"
)
shared_examples
'wiki page versions'
do
let
(
: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
after
do
destroy_page
(
"Update"
)
context
'when Gitaly is enabled'
do
it_behaves_like
'wiki page versions'
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
)
context
'when Gitaly is disabled'
,
:disable_gitaly
do
it_behaves_like
'wiki page versions'
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment