Commit 69df9d7b authored by Patrick Bajao's avatar Patrick Bajao

Abort immediately when limit gets reached

parent 894157ad
......@@ -84,7 +84,7 @@ module EE
def check_push_size!
return unless check_size_limit?
# Use #quarantine_size to get correct push size whenever a lof of changes
# Use #check_quarantine_size to get correct push size whenever a lot of changes
# gets pushed at the same time containing the same blobs. This is only
# doable if GIT_OBJECT_DIRECTORY_RELATIVE env var is set and happens
# when git push comes from CLI (not via UI and API).
......@@ -92,10 +92,10 @@ module EE
# Fallback to determining push size using the changes_list so we can still
# determine the push size if env var isn't set (e.g. changes are made
# via UI and API).
push_size = check_quarantine_size? ? quarantine_size : changes_size
if project.changes_will_exceed_size_limit?(push_size)
raise ::Gitlab::GitAccess::UnauthorizedError, ::Gitlab::RepositorySizeError.new(project).new_changes_error
if check_quarantine_size?
check_quarantine_size
else
check_changes_size
end
end
......@@ -107,23 +107,29 @@ module EE
end
end
def quarantine_size
project.repository.object_directory_size
def check_quarantine_size
check_size_against_limit(project.repository.object_directory_size)
end
def changes_size
def check_changes_size
# 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
size_in_bytes = 0
changes_size = 0
changes_list.each do |change|
size_in_bytes += repository.new_blobs(change[:newrev]).sum(&:size) # rubocop: disable CodeReuse/ActiveRecord
changes_size += repository.new_blobs(change[:newrev]).sum(&:size) # rubocop: disable CodeReuse/ActiveRecord
check_size_against_limit(changes_size)
end
end
size_in_bytes
def check_size_against_limit(size)
if project.changes_will_exceed_size_limit?(size)
raise ::Gitlab::GitAccess::UnauthorizedError, ::Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
def check_size_limit?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment