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
Boxiang Sun
gitlab-ce
Commits
13992ac9
Commit
13992ac9
authored
Apr 05, 2018
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checksum calculation is handled by Gitaly when feature is enabled
parent
e892eeb5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
24 deletions
+50
-24
lib/gitlab/git/checksum.rb
lib/gitlab/git/checksum.rb
+19
-4
spec/lib/gitlab/git/checksum_spec.rb
spec/lib/gitlab/git/checksum_spec.rb
+31
-20
No files found.
lib/gitlab/git/checksum.rb
View file @
13992ac9
...
...
@@ -7,13 +7,14 @@ module Gitlab
Failure
=
Class
.
new
(
StandardError
)
attr_reader
:path
,
:relative_path
,
:storage
,
:storage_path
attr_reader
:path
,
:relative_path
,
:storage
,
:storage_path
,
:gl_repository
def
initialize
(
storage
,
relative_path
)
def
initialize
(
storage
,
relative_path
,
gl_repository
)
@storage
=
storage
@storage_path
=
Gitlab
.
config
.
repositories
.
storages
[
storage
].
legacy_disk_path
@relative_path
=
"
#{
relative_path
}
.git"
@path
=
File
.
join
(
storage_path
,
@relative_path
)
@gl_repository
=
gl_repository
end
def
calculate
...
...
@@ -21,7 +22,13 @@ module Gitlab
failure!
(
Gitlab
::
Git
::
Repository
::
NoRepository
,
'No repository for such path'
)
end
calculate_checksum_by_shelling_out
raw_repository
.
gitaly_migrate
(
:calculate_checksum
)
do
|
is_enabled
|
if
is_enabled
calculate_checksum_gitaly
else
calculate_checksum_by_shelling_out
end
end
end
private
...
...
@@ -30,6 +37,10 @@ module Gitlab
raw_repository
.
exists?
end
def
calculate_checksum_gitaly
gitaly_repository_client
.
calculate_checksum
end
def
calculate_checksum_by_shelling_out
args
=
%W(--git-dir=
#{
path
}
show-ref --heads --tags)
output
,
status
=
run_git
(
args
)
...
...
@@ -69,7 +80,11 @@ module Gitlab
end
def
raw_repository
Gitlab
::
Git
::
Repository
.
new
(
storage
,
relative_path
,
nil
)
@raw_repository
||=
Gitlab
::
Git
::
Repository
.
new
(
storage
,
relative_path
,
gl_repository
)
end
def
gitaly_repository_client
raw_repository
.
gitaly_repository_client
end
def
run_git
(
args
)
...
...
spec/lib/gitlab/git/checksum_spec.rb
View file @
13992ac9
...
...
@@ -2,37 +2,48 @@ require 'spec_helper'
describe
Gitlab
::
Git
::
Checksum
,
seed_helper:
true
do
let
(
:storage
)
{
'default'
}
let
(
:gl_repository
)
{
'project-123'
}
it
'raises Gitlab::Git::Repository::NoRepository when there is no repo'
do
checksum
=
described_class
.
new
(
storage
,
'nonexistent-repo'
)
shared_examples
'calculating checksum'
do
it
'raises Gitlab::Git::Repository::NoRepository when there is no repo'
do
checksum
=
described_class
.
new
(
storage
,
'nonexistent-repo'
,
gl_repository
)
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Repository
::
NoRepository
end
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Repository
::
NoRepository
end
it
'pretends that checksum is 000000... when the repo is empty'
do
FileUtils
.
rm_rf
(
File
.
join
(
SEED_STORAGE_PATH
,
'empty-repo.git'
))
it
'pretends that checksum is 000000... when the repo is empty'
do
FileUtils
.
rm_rf
(
File
.
join
(
SEED_STORAGE_PATH
,
'empty-repo.git'
))
system
(
git_env
,
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
init --bare empty-repo.git)
,
chdir:
SEED_STORAGE_PATH
,
out:
'/dev/null'
,
err:
'/dev/null'
)
system
(
git_env
,
*
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
init --bare empty-repo.git)
,
chdir:
SEED_STORAGE_PATH
,
out:
'/dev/null'
,
err:
'/dev/null'
)
checksum
=
described_class
.
new
(
storage
,
'empty-repo'
)
checksum
=
described_class
.
new
(
storage
,
'empty-repo'
,
gl_repository
)
expect
(
checksum
.
calculate
).
to
eq
'0000000000000000000000000000000000000000'
end
expect
(
checksum
.
calculate
).
to
eq
'0000000000000000000000000000000000000000'
end
it
'raises Gitlab::Git::Repository::Failure when shelling out to git return non-zero status
'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
)
it
'calculates the checksum when there is a repo
'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
,
gl_repository
)
allow
(
checksum
).
to
receive
(
:popen
).
and_return
([
'output'
,
nil
])
expect
(
checksum
.
calculate
).
to
eq
'54f21be4c32c02f6788d72207fa03ad3bce725e4'
end
end
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Checksum
::
Failure
context
'when calculate_checksum Gitaly feature is enabled'
do
it_behaves_like
'calculating checksum'
end
it
'calculates the checksum when there is a repo'
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
)
context
'when calculate_checksum Gitaly feature is disabled'
,
:disable_gitaly
do
it_behaves_like
'calculating checksum'
it
"raises a Gitlab::Git::Repository::Failure error if the `popen` call to git returns a non-zero exit code"
do
checksum
=
described_class
.
new
(
storage
,
'gitlab-git-test'
,
gl_repository
)
allow
(
checksum
).
to
receive
(
:popen
).
and_return
([
'output'
,
nil
])
expect
(
checksum
.
calculate
).
to
eq
'54f21be4c32c02f6788d72207fa03ad3bce725e4'
expect
{
checksum
.
calculate
}.
to
raise_error
Gitlab
::
Git
::
Checksum
::
Failure
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