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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1b56af58
Commit
1b56af58
authored
Dec 20, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract push size check into dedicated method
parent
ca3d8271
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
15 deletions
+23
-15
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+23
-15
No files found.
lib/gitlab/git_access.rb
View file @
1b56af58
...
...
@@ -279,17 +279,16 @@ module Gitlab
end
check_change_access!
check_push_size!
end
# rubocop: disable CodeReuse/ActiveRecord
def
check_change_access!
# If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also
# clear stale lock files.
project
.
repository
.
clean_stale_repository_files
push_size_in_bytes
=
0
# Iterate over all changes to find if user allowed all of them to be applied
changes_list
.
each
.
with_index
do
|
change
,
index
|
first_change
=
index
==
0
...
...
@@ -297,17 +296,8 @@ module Gitlab
# If user does not have access to make at least one change, cancel all
# push by allowing the exception to bubble up
check_single_change_access
(
change
,
skip_lfs_integrity_check:
!
first_change
)
if
project
.
size_limit_enabled?
push_size_in_bytes
+=
repository
.
new_blobs
(
change
[
:newrev
]).
sum
(
&
:size
)
end
end
if
check_size_limit?
&&
project
.
changes_will_exceed_size_limit?
(
push_size_in_bytes
)
raise
UnauthorizedError
,
Gitlab
::
RepositorySizeError
.
new
(
project
).
new_changes_error
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
check_single_change_access
(
change
,
skip_lfs_integrity_check:
false
)
change_access
=
Checks
::
ChangeAccess
.
new
(
...
...
@@ -325,6 +315,25 @@ module Gitlab
raise
TimeoutError
,
logger
.
full_message
end
def
check_push_size!
return
unless
check_size_limit?
# If there are worktrees with a HEAD pointing to a non-existent object,
# calls to `git rev-list --all` will fail in git 2.15+. This should also
# clear stale lock files.
project
.
repository
.
clean_stale_repository_files
# rubocop: disable CodeReuse/ActiveRecord
push_size_in_bytes
=
changes_list
.
sum
do
|
change
|
repository
.
new_blobs
(
change
[
:newrev
]).
sum
(
&
:size
)
end
# rubocop: enable CodeReuse/ActiveRecord
if
project
.
changes_will_exceed_size_limit?
(
push_size_in_bytes
)
raise
UnauthorizedError
,
Gitlab
::
RepositorySizeError
.
new
(
project
).
new_changes_error
end
end
def
deploy_key
actor
if
deploy_key?
end
...
...
@@ -381,9 +390,8 @@ module Gitlab
def
check_size_limit?
strong_memoize
(
:check_size_limit
)
do
changes_list
.
any?
do
|
change
|
change
[
:newrev
]
&&
change
[
:newrev
]
!=
::
Gitlab
::
Git
::
BLANK_SHA
end
project
.
size_limit_enabled?
&&
changes_list
.
any?
{
|
change
|
!
Gitlab
::
Git
.
blank_ref?
(
change
[
:newrev
])
}
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