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
65dbead7
Commit
65dbead7
authored
Jun 05, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix repository archive generation when hashed storage is enabled
parent
53811074
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
15 deletions
+49
-15
app/models/repository.rb
app/models/repository.rb
+10
-0
changelogs/unreleased/45702-fix-hashed-storage-repository-archive.yml
...nreleased/45702-fix-hashed-storage-repository-archive.yml
+5
-0
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+4
-8
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+26
-0
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+3
-6
No files found.
app/models/repository.rb
View file @
65dbead7
...
@@ -270,6 +270,16 @@ class Repository
...
@@ -270,6 +270,16 @@ class Repository
end
end
end
end
def
archive_metadata
(
ref
,
storage_path
,
format
=
"tar.gz"
,
append_sha
:)
raw_repository
.
archive_metadata
(
ref
,
storage_path
,
project
.
path
,
format
,
append_sha:
append_sha
)
end
def
expire_tags_cache
def
expire_tags_cache
expire_method_caches
(
%i(tag_names tag_count)
)
expire_method_caches
(
%i(tag_names tag_count)
)
@tags
=
nil
@tags
=
nil
...
...
changelogs/unreleased/45702-fix-hashed-storage-repository-archive.yml
0 → 100644
View file @
65dbead7
---
title
:
Fix repository archive generation when hashed storage is enabled
merge_request
:
19441
author
:
type
:
fixed
lib/gitlab/git/repository.rb
View file @
65dbead7
...
@@ -395,12 +395,12 @@ module Gitlab
...
@@ -395,12 +395,12 @@ module Gitlab
nil
nil
end
end
def
archive_metadata
(
ref
,
storage_path
,
format
=
"tar.gz"
,
append_sha
:)
def
archive_metadata
(
ref
,
storage_path
,
project_path
,
format
=
"tar.gz"
,
append_sha
:)
ref
||=
root_ref
ref
||=
root_ref
commit
=
Gitlab
::
Git
::
Commit
.
find
(
self
,
ref
)
commit
=
Gitlab
::
Git
::
Commit
.
find
(
self
,
ref
)
return
{}
if
commit
.
nil?
return
{}
if
commit
.
nil?
prefix
=
archive_prefix
(
ref
,
commit
.
id
,
append_sha:
append_sha
)
prefix
=
archive_prefix
(
ref
,
commit
.
id
,
project_path
,
append_sha:
append_sha
)
{
{
'ArchivePrefix'
=>
prefix
,
'ArchivePrefix'
=>
prefix
,
...
@@ -412,16 +412,12 @@ module Gitlab
...
@@ -412,16 +412,12 @@ module Gitlab
# This is both the filename of the archive (missing the extension) and the
# This is both the filename of the archive (missing the extension) and the
# name of the top-level member of the archive under which all files go
# name of the top-level member of the archive under which all files go
#
def
archive_prefix
(
ref
,
sha
,
project_path
,
append_sha
:)
# FIXME: The generated prefix is incorrect for projects with hashed
# storage enabled
def
archive_prefix
(
ref
,
sha
,
append_sha
:)
append_sha
=
(
ref
!=
sha
)
if
append_sha
.
nil?
append_sha
=
(
ref
!=
sha
)
if
append_sha
.
nil?
project_name
=
self
.
name
.
chomp
(
'.git'
)
formatted_ref
=
ref
.
tr
(
'/'
,
'-'
)
formatted_ref
=
ref
.
tr
(
'/'
,
'-'
)
prefix_segments
=
[
project_
name
,
formatted_ref
]
prefix_segments
=
[
project_
path
,
formatted_ref
]
prefix_segments
<<
sha
if
append_sha
prefix_segments
<<
sha
if
append_sha
prefix_segments
.
join
(
'-'
)
prefix_segments
.
join
(
'-'
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
65dbead7
...
@@ -256,7 +256,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -256,7 +256,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
let
(
:expected_path
)
{
File
.
join
(
storage_path
,
cache_key
,
expected_filename
)
}
let
(
:expected_path
)
{
File
.
join
(
storage_path
,
cache_key
,
expected_filename
)
}
let
(
:expected_prefix
)
{
"gitlab-git-test-
#{
ref
}
-
#{
SeedRepo
::
LastCommit
::
ID
}
"
}
let
(
:expected_prefix
)
{
"gitlab-git-test-
#{
ref
}
-
#{
SeedRepo
::
LastCommit
::
ID
}
"
}
subject
(
:metadata
)
{
repository
.
archive_metadata
(
ref
,
storage_path
,
format
,
append_sha:
append_sha
)
}
subject
(
:metadata
)
{
repository
.
archive_metadata
(
ref
,
storage_path
,
'gitlab-git-test'
,
format
,
append_sha:
append_sha
)
}
it
'sets CommitId to the commit SHA'
do
it
'sets CommitId to the commit SHA'
do
expect
(
metadata
[
'CommitId'
]).
to
eq
(
SeedRepo
::
LastCommit
::
ID
)
expect
(
metadata
[
'CommitId'
]).
to
eq
(
SeedRepo
::
LastCommit
::
ID
)
...
...
spec/models/repository_spec.rb
View file @
65dbead7
...
@@ -2443,6 +2443,32 @@ describe Repository do
...
@@ -2443,6 +2443,32 @@ describe Repository do
end
end
end
end
describe
'#archive_metadata'
do
let
(
:ref
)
{
'master'
}
let
(
:storage_path
)
{
'/tmp'
}
let
(
:prefix
)
{
[
project
.
path
,
ref
].
join
(
'-'
)
}
let
(
:filename
)
{
prefix
+
'.tar.gz'
}
subject
(
:result
)
{
repository
.
archive_metadata
(
ref
,
storage_path
,
append_sha:
false
)
}
context
'with hashed storage disabled'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:legacy_storage
)
}
it
'uses the project path to generate the filename'
do
expect
(
result
[
'ArchivePrefix'
]).
to
eq
(
prefix
)
expect
(
File
.
basename
(
result
[
'ArchivePath'
])).
to
eq
(
filename
)
end
end
context
'with hashed storage enabled'
do
it
'uses the project path to generate the filename'
do
expect
(
result
[
'ArchivePrefix'
]).
to
eq
(
prefix
)
expect
(
File
.
basename
(
result
[
'ArchivePath'
])).
to
eq
(
filename
)
end
end
end
describe
'commit cache'
do
describe
'commit cache'
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
spec/requests/api/repositories_spec.rb
View file @
65dbead7
...
@@ -220,11 +220,10 @@ describe API::Repositories do
...
@@ -220,11 +220,10 @@ describe API::Repositories do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
type
,
params
=
workhorse_send_data
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.tar.gz/
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
project
.
path
}
\-[^\.]+\.tar.gz/
)
end
end
it
'returns the repository archive archive.zip'
do
it
'returns the repository archive archive.zip'
do
...
@@ -232,11 +231,10 @@ describe API::Repositories do
...
@@ -232,11 +231,10 @@ describe API::Repositories do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
type
,
params
=
workhorse_send_data
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.zip/
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
project
.
path
}
\-[^\.]+\.zip/
)
end
end
it
'returns the repository archive archive.tar.bz2'
do
it
'returns the repository archive archive.tar.bz2'
do
...
@@ -244,11 +242,10 @@ describe API::Repositories do
...
@@ -244,11 +242,10 @@ describe API::Repositories do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
type
,
params
=
workhorse_send_data
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.tar.bz2/
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
project
.
path
}
\-[^\.]+\.tar.bz2/
)
end
end
context
'when sha does not exist'
do
context
'when sha does not exist'
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