BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
25c34608
Commit
25c34608
authored
Sep 06, 2017
by
Kim "BKC" Carlbäcker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Git::CommitStats to Gitaly
parent
de14e9c2
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
3 deletions
+61
-3
commit.rb
lib/gitlab/git/commit.rb
+1
-1
commit_stats.rb
lib/gitlab/git/commit_stats.rb
+18
-1
commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+8
-0
commit_spec.rb
spec/lib/gitlab/git/commit_spec.rb
+9
-1
commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+25
-0
No files found.
lib/gitlab/git/commit.rb
View file @
25c34608
...
...
@@ -352,7 +352,7 @@ module Gitlab
end
def
stats
Gitlab
::
Git
::
CommitStats
.
new
(
self
)
Gitlab
::
Git
::
CommitStats
.
new
(
@repository
,
self
)
end
def
to_patch
(
options
=
{})
...
...
lib/gitlab/git/commit_stats.rb
View file @
25c34608
...
...
@@ -10,12 +10,29 @@ module Gitlab
# Instantiate a CommitStats object
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
def
initialize
(
commit
)
def
initialize
(
repo
,
commit
)
@id
=
commit
.
id
@additions
=
0
@deletions
=
0
@total
=
0
repo
.
gitaly_migrate
(
:commit_stats
)
do
|
is_enabled
|
if
is_enabled
gitaly_stats
(
repo
,
commit
)
else
rugged_stats
(
commit
)
end
end
end
def
gitaly_stats
(
repo
,
commit
)
stats
=
repo
.
gitaly_commit_client
.
commit_stats
(
@id
)
@additions
=
stats
.
additions
@deletions
=
stats
.
deletions
@total
=
@additions
+
@deletions
end
def
rugged_stats
(
commit
)
diff
=
commit
.
rugged_diff_from_parent
diff
.
each_patch
do
|
p
|
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
25c34608
...
...
@@ -204,6 +204,14 @@ module Gitlab
response
.
sum
(
&
:data
)
end
def
commit_stats
(
revision
)
request
=
Gitaly
::
CommitStatsRequest
.
new
(
repository:
@gitaly_repo
,
revision:
GitalyClient
.
encode
(
revision
)
)
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:commit_stats
,
request
)
end
private
def
commit_diff_request_params
(
commit
,
options
=
{})
...
...
spec/lib/gitlab/git/commit_spec.rb
View file @
25c34608
...
...
@@ -401,7 +401,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
end
describe
'#stats'
do
shared_examples
'#stats'
do
subject
{
commit
.
stats
}
describe
'#additions'
do
...
...
@@ -415,6 +415,14 @@ describe Gitlab::Git::Commit, seed_helper: true do
end
end
describe
'#stats with gitaly on'
do
it_should_behave_like
'#stats'
end
describe
'#stats with gitaly disabled'
,
skip_gitaly_mock:
true
do
it_should_behave_like
'#stats'
end
describe
'#to_diff'
do
subject
{
commit
.
to_diff
}
...
...
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
25c34608
...
...
@@ -165,4 +165,29 @@ describe Gitlab::GitalyClient::CommitService do
expect
(
subject
).
to
eq
(
"my diff"
)
end
end
describe
'#commit_stats'
do
let
(
:request
)
do
Gitaly
::
CommitStatsRequest
.
new
(
repository:
repository_message
,
revision:
revision
)
end
let
(
:response
)
do
Gitaly
::
CommitStatsResponse
.
new
(
oid:
revision
,
additions:
11
,
deletions:
15
)
end
subject
{
described_class
.
new
(
repository
).
commit_stats
(
revision
)
}
it
'sends an RPC request'
do
expect_any_instance_of
(
Gitaly
::
CommitService
::
Stub
).
to
receive
(
:commit_stats
)
.
with
(
request
,
kind_of
(
Hash
)).
and_return
(
response
)
expect
(
subject
.
additions
).
to
eq
(
11
)
expect
(
subject
.
deletions
).
to
eq
(
15
)
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