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
6ed01ebf
Commit
6ed01ebf
authored
Aug 18, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitaly-apply-gitattributes' into 'master'
Gitaly apply gitattributes Closes gitaly#464 See merge request !13517
parents
45c8c17e
c463a834
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
26 deletions
+123
-26
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
repository.rb
lib/gitlab/git/repository.rb
+41
-25
repository_service.rb
lib/gitlab/gitaly_client/repository_service.rb
+5
-0
repository_service_spec.rb
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+76
-0
No files found.
GITALY_SERVER_VERSION
View file @
6ed01ebf
0.3
0
.0
0.3
1
.0
lib/gitlab/git/repository.rb
View file @
6ed01ebf
...
...
@@ -653,33 +653,15 @@ module Gitlab
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/328
def
copy_gitattributes
(
ref
)
begin
commit
=
lookup
(
ref
)
rescue
Rugged
::
ReferenceError
raise
InvalidRef
.
new
(
"Ref
#{
ref
}
is invalid"
)
end
# Create the paths
info_dir_path
=
File
.
join
(
path
,
'info'
)
info_attributes_path
=
File
.
join
(
info_dir_path
,
'attributes'
)
begin
# Retrieve the contents of the blob
gitattributes_content
=
blob_content
(
commit
,
'.gitattributes'
)
rescue
InvalidBlobName
# No .gitattributes found. Should now remove any info/attributes and return
File
.
delete
(
info_attributes_path
)
if
File
.
exist?
(
info_attributes_path
)
return
Gitlab
::
GitalyClient
.
migrate
(
:apply_gitattributes
)
do
|
is_enabled
|
if
is_enabled
gitaly_copy_gitattributes
(
ref
)
else
rugged_copy_gitattributes
(
ref
)
end
# Create the info directory if needed
Dir
.
mkdir
(
info_dir_path
)
unless
File
.
directory?
(
info_dir_path
)
# Write the contents of the .gitattributes file to info/attributes
# Use binary mode to prevent Rails from converting ASCII-8BIT to UTF-8
File
.
open
(
info_attributes_path
,
"wb"
)
do
|
file
|
file
.
write
(
gitattributes_content
)
end
rescue
GRPC
::
InvalidArgument
raise
InvalidRef
end
# Returns the Git attributes for the given file path.
...
...
@@ -1012,6 +994,40 @@ module Gitlab
raw_output
.
compact
end
def
gitaly_copy_gitattributes
(
revision
)
gitaly_repository_client
.
apply_gitattributes
(
revision
)
end
def
rugged_copy_gitattributes
(
ref
)
begin
commit
=
lookup
(
ref
)
rescue
Rugged
::
ReferenceError
raise
InvalidRef
.
new
(
"Ref
#{
ref
}
is invalid"
)
end
# Create the paths
info_dir_path
=
File
.
join
(
path
,
'info'
)
info_attributes_path
=
File
.
join
(
info_dir_path
,
'attributes'
)
begin
# Retrieve the contents of the blob
gitattributes_content
=
blob_content
(
commit
,
'.gitattributes'
)
rescue
InvalidBlobName
# No .gitattributes found. Should now remove any info/attributes and return
File
.
delete
(
info_attributes_path
)
if
File
.
exist?
(
info_attributes_path
)
return
end
# Create the info directory if needed
Dir
.
mkdir
(
info_dir_path
)
unless
File
.
directory?
(
info_dir_path
)
# Write the contents of the .gitattributes file to info/attributes
# Use binary mode to prevent Rails from converting ASCII-8BIT to UTF-8
File
.
open
(
info_attributes_path
,
"wb"
)
do
|
file
|
file
.
write
(
gitattributes_content
)
end
end
end
end
end
lib/gitlab/gitaly_client/repository_service.rb
View file @
6ed01ebf
...
...
@@ -32,6 +32,11 @@ module Gitlab
request
=
Gitaly
::
RepositorySizeRequest
.
new
(
repository:
@gitaly_repo
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:repository_size
,
request
).
size
end
def
apply_gitattributes
(
revision
)
request
=
Gitaly
::
ApplyGitattributesRequest
.
new
(
repository:
@gitaly_repo
,
revision:
revision
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:apply_gitattributes
,
request
)
end
end
end
end
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
0 → 100644
View file @
6ed01ebf
require
'spec_helper'
describe
Gitlab
::
GitalyClient
::
RepositoryService
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:storage_name
)
{
project
.
repository_storage
}
let
(
:relative_path
)
{
project
.
disk_path
+
'.git'
}
let
(
:client
)
{
described_class
.
new
(
project
.
repository
)
}
describe
'#exists?'
do
it
'sends a repository_exists message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:repository_exists
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
(
exists:
true
))
client
.
exists?
end
end
describe
'#garbage_collect'
do
it
'sends a garbage_collect message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:garbage_collect
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
(
:garbage_collect_response
))
client
.
garbage_collect
(
true
)
end
end
describe
'#repack_full'
do
it
'sends a repack_full message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:repack_full
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
(
:repack_full_response
))
client
.
repack_full
(
true
)
end
end
describe
'#repack_incremental'
do
it
'sends a repack_incremental message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:repack_incremental
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
(
:repack_incremental_response
))
client
.
repack_incremental
end
end
describe
'#repository_size'
do
it
'sends a repository_size message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:repository_size
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
size:
0
)
client
.
repository_size
end
end
describe
'#apply_gitattributes'
do
let
(
:revision
)
{
'master'
}
it
'sends an apply_gitattributes message'
do
expect_any_instance_of
(
Gitaly
::
RepositoryService
::
Stub
)
.
to
receive
(
:apply_gitattributes
)
.
with
(
gitaly_request_with_path
(
storage_name
,
relative_path
),
kind_of
(
Hash
))
.
and_return
(
double
(
:apply_gitattributes_response
))
client
.
apply_gitattributes
(
revision
)
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