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
a480ee18
Commit
a480ee18
authored
Feb 06, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zj/gitlab-ce-zj-wiki-page-versions'
parents
245d9375
5db5a9cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
19 deletions
+75
-19
app/controllers/projects/wikis_controller.rb
app/controllers/projects/wikis_controller.rb
+2
-2
lib/gitlab/git/wiki.rb
lib/gitlab/git/wiki.rb
+16
-4
lib/gitlab/gitaly_client/wiki_service.rb
lib/gitlab/gitaly_client/wiki_service.rb
+33
-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 @
a480ee18
...
@@ -76,9 +76,9 @@ class Projects::WikisController < Projects::ApplicationController
...
@@ -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
),
...
...
lib/gitlab/git/wiki.rb
View file @
a480ee18
...
@@ -96,11 +96,23 @@ module Gitlab
...
@@ -96,11 +96,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
)
@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
|
commits_from_page
(
current_page
,
options
).
map
do
|
gitlab_git_commit
|
gollum_page
=
gollum_wiki
.
page
(
current_page
.
title
,
gitlab_git_commit
.
id
)
gollum_page
=
gollum_wiki
.
page
(
current_page
.
title
,
gitlab_git_commit
.
id
)
Gitlab
::
Git
::
WikiPageVersion
.
new
(
gitlab_git_commit
,
gollum_page
&
.
format
)
Gitlab
::
Git
::
WikiPageVersion
.
new
(
gitlab_git_commit
,
gollum_page
&
.
format
)
end
end
end
end
end
end
...
...
lib/gitlab/gitaly_client/wiki_service.rb
View file @
a480ee18
...
@@ -101,6 +101,30 @@ module Gitlab
...
@@ -101,6 +101,30 @@ 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
),
page:
options
[
:page
]
||
1
,
per_page:
options
[
:per_page
]
||
Gollum
::
Page
.
per_page
)
stream
=
GitalyClient
.
call
(
@repository
.
storage
,
:wiki_service
,
:wiki_get_page_versions
,
request
)
versions
=
[]
stream
.
each
do
|
message
|
message
.
versions
.
each
do
|
version
|
versions
<<
new_wiki_page_version
(
version
)
end
end
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
,
...
@@ -141,7 +165,7 @@ module Gitlab
...
@@ -141,7 +165,7 @@ module Gitlab
private
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.
# 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
)
...
@@ -158,10 +182,7 @@ module Gitlab
...
@@ -158,10 +182,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
...
@@ -170,6 +191,13 @@ module Gitlab
...
@@ -170,6 +191,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
),
...
...
spec/models/wiki_page_spec.rb
View file @
a480ee18
...
@@ -364,18 +364,34 @@ describe WikiPage do
...
@@ -364,18 +364,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
...
...
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