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
Jérome Perrin
gitlab-ce
Commits
c24e39ab
Commit
c24e39ab
authored
Jun 14, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Counting commits is done by Gitaly
Closes
https://gitlab.com/gitlab-org/gitaly/issues/382
parent
0716e192
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
80 deletions
+18
-80
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+4
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+13
-70
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+1
-9
No files found.
app/controllers/projects/branches_controller.rb
View file @
c24e39ab
...
@@ -31,7 +31,10 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -31,7 +31,10 @@ class Projects::BranchesController < Projects::ApplicationController
end
end
end
end
render
# https://gitlab.com/gitlab-org/gitlab-ce/issues/48097
Gitlab
::
GitalyClient
.
allow_n_plus_1_calls
do
render
end
end
end
format
.
json
do
format
.
json
do
branches
=
BranchesFinder
.
new
(
@repository
,
params
).
execute
branches
=
BranchesFinder
.
new
(
@repository
,
params
).
execute
...
...
lib/gitlab/git/repository.rb
View file @
c24e39ab
...
@@ -472,13 +472,21 @@ module Gitlab
...
@@ -472,13 +472,21 @@ module Gitlab
end
end
def
count_commits
(
options
)
def
count_commits
(
options
)
count_commits_options
=
process_count_commits_options
(
options
)
options
=
process_count_commits_options
(
options
.
dup
)
gitaly_migrate
(
:count_commits
,
status:
Gitlab
::
GitalyClient
::
MigrationStatus
::
OPT_OUT
)
do
|
is_enabled
|
wrapped_gitaly_errors
do
if
is_enabled
if
options
[
:left_right
]
count_commits_by_gitaly
(
count_commits_options
)
from
=
options
[
:from
]
to
=
options
[
:to
]
right_count
=
gitaly_commit_client
.
commit_count
(
"
#{
from
}
..
#{
to
}
"
,
options
)
left_count
=
gitaly_commit_client
.
commit_count
(
"
#{
to
}
..
#{
from
}
"
,
options
)
[
left_count
,
right_count
]
else
else
count_commits_by_shelling_out
(
count_commits_
options
)
gitaly_commit_client
.
commit_count
(
options
[
:ref
],
options
)
end
end
end
end
end
end
...
@@ -1902,71 +1910,6 @@ module Gitlab
...
@@ -1902,71 +1910,6 @@ module Gitlab
gitaly_repository_client
.
repository_size
gitaly_repository_client
.
repository_size
end
end
def
count_commits_by_gitaly
(
options
)
if
options
[
:left_right
]
from
=
options
[
:from
]
to
=
options
[
:to
]
right_count
=
gitaly_commit_client
.
commit_count
(
"
#{
from
}
..
#{
to
}
"
,
options
)
left_count
=
gitaly_commit_client
.
commit_count
(
"
#{
to
}
..
#{
from
}
"
,
options
)
[
left_count
,
right_count
]
else
gitaly_commit_client
.
commit_count
(
options
[
:ref
],
options
)
end
end
def
count_commits_by_shelling_out
(
options
)
cmd
=
count_commits_shelling_command
(
options
)
raw_output
,
_status
=
run_git
(
cmd
)
process_count_commits_raw_output
(
raw_output
,
options
)
end
def
count_commits_shelling_command
(
options
)
cmd
=
%w[rev-list]
cmd
<<
"--after=
#{
options
[
:after
].
iso8601
}
"
if
options
[
:after
]
cmd
<<
"--before=
#{
options
[
:before
].
iso8601
}
"
if
options
[
:before
]
cmd
<<
"--max-count=
#{
options
[
:max_count
]
}
"
if
options
[
:max_count
]
cmd
<<
"--left-right"
if
options
[
:left_right
]
cmd
<<
'--count'
cmd
<<
if
options
[
:all
]
'--all'
elsif
options
[
:ref
]
options
[
:ref
]
else
raise
ArgumentError
,
"Please specify a valid ref or set the 'all' attribute to true"
end
cmd
+=
%W[--
#{
options
[
:path
]
}
]
if
options
[
:path
].
present?
cmd
end
def
process_count_commits_raw_output
(
raw_output
,
options
)
if
options
[
:left_right
]
result
=
raw_output
.
scan
(
/\d+/
).
map
(
&
:to_i
)
if
result
.
sum
!=
options
[
:max_count
]
result
else
# Reaching max count, right is not accurate
right_option
=
process_count_commits_options
(
options
.
except
(
:left_right
,
:from
,
:to
)
.
merge
(
ref:
options
[
:to
]))
right
=
count_commits_by_shelling_out
(
right_option
)
[
result
.
first
,
right
]
# left should be accurate in the first call
end
else
raw_output
.
to_i
end
end
def
gitaly_ls_files
(
ref
)
def
gitaly_ls_files
(
ref
)
gitaly_commit_client
.
ls_files
(
ref
)
gitaly_commit_client
.
ls_files
(
ref
)
end
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
c24e39ab
...
@@ -1114,7 +1114,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1114,7 +1114,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#count_commits'
do
describe
'#count_commits'
do
shared_examples
'extended commit counting'
do
describe
'extended commit counting'
do
context
'with after timestamp'
do
context
'with after timestamp'
do
it
'returns the number of commits after timestamp'
do
it
'returns the number of commits after timestamp'
do
options
=
{
ref:
'master'
,
after:
Time
.
iso8601
(
'2013-03-03T20:15:01+00:00'
)
}
options
=
{
ref:
'master'
,
after:
Time
.
iso8601
(
'2013-03-03T20:15:01+00:00'
)
}
...
@@ -1199,14 +1199,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1199,14 +1199,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
end
end
context
'when Gitaly count_commits feature is enabled'
do
it_behaves_like
'extended commit counting'
end
context
'when Gitaly count_commits feature is disabled'
,
:disable_gitaly
do
it_behaves_like
'extended commit counting'
end
end
end
describe
'#autocrlf'
do
describe
'#autocrlf'
do
...
...
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