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
780dcf9c
Commit
780dcf9c
authored
May 02, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitaly-branch-tag-count' into 'master'
Use Gitaly for getting Branch/Tag counts Closes gitaly#157 See merge request !10780
parents
554c4e0d
573d0989
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
22 deletions
+41
-22
repository.rb
app/models/repository.rb
+1
-7
repository.rb
lib/gitlab/git/repository.rb
+17
-0
ref.rb
lib/gitlab/gitaly_client/ref.rb
+8
-0
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+1
-13
repository_spec.rb
spec/models/repository_spec.rb
+10
-0
backup_rake_spec.rb
spec/tasks/gitlab/backup_rake_spec.rb
+4
-2
No files found.
app/models/repository.rb
View file @
780dcf9c
...
...
@@ -505,14 +505,8 @@ class Repository
delegate
:tag_names
,
to: :raw_repository
cache_method
:tag_names
,
fallback:
[]
def
branch_count
branches
.
size
end
delegate
:branch_count
,
:tag_count
,
to: :raw_repository
cache_method
:branch_count
,
fallback:
0
def
tag_count
raw_repository
.
rugged
.
tags
.
count
end
cache_method
:tag_count
,
fallback:
0
def
avatar
...
...
lib/gitlab/git/repository.rb
View file @
780dcf9c
...
...
@@ -122,6 +122,10 @@ module Gitlab
# Returns the number of valid branches
def
branch_count
Gitlab
::
GitalyClient
.
migrate
(
:branch_names
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_client
.
count_branch_names
else
rugged
.
branches
.
count
do
|
ref
|
begin
ref
.
name
&&
ref
.
target
# ensures the branch is valid
...
...
@@ -132,6 +136,19 @@ module Gitlab
end
end
end
end
end
# Returns the number of valid tags
def
tag_count
Gitlab
::
GitalyClient
.
migrate
(
:tag_names
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_client
.
count_tag_names
else
rugged
.
tags
.
count
end
end
end
# Returns an Array of tag names
def
tag_names
...
...
lib/gitlab/gitaly_client/ref.rb
View file @
780dcf9c
...
...
@@ -34,6 +34,14 @@ module Gitlab
stub
.
find_ref_name
(
request
).
name
end
def
count_tag_names
tag_names
.
count
end
def
count_branch_names
branch_names
.
count
end
private
def
consume_refs_response
(
response
,
prefix
:)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
780dcf9c
...
...
@@ -1074,20 +1074,8 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe
'#branch_count'
do
before
(
:each
)
do
valid_ref
=
double
(
:ref
)
invalid_ref
=
double
(
:ref
)
allow
(
valid_ref
).
to
receive_messages
(
name:
'master'
,
target:
double
(
:target
))
allow
(
invalid_ref
).
to
receive_messages
(
name:
'bad-branch'
)
allow
(
invalid_ref
).
to
receive
(
:target
)
{
raise
Rugged
::
ReferenceError
}
allow
(
repository
.
rugged
).
to
receive_messages
(
branches:
[
valid_ref
,
invalid_ref
])
end
it
'returns the number of branches'
do
expect
(
repository
.
branch_count
).
to
eq
(
1
)
expect
(
repository
.
branch_count
).
to
eq
(
9
)
end
end
...
...
spec/models/repository_spec.rb
View file @
780dcf9c
...
...
@@ -1379,12 +1379,22 @@ describe Repository, models: true do
describe
'#branch_count'
do
it
'returns the number of branches'
do
expect
(
repository
.
branch_count
).
to
be_an
(
Integer
)
# NOTE: Until rugged goes away, make sure rugged and gitaly are in sync
rugged_count
=
repository
.
raw_repository
.
rugged
.
branches
.
count
expect
(
repository
.
branch_count
).
to
eq
(
rugged_count
)
end
end
describe
'#tag_count'
do
it
'returns the number of tags'
do
expect
(
repository
.
tag_count
).
to
be_an
(
Integer
)
# NOTE: Until rugged goes away, make sure rugged and gitaly are in sync
rugged_count
=
repository
.
raw_repository
.
rugged
.
tags
.
count
expect
(
repository
.
tag_count
).
to
eq
(
rugged_count
)
end
end
...
...
spec/tasks/gitlab/backup_rake_spec.rb
View file @
780dcf9c
...
...
@@ -230,11 +230,13 @@ describe 'gitlab:app namespace rake task' do
before
do
FileUtils
.
mkdir
(
'tmp/tests/default_storage'
)
FileUtils
.
mkdir
(
'tmp/tests/custom_storage'
)
gitaly_address
=
Gitlab
.
config
.
repositories
.
storages
.
default
.
gitaly_address
storages
=
{
'default'
=>
{
'path'
=>
Settings
.
absolute
(
'tmp/tests/default_storage'
)
},
'custom'
=>
{
'path'
=>
Settings
.
absolute
(
'tmp/tests/custom_storage'
)
}
'default'
=>
{
'path'
=>
Settings
.
absolute
(
'tmp/tests/default_storage'
)
,
'gitaly_address'
=>
gitaly_address
},
'custom'
=>
{
'path'
=>
Settings
.
absolute
(
'tmp/tests/custom_storage'
)
,
'gitaly_address'
=>
gitaly_address
}
}
allow
(
Gitlab
.
config
.
repositories
).
to
receive
(
:storages
).
and_return
(
storages
)
Gitlab
::
GitalyClient
.
configure_channels
# Create the projects now, after mocking the settings but before doing the backup
project_a
...
...
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