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
4d52131d
Commit
4d52131d
authored
Apr 11, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a feature flag for subdirectory archives
parent
670b2c1a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
41 deletions
+94
-41
app/views/projects/buttons/_download.html.haml
app/views/projects/buttons/_download.html.haml
+1
-1
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+35
-15
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+58
-25
No files found.
app/views/projects/buttons/_download.html.haml
View file @
4d52131d
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
%li
.dropdown-bold-header
=
_
(
'Download source code'
)
%li
.dropdown-bold-header
=
_
(
'Download source code'
)
%li
.dropdown-menu-content
%li
.dropdown-menu-content
=
render
'projects/buttons/download_links'
,
project:
project
,
ref:
ref
,
archive_prefix:
archive_prefix
,
path:
nil
=
render
'projects/buttons/download_links'
,
project:
project
,
ref:
ref
,
archive_prefix:
archive_prefix
,
path:
nil
-
if
directory?
-
if
directory?
&&
Feature
.
enabled?
(
:git_archive_path
,
default_enabled:
true
)
%li
.separator
%li
.separator
%li
.dropdown-bold-header
=
_
(
'Download this directory'
)
%li
.dropdown-bold-header
=
_
(
'Download this directory'
)
%li
.dropdown-menu-content
%li
.dropdown-menu-content
...
...
lib/gitlab/workhorse.rb
View file @
4d52131d
...
@@ -64,28 +64,33 @@ module Gitlab
...
@@ -64,28 +64,33 @@ module Gitlab
end
end
def
send_git_archive
(
repository
,
ref
:,
format
:,
append_sha
:,
path:
nil
)
def
send_git_archive
(
repository
,
ref
:,
format
:,
append_sha
:,
path:
nil
)
path_enabled
=
Feature
.
enabled?
(
:git_archive_path
,
default_enabled:
true
)
path
=
nil
unless
path_enabled
format
||=
'tar.gz'
format
||=
'tar.gz'
format
=
format
.
downcase
format
=
format
.
downcase
metadata
=
repository
.
archive_metadata
(
ref
,
Gitlab
.
config
.
gitlab
.
repository_downloads_path
,
format
,
append_sha:
append_sha
,
path:
path
)
metadata
=
repository
.
archive_metadata
(
ref
,
Gitlab
.
config
.
gitlab
.
repository_downloads_path
,
format
,
append_sha:
append_sha
,
path:
path
)
raise
"Repository or ref not found"
if
metadata
.
empty?
raise
"Repository or ref not found"
if
metadata
.
empty?
params
=
{
params
=
'GitalyServer'
=>
gitaly_server_hash
(
repository
),
if
path_enabled
'ArchivePath'
=>
metadata
[
'ArchivePath'
],
send_git_archive_params
(
repository
,
metadata
,
path
,
archive_format
(
format
))
'GetArchiveRequest'
=>
encode_binary
(
else
Gitaly
::
GetArchiveRequest
.
new
(
metadata
repository:
repository
.
gitaly_repository
,
end
commit_id:
metadata
[
'CommitId'
],
prefix:
metadata
[
'ArchivePrefix'
],
format:
archive_format
(
format
),
path:
path
.
presence
||
""
).
to_proto
)
}
# If present DisableCache must be a Boolean. Otherwise workhorse ignores it.
# If present, DisableCache must be a Boolean. Otherwise
# workhorse ignores it.
params
[
'DisableCache'
]
=
true
if
git_archive_cache_disabled?
params
[
'DisableCache'
]
=
true
if
git_archive_cache_disabled?
params
[
'GitalyServer'
]
=
gitaly_server_hash
(
repository
)
[
[
SEND_DATA_HEADER
,
SEND_DATA_HEADER
,
...
@@ -273,6 +278,21 @@ module Gitlab
...
@@ -273,6 +278,21 @@ module Gitlab
Gitaly
::
GetArchiveRequest
::
Format
::
TAR_GZ
Gitaly
::
GetArchiveRequest
::
Format
::
TAR_GZ
end
end
end
end
def
send_git_archive_params
(
repository
,
metadata
,
path
,
format
)
{
'ArchivePath'
=>
metadata
[
'ArchivePath'
],
'GetArchiveRequest'
=>
encode_binary
(
Gitaly
::
GetArchiveRequest
.
new
(
repository:
repository
.
gitaly_repository
,
commit_id:
metadata
[
'CommitId'
],
prefix:
metadata
[
'ArchivePrefix'
],
format:
format
,
path:
path
.
presence
||
""
).
to_proto
)
}
end
end
end
end
end
end
end
spec/lib/gitlab/workhorse_spec.rb
View file @
4d52131d
...
@@ -16,7 +16,7 @@ describe Gitlab::Workhorse do
...
@@ -16,7 +16,7 @@ describe Gitlab::Workhorse do
let
(
:ref
)
{
'master'
}
let
(
:ref
)
{
'master'
}
let
(
:format
)
{
'zip'
}
let
(
:format
)
{
'zip'
}
let
(
:storage_path
)
{
Gitlab
.
config
.
gitlab
.
repository_downloads_path
}
let
(
:storage_path
)
{
Gitlab
.
config
.
gitlab
.
repository_downloads_path
}
let
(
:path
)
{
'some/path'
}
let
(
:path
)
{
'some/path'
if
Feature
.
enabled?
(
:git_archive_path
,
default_enabled:
true
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
ref
,
storage_path
,
format
,
append_sha:
nil
,
path:
path
)
}
let
(
:metadata
)
{
repository
.
archive_metadata
(
ref
,
storage_path
,
format
,
append_sha:
nil
,
path:
path
)
}
let
(
:cache_disabled
)
{
false
}
let
(
:cache_disabled
)
{
false
}
...
@@ -28,6 +28,38 @@ describe Gitlab::Workhorse do
...
@@ -28,6 +28,38 @@ describe Gitlab::Workhorse do
allow
(
described_class
).
to
receive
(
:git_archive_cache_disabled?
).
and_return
(
cache_disabled
)
allow
(
described_class
).
to
receive
(
:git_archive_cache_disabled?
).
and_return
(
cache_disabled
)
end
end
context
'feature flag disabled'
do
before
do
stub_feature_flags
(
git_archive_path:
false
)
end
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
expected_params
=
metadata
.
merge
(
'GitalyRepository'
=>
repository
.
gitaly_repository
.
to_h
,
'GitalyServer'
=>
{
address:
Gitlab
::
GitalyClient
.
address
(
project
.
repository_storage
),
token:
Gitlab
::
GitalyClient
.
token
(
project
.
repository_storage
)
}
)
expect
(
key
).
to
eq
(
'Gitlab-Workhorse-Send-Data'
)
expect
(
command
).
to
eq
(
'git-archive'
)
expect
(
params
).
to
eq
(
expected_params
.
deep_stringify_keys
)
end
context
'when archive caching is disabled'
do
let
(
:cache_disabled
)
{
true
}
it
'tells workhorse not to use the cache'
do
_
,
_
,
params
=
decode_workhorse_header
(
subject
)
expect
(
params
).
to
include
({
'DisableCache'
=>
true
})
end
end
end
context
'feature flag enabled'
do
it
'sets the header correctly'
do
it
'sets the header correctly'
do
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
key
,
command
,
params
=
decode_workhorse_header
(
subject
)
...
@@ -59,6 +91,7 @@ describe Gitlab::Workhorse do
...
@@ -59,6 +91,7 @@ describe Gitlab::Workhorse do
expect
(
params
).
to
include
({
'DisableCache'
=>
true
})
expect
(
params
).
to
include
({
'DisableCache'
=>
true
})
end
end
end
end
end
context
"when the repository doesn't have an archive file path"
do
context
"when the repository doesn't have an archive file path"
do
before
do
before
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