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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ec78d29a
Commit
ec78d29a
authored
Jun 28, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FindAllCommits mandatory
Closes
https://gitlab.com/gitlab-org/gitaly/issues/326
parent
eaa9d4fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
115 deletions
+38
-115
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+2
-49
spec/lib/gitlab/git/commit_spec.rb
spec/lib/gitlab/git/commit_spec.rb
+36
-66
No files found.
lib/gitlab/git/commit.rb
View file @
ec78d29a
...
@@ -149,58 +149,11 @@ module Gitlab
...
@@ -149,58 +149,11 @@ module Gitlab
#
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/326
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/326
def
find_all
(
repo
,
options
=
{})
def
find_all
(
repo
,
options
=
{})
Gitlab
::
GitalyClient
.
migrate
(
:find_all_commits
)
do
|
is_enabled
|
repo
.
wrapped_gitaly_errors
do
if
is_enabled
Gitlab
::
GitalyClient
::
CommitService
.
new
(
repo
).
find_all_commits
(
options
)
find_all_by_gitaly
(
repo
,
options
)
else
find_all_by_rugged
(
repo
,
options
)
end
end
end
end
end
def
find_all_by_rugged
(
repo
,
options
=
{})
actual_options
=
options
.
dup
allowed_options
=
[
:ref
,
:max_count
,
:skip
,
:order
]
actual_options
.
keep_if
do
|
key
|
allowed_options
.
include?
(
key
)
end
default_options
=
{
skip:
0
}
actual_options
=
default_options
.
merge
(
actual_options
)
rugged
=
repo
.
rugged
walker
=
Rugged
::
Walker
.
new
(
rugged
)
if
actual_options
[
:ref
]
walker
.
push
(
rugged
.
rev_parse_oid
(
actual_options
[
:ref
]))
else
rugged
.
references
.
each
(
"refs/heads/*"
)
do
|
ref
|
walker
.
push
(
ref
.
target_id
)
end
end
walker
.
sorting
(
rugged_sort_type
(
actual_options
[
:order
]))
commits
=
[]
offset
=
actual_options
[
:skip
]
limit
=
actual_options
[
:max_count
]
walker
.
each
(
offset:
offset
,
limit:
limit
)
do
|
commit
|
commits
.
push
(
decorate
(
repo
,
commit
))
end
walker
.
reset
commits
rescue
Rugged
::
OdbError
[]
end
def
find_all_by_gitaly
(
repo
,
options
=
{})
Gitlab
::
GitalyClient
::
CommitService
.
new
(
repo
).
find_all_commits
(
options
)
end
def
decorate
(
repository
,
commit
,
ref
=
nil
)
def
decorate
(
repository
,
commit
,
ref
=
nil
)
Gitlab
::
Git
::
Commit
.
new
(
repository
,
commit
,
ref
)
Gitlab
::
Git
::
Commit
.
new
(
repository
,
commit
,
ref
)
end
end
...
...
spec/lib/gitlab/git/commit_spec.rb
View file @
ec78d29a
...
@@ -331,84 +331,54 @@ describe Gitlab::Git::Commit, seed_helper: true do
...
@@ -331,84 +331,54 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
end
describe
'.find_all'
do
describe
'.find_all'
do
shared_examples
'finding all commits'
do
it
'should return a return a collection of commits'
do
it
'should return a return a collection of commits'
do
commits
=
described_class
.
find_all
(
repository
)
commits
=
described_class
.
find_all
(
repository
)
expect
(
commits
).
to
all
(
be_a_kind_of
(
described_class
)
)
expect
(
commits
).
to
all
(
be_a_kind_of
(
described_class
)
)
end
end
context
'max_count'
do
subject
do
commits
=
described_class
.
find_all
(
repository
,
max_count:
50
)
commits
.
map
(
&
:id
)
end
it
'has 34 elements'
do
context
'max_count'
do
expect
(
subject
.
size
).
to
eq
(
34
)
subject
do
end
commits
=
described_class
.
find_all
(
repository
,
max_count:
50
)
it
'includes the expected commits'
do
commits
.
map
(
&
:id
)
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
Commit
::
PARENT_ID
,
SeedRepo
::
FirstCommit
::
ID
)
end
end
end
context
'ref + max_count + skip'
do
it
'has 34 elements'
do
subject
do
expect
(
subject
.
size
).
to
eq
(
34
)
commits
=
described_class
.
find_all
(
repository
,
ref:
'master'
,
max_count:
50
,
skip:
1
)
commits
.
map
(
&
:id
)
end
it
'has 24 elements'
do
expect
(
subject
.
size
).
to
eq
(
24
)
end
it
'includes the expected commits'
do
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
FirstCommit
::
ID
)
expect
(
subject
).
not_to
include
(
SeedRepo
::
LastCommit
::
ID
)
end
end
end
end
context
'when Gitaly find_all_commits feature is enabled'
do
it
'includes the expected commits'
do
it_behaves_like
'finding all commits'
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
Commit
::
PARENT_ID
,
SeedRepo
::
FirstCommit
::
ID
)
end
end
end
context
'when Gitaly find_all_commits feature is disabled'
,
:skip_gitaly_mock
do
context
'ref + max_count + skip'
do
it_behaves_like
'finding all commits'
subject
do
commits
=
described_class
.
find_all
(
context
'while applying a sort order based on the `order` option'
do
repository
,
it
"allows ordering topologically (no parents shown before their children)"
do
ref:
'master'
,
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_TOPO
)
max_count:
50
,
skip:
1
described_class
.
find_all
(
repository
,
order: :topo
)
)
end
it
"allows ordering by date"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_DATE
|
Rugged
::
SORT_TOPO
)
described_class
.
find_all
(
repository
,
order: :date
)
commits
.
map
(
&
:id
)
end
end
it
"applies no sorting by default"
do
it
'has 24 elements'
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_NONE
)
expect
(
subject
.
size
).
to
eq
(
24
)
end
described_class
.
find_all
(
repository
)
it
'includes the expected commits'
do
end
expect
(
subject
).
to
include
(
SeedRepo
::
Commit
::
ID
,
SeedRepo
::
FirstCommit
::
ID
)
expect
(
subject
).
not_to
include
(
SeedRepo
::
LastCommit
::
ID
)
end
end
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