Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit repo size #21820

Open
wants to merge 151 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
bb96349
rebase on master
sapk Nov 7, 2020
56b92a1
generate swagger
sapk Nov 7, 2020
2f65545
add some tests
sapk Nov 7, 2020
7c31cfc
add some tests
sapk Nov 7, 2020
6a2e670
Merge remote-tracking branch 'upstream/main' into limit-repo-size ini…
sapk Nov 12, 2022
df60de2
Fixing Merge errors - still few to go
DmitryFrolovTri Nov 12, 2022
136b631
Removed code frmo models/repo/repo.go to stop compile errors - TODO f…
DmitryFrolovTri Nov 14, 2022
20bfff3
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 15, 2022
75585de
lint related changes
DmitryFrolovTri Nov 15, 2022
036e55c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 16, 2022
62d3c05
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 24, 2022
ee31efc
fix migrations.go conflict
DmitryFrolovTri Nov 24, 2022
36b43fe
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 26, 2022
762799b
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 26, 2022
b391383
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 30, 2022
04de706
Merge branch 'main' into limit-repo-size
zeripath Dec 3, 2022
d9ab187
update license header
techknowlogick Dec 4, 2022
31359b4
moved AddSizeLimitOnRepo migration to v1_19 package
DmitryFrolovTri Dec 4, 2022
4c0921e
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 4, 2022
1c7b3b6
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 5, 2022
a16f5fa
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 5, 2022
af2e3a3
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 6, 2022
4687f0c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 8, 2022
d1368ec
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 14, 2022
4256bdc
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 16, 2022
cdc5a2c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 19, 2022
e26bcfc
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 21, 2022
2763393
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 25, 2022
e7ab661
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 27, 2022
6060ae1
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 9, 2023
8383ec5
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 9, 2023
562bc27
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 9, 2023
d13d457
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 9, 2023
80fa68b
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 10, 2023
4a31279
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 11, 2023
fe168a4
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 11, 2023
f8b1413
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 12, 2023
ac99056
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 13, 2023
0666202
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 14, 2023
c20faef
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 16, 2023
3429b99
Fix merge conflict in migrations.go, v238.go, create v999.go and Merg…
DmitryFrolovTri Jan 17, 2023
bcea146
Fix merge conflig in migrations.go Merge remote-tracking branch 'upst…
DmitryFrolovTri Jan 18, 2023
7aeb909
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 19, 2023
dd0246e
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 20, 2023
64f5b94
Fixing lint error in models/migrations/v1_19 for v999.go
DmitryFrolovTri Jan 20, 2023
9a36273
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 22, 2023
cc2521c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 23, 2023
8adfb6d
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 23, 2023
b00f27e
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 24, 2023
37725e4
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 26, 2023
7b4e90b
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jan 29, 2023
9da8b9d
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 1, 2023
82dcd0c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 3, 2023
ae06851
Fixed Test(SizeLimit/Over)
truecode112 Feb 6, 2023
e3b4628
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 6, 2023
8494f19
fix fmt errors
DmitryFrolovTri Feb 6, 2023
0afa267
Fixed unclosed logger test
truecode112 Feb 6, 2023
211c085
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 6, 2023
8293e7f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 14, 2023
920fb58
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 17, 2023
f583b8f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 27, 2023
8a84718
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 27, 2023
4b09713
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Mar 13, 2023
3f8bdd1
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Mar 22, 2023
ab5ffc0
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Mar 25, 2023
83cc033
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Apr 14, 2023
d98a62a
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Apr 17, 2023
7f28229
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Apr 18, 2023
4793882
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 3, 2023
3592ae7
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 3, 2023
1765ea3
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 11, 2023
a22b738
Added ENABLE_SIZE_LIMIT config option
truecode112 May 15, 2023
66c476e
UI related changed for ENABLE_SIZE_LIMIT & REPO_SIZE_LIMIT options
truecode112 May 15, 2023
d843a67
Overall Done for Global Repo Size Limit Option
truecode112 May 15, 2023
0231760
All done for Global Repo Size Option
truecode112 May 15, 2023
82f3e2d
add test for global repo size limit option
truecode112 May 15, 2023
2a1abe5
Add test script
truecode112 May 15, 2023
3d0004a
Modified app.example.ini with REPO_SIZE_LIMIT and ENABLE_SIZE_LIMIT o…
DmitryFrolovTri May 15, 2023
414c902
updated content/doc/administration/config-cheat-sheet.en-us.md with E…
DmitryFrolovTri May 15, 2023
31600a0
Config parameter REPO_SIZE_LIMIT = XXXX (should accept bytes human re…
May 16, 2023
703ba07
Config parameter REPO_SIZE_LIMIT = XXXX (should accept bytes human re…
May 16, 2023
c55ccfd
revert saving config part
May 16, 2023
9e5f2fd
lint error fixed.
May 16, 2023
80f8977
fixed issues for testing
May 16, 2023
8ac833a
Fixed issues in test scripts.
May 16, 2023
c31c510
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 17, 2023
8750728
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 17, 2023
c2fc283
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 17, 2023
4936e49
present a correct message when repo is over
May 17, 2023
e9c29f8
doDeleteCommitAndPush implemented
May 18, 2023
57c94e6
Allow operations that potentially reduce repository size through even…
DmitryFrolovTri May 19, 2023
656a3dc
Update modules/setting/repository.go
DmitryFrolovTri May 19, 2023
ef760d7
Update modules/base/tool_test.go
DmitryFrolovTri May 19, 2023
51a7697
Fix in /modules/setting/repository.go
DmitryFrolovTri May 19, 2023
2cbdee0
Revert "doDeleteCommitAndPush implemented"
DmitryFrolovTri May 19, 2023
88e74d6
Correctly report messages on erros with rev-list size getting on pre …
DmitryFrolovTri May 21, 2023
7120c30
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 21, 2023
db5a8da
Refactor hook_pre_recieve to increase speed of size checking
DmitryFrolovTri May 23, 2023
08c65ff
Update for TestScript to Reduce RepoSize
May 23, 2023
ab3097d
Merge branch 'limit-repo-size' of https://github.com/DmitryFrolovTri/…
May 23, 2023
ed4865c
Refactor hook_pre_recieve to increase speed of size checking and mino…
DmitryFrolovTri May 23, 2023
c96ec8d
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 23, 2023
fd73ace
Merge branch 'limit-repo-size' of https://github.com/DmitryFrolovTri/…
May 23, 2023
256173f
Fixed lint errors in hook_pre_recieve.go
DmitryFrolovTri May 23, 2023
6e99cf4
Merge branch 'limit-repo-size' into upstream
DmitryFrolovTri May 23, 2023
a32f797
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 23, 2023
7bc9554
The size unit of measurements should be mentioned in the config and d…
DmitryFrolovTri May 23, 2023
22bb76c
Revert "Update for TestScript to Reduce RepoSize"
DmitryFrolovTri May 24, 2023
a08c6fe
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 24, 2023
64f6dd6
Documentation modification for the repo size limit feature
DmitryFrolovTri May 24, 2023
20d4d4f
test script to check if repo size is reduced.
May 25, 2023
39ade30
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri May 26, 2023
0c3a46f
checking reduced size scenario 2
May 26, 2023
ccc564a
Merge branch 'limit-repo-size' of https://github.com/DmitryFrolovTri/…
May 26, 2023
851c988
Fixed getting repo size via api call.
May 31, 2023
649da24
Removing unneeded comments
DmitryFrolovTri Jun 7, 2023
44df2b6
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 7, 2023
9c9f75f
Limit repo size packs (#1)
DmitryFrolovTri Jun 12, 2023
cdf5946
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 13, 2023
eac9822
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 13, 2023
4b709c6
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 14, 2023
7240e3a
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 19, 2023
c203d2c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 29, 2023
bc1cb65
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 30, 2023
9014d9f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jun 30, 2023
79251d5
fixed a lint error
DmitryFrolovTri Jun 30, 2023
bc051a3
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jul 11, 2023
b521d36
Now in hook_pre_recieve.go, when cat file -s is called - the work is …
DmitryFrolovTri Jul 11, 2023
9bf945f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jul 24, 2023
efd3596
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jul 24, 2023
410d0cd
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jul 24, 2023
236681b
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Jul 28, 2023
918325f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Aug 23, 2023
0e05c2e
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Aug 23, 2023
e5a04cd
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Sep 4, 2023
e9b8e6f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Sep 5, 2023
8097699
Updated routers/web/admin/repos_test.go to use code.gitea.io/gitea/mo…
DmitryFrolovTri Sep 5, 2023
23a492d
Merge remote-tracking branch 'upstream/main' into limit-repo-size, fi…
DmitryFrolovTri Sep 14, 2023
f810b42
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Oct 4, 2023
cfd013f
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Oct 25, 2023
aec62fa
Update templates/repo/settings/options.tmpl
DmitryFrolovTri Nov 7, 2023
b709876
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Nov 8, 2023
e1267d5
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Dec 2, 2023
3612140
fix a panic in hook_pre_recieve.go
DmitryFrolovTri Dec 2, 2023
006f216
fix race condition due to opts.Env. Exclude size breach determination…
DmitryFrolovTri Dec 3, 2023
0fee4f4
Merge remote-tracking branch 'upstream/main' into limit-repo-size.
DmitryFrolovTri Feb 28, 2024
ecdc2a7
Fixes related to prior merge
DmitryFrolovTri Feb 28, 2024
807da90
Postmerge update auth for TestGit/HTTP/SizeLimit - Over, UnderAfterRe…
DmitryFrolovTri Feb 28, 2024
4b6a77c
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Feb 28, 2024
bf1870d
Merge remote-tracking branch 'upstream/main' into limit-repo-size
DmitryFrolovTri Mar 5, 2024
748dbd0
Merge remote-tracking branch 'upstream/main' into limit-repo-size
techknowlogick Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,15 @@ LEVEL = Info

;; Allow fork repositories without maximum number limit
;ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT = true
;
;; Enable applying a global size limit defined by REPO_SIZE_LIMIT. Each repository can have a value that overrides the global limit
;; "false" means no limit will be enforced, even if specified on a repository
;ENABLE_SIZE_LIMIT = false
Copy link
Member

@lafriks lafriks Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this option even needed? I mean if by default global limit and individual repo limit is 0 (no limit). What is the use case for this option and why disabled by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks The reason why disabled by default is that it is a feature that should be enabled by administrator people mostly install gitea for their own need and such option might not be needed by default. It would be needed for any cloud install. So this allows gitea to work like before.
Despite me believing it that feature is ready, I still believe it should be "experimental" hence disabled by default for some time.

Copy link
Contributor Author

@DmitryFrolovTri DmitryFrolovTri Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks As for the use case it allows to easily switch on and off without modifying anything in the actual limits. Cause it could be quite hard after populating all the size limits individually on different repos to disable this feature. One would need to update each repo size limit to 0 (if he chooses not to use the global one) and his previous value would be lost. The repo size limit takes precedence over global size limit

Copy link
Member

@lafriks lafriks Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but if you do not need limits you would not just set them, we have too many options already imho in app ini to add even more, as for being experimental we could state it in docs and UI in label for example.

Copy link
Contributor Author

@DmitryFrolovTri DmitryFrolovTri Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main issue that still needs to be resolved is splitting repo size stored in database (git object size and LFS object size) in different columns

Of course refactor to split current repo size column into two can be made outside of this PR but this PR should depend on it being merged first

from your point of view how this one is close to the needed @lafriks ?
#22900

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks ok so let's see how can we help @a1012112796 to achieve it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but if you do not need limits you would not just set them, we have too many options already imho in app ini to add even more, as for being experimental we could state it in docs and UI in label for example.

@lafriks that was my use case:

  • As an administrator of gitea site I want to quickly enable or disable size limits without modifying the actual limit values as I had done some calculations while enabling them and I have many repositories.

What could the solution be then to achieve it?

  • keep as is
  • drop the requirement and set individual and global repo size limits to 0 on all repos to disable size limit feature
  • create a non "app.ini" global setting switch in UI/DB that is persistent
  • modify docs, advise that global size limit boolean switch is an experiments and would be removed later, decommission setting later
  • something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lafriks is current apporach ok? Can I resolve this. if not - could you choose among the options or suggest something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we don't need this. We can use REPO_SIZE_LIMIT = 0 to do the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the REPO_SIZE_LIMIT = -1 as the switch off (and removing the boolean flag).

REPO_SIZE_LIMIT = 0 Size limit is enabled but I don't care what the size limit is if an individual repo size limit is set use it.
REPO_SIZE_LIMIT > 0 Use this Size limit for any repository where size limit is 0 (not set) use individual repo size where it is set
Does this look acceptable? This would remove the need to for the extra config parameter also it would still allow ti switch off the size limit checking if administrator chooses to do so?

;
;; Specify a global repository size limit in bytes to apply for each repository. 0 - No limit
;; If repository has it's own limit set in UI it will override the global setting
;; Standard units of measurements for size can be used like B, KB, KiB, ... , EB, EiB, ...
;REPO_SIZE_LIMIT = 0
lunny marked this conversation as resolved.
Show resolved Hide resolved

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
52 changes: 52 additions & 0 deletions docs/content/administration/repo-size-limit.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
date: "2023-05-24T13:00:00+00:00"
title: "Per repository size limit"
slug: "repo-size-limit"
weight: 12
toc: false
draft: false
aliases:
- /en-us/repo-size-limit
menu:
sidebar:
parent: "administration"
name: "Per repository size limit"
weight: 12
identifier: "repo-size-limit"
---

# Gitea per repository size limit setup

To use Gitea's experimental built-in per repository size limit support, Administrator must update the `app.ini` file:

```ini
;; Enable applying a global size limit defined by REPO_SIZE_LIMIT. Each repository can have a value that overrides the global limit
;; "false" means no limit will be enforced, even if specified on a repository
ENABLE_SIZE_LIMIT = true

;; Specify a global repository size limit in bytes to apply for each repository. 0 - No limit
;; If repository has it's own limit set in UI it will override the global setting
;; Standard units of measurements for size can be used like B, KB, KiB, ... , EB, EiB, ...
REPO_SIZE_LIMIT = 500 MB

This setting is persistent.

The size limitation is triggered when repository `disk size` + `new commit size` > `defined repository size limit`

If size limitation is triggered the feature would prevent commits that increase repository size on disk
of gitea server and allow those that decrease it

# Gitea per repository size limit setup in UI

1. For Gitea admin it is possible during runtime to enable/disable limit size feature, change the global size limit on the fly.
**This setting is not persistent across restarts**

`Admin panel/Site settings` -> `Repository management`

Persistance can be achieved if the limit is maintained by editing `app.ini` file

2. The individually set per repository limit in `Settings` of the
repository would take precedence over global limit when the size limit
feature is enabled. Only admin can modify those limits

**Note**: Size checking for large repositories is time consuming operation so time of push under size limit might increase up to a minute depending on your server hardware
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ var migrations = []Migration{
NewMigration("Add metadata column for comment table", v1_23.AddCommentMetaDataColumn),
// v304 -> v305
NewMigration("Add index for release sha1", v1_23.AddIndexForReleaseSha1),
// to modify later
NewMigration("Add size limit on repository", v1_22.AddSizeLimitOnRepo),
}

// GetCurrentDBVersion returns the current db version
Expand Down
17 changes: 17 additions & 0 deletions models/migrations/v1_22/v999.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package v1_22 //nolint

import (
"xorm.io/xorm"
)

func AddSizeLimitOnRepo(x *xorm.Engine) error {
type Repository struct {
ID int64 `xorm:"pk autoincr"`
SizeLimit int64 `xorm:"NOT NULL DEFAULT 0"`
}

return x.Sync2(new(Repository))
}
23 changes: 23 additions & 0 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ type Repository struct {
BaseRepo *Repository `xorm:"-"`
IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"`
TemplateID int64 `xorm:"INDEX"`
SizeLimit int64 `xorm:"NOT NULL DEFAULT 0"`
Size int64 `xorm:"NOT NULL DEFAULT 0"`
EnableSizeLimit bool `xorm:"NOT NULL DEFAULT true"`
GitSize int64 `xorm:"NOT NULL DEFAULT 0"`
LFSSize int64 `xorm:"NOT NULL DEFAULT 0"`
CodeIndexerStatus *RepoIndexerStatus `xorm:"-"`
Expand Down Expand Up @@ -584,6 +586,27 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
return repo.OwnerID == userID
}

// GetActualSizeLimit returns repository size limit in bytes
// or global repository limit setting if per repository size limit is not set
func (repo *Repository) GetActualSizeLimit() int64 {
sizeLimit := repo.SizeLimit
if setting.RepoSizeLimit > 0 && sizeLimit == 0 {
sizeLimit = setting.RepoSizeLimit
}
return sizeLimit
}

// RepoSizeIsOversized return true if is over size limitation
func (repo *Repository) IsRepoSizeOversized(additionalSize int64) bool {
return setting.EnableSizeLimit && repo.GetActualSizeLimit() > 0 && repo.GitSize+additionalSize > repo.GetActualSizeLimit()
}

// RepoSizeLimitEnabled return true if size limit checking is enabled and limit is non zero for this specific repository
// this is used to enable size checking during pre-receive hook
func (repo *Repository) IsRepoSizeLimitEnabled() bool {
return setting.EnableSizeLimit && repo.GetActualSizeLimit() > 0
}

// CanCreateBranch returns true if repository meets the requirements for creating new branches.
func (repo *Repository) CanCreateBranch() bool {
return !repo.IsMirror
Expand Down
7 changes: 7 additions & 0 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func FileSize(s int64) string {
return humanize.IBytes(uint64(s))
}

// Get FileSize bytes value from String.
func GetFileSize(s string) (int64, error) {
v, err := humanize.ParseBytes(s)
iv := int64(v)
return iv, err
}

// EllipsisString returns a truncated short string,
// it appends '...' in the end of the length of string is too large.
func EllipsisString(str string, length int) string {
Expand Down
7 changes: 7 additions & 0 deletions modules/base/tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func TestFileSize(t *testing.T) {
assert.Equal(t, "2.0 EiB", FileSize(size))
}

func TestGetFileSize(t *testing.T) {
var size int64 = 512 * 1024 * 1024 * 1024
s, err := GetFileSize("512 GiB")
assert.Equal(t, s, size)
assert.Nil(t, err)
}

func TestEllipsisString(t *testing.T) {
assert.Equal(t, "...", EllipsisString("foobar", 0))
assert.Equal(t, "...", EllipsisString("foobar", 1))
Expand Down
68 changes: 68 additions & 0 deletions modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,74 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
return nil
}

// CountObject represents repository count objects report
type CountObject struct {
Count int64
Size int64
InPack int64
Packs int64
SizePack int64
PrunePack int64
Garbage int64
SizeGarbage int64
}

const (
statCount = "count: "
statSize = "size: "
statInpack = "in-pack: "
statPacks = "packs: "
statSizePack = "size-pack: "
statPrunePackage = "prune-package: "
statGarbage = "garbage: "
statSizeGarbage = "size-garbage: "
)

// CountObjects returns the results of git count-objects on the repoPath
func CountObjects(ctx context.Context, repoPath string) (*CountObject, error) {
return CountObjectsWithEnv(ctx, repoPath, nil)
}

// CountObjectsWithEnv returns the results of git count-objects on the repoPath with custom env setup
func CountObjectsWithEnv(ctx context.Context, repoPath string, env []string) (*CountObject, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need a go-git variant too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @KN4CK3R would we need this into this PR or it's ok to add later?
@truecode112 fyi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KN4CK3R could you please advise if it is still a "may" on this item or it is actually "must"?

cmd := NewCommand(ctx, "count-objects", "-v")
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath, Env: env})
if err != nil {
return nil, err
}

return parseSize(stdout), nil
}

// parseSize parses the output from count-objects and return a CountObject
func parseSize(objects string) *CountObject {
repoSize := new(CountObject)
for _, line := range strings.Split(objects, "\n") {
switch {
case strings.HasPrefix(line, statCount):
repoSize.Count, _ = strconv.ParseInt(line[7:], 10, 64)
case strings.HasPrefix(line, statSize):
number, _ := strconv.ParseInt(line[6:], 10, 64)
repoSize.Size = number * 1024
case strings.HasPrefix(line, statInpack):
repoSize.InPack, _ = strconv.ParseInt(line[9:], 10, 64)
case strings.HasPrefix(line, statPacks):
repoSize.Packs, _ = strconv.ParseInt(line[7:], 10, 64)
case strings.HasPrefix(line, statSizePack):
number, _ := strconv.ParseInt(line[11:], 10, 64)
repoSize.SizePack = number * 1024
case strings.HasPrefix(line, statPrunePackage):
repoSize.PrunePack, _ = strconv.ParseInt(line[16:], 10, 64)
case strings.HasPrefix(line, statGarbage):
repoSize.Garbage, _ = strconv.ParseInt(line[9:], 10, 64)
case strings.HasPrefix(line, statSizeGarbage):
number, _ := strconv.ParseInt(line[14:], 10, 64)
repoSize.SizeGarbage = number * 1024
}
}
return repoSize
}

// GetLatestCommitTime returns time for latest commit in repository (across all branches)
func GetLatestCommitTime(ctx context.Context, repoPath string) (time.Time, error) {
cmd := NewCommand(ctx, "for-each-ref", "--sort=-committerdate", BranchPrefix, "--count", "1", "--format=%(committerdate)")
Expand Down
25 changes: 25 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"

"code.gitea.io/gitea/modules/log"

"github.com/dustin/go-humanize"
)

// enumerates all the policy repository creating
Expand Down Expand Up @@ -268,12 +270,35 @@ var (
}
RepoRootPath string
ScriptType = "bash"

EnableSizeLimit = true
RepoSizeLimit int64
)

func SaveGlobalRepositorySetting(enableSizeLimit bool, repoSizeLimit int64) error {
EnableSizeLimit = enableSizeLimit
RepoSizeLimit = repoSizeLimit
sec := CfgProvider.Section("repository")
if EnableSizeLimit {
sec.Key("ENABLE_SIZE_LIMIT").SetValue("true")
} else {
sec.Key("ENABLE_SIZE_LIMIT").SetValue("false")
}

sec.Key("REPO_SIZE_LIMIT").SetValue(humanize.Bytes(uint64(RepoSizeLimit)))
return nil
}

func loadRepositoryFrom(rootCfg ConfigProvider) {
var err error

// Determine and create root git repository path.
sec := rootCfg.Section("repository")
EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool(false)

v, _ := humanize.ParseBytes(sec.Key("REPO_SIZE_LIMIT").MustString("0"))
RepoSizeLimit = int64(v)

Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()
Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool()
Repository.GoGetCloneURLProtocol = sec.Key("GO_GET_CLONE_URL_PROTOCOL").MustString("https")
Expand Down
4 changes: 4 additions & 0 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ type CreateRepoOption struct {
// ObjectFormatName of the underlying git repository
// enum: sha1,sha256
ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"`
// SizeLimit of the repository
SizeLimit int64 `json:"size_limit"`
}

// EditRepoOption options when editing a repository's properties
Expand Down Expand Up @@ -216,6 +218,8 @@ type EditRepoOption struct {
DefaultAllowMaintainerEdit *bool `json:"default_allow_maintainer_edit,omitempty"`
// set to `true` to archive this repository.
Archived *bool `json:"archived,omitempty"`
// SizeLimit of the repository.
SizeLimit *int64 `json:"size_limit,omitempty"`
// set to a string like `8h30m0s` to set the mirror interval time
MirrorInterval *string `json:"mirror_interval,omitempty"`
// enable prune - remove obsolete remote-tracking references when mirroring
Expand Down
10 changes: 10 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ owner_helper = Some organizations may not show up in the dropdown due to a maxim
repo_name = Repository Name
repo_name_helper = Good repository names use short, memorable and unique keywords.
repo_size = Repository Size
repo_size_limit = Repository Size Limit
template = Template
template_select = Select a template.
template_helper = Make repository a template
Expand Down Expand Up @@ -1132,6 +1133,8 @@ form.reach_limit_of_creation_1 = The owner has already reached the limit of %d r
form.reach_limit_of_creation_n = The owner has already reached the limit of %d repositories.
form.name_reserved = The repository name "%s" is reserved.
form.name_pattern_not_allowed = The pattern "%s" is not allowed in a repository name.
form.repo_size_limit_negative = Repository size limitation cannot be negative.
form.repo_size_limit_only_by_admins = Only administrators can change the repository size limitation.

need_auth = Authorization
migrate_options = Migration Options
Expand Down Expand Up @@ -3290,6 +3293,13 @@ config.disable_gravatar = Disable Gravatar
config.enable_federated_avatar = Enable Federated Avatars
config.open_with_editor_app_help = The "Open with" editors for the clone menu. If left empty, the default will be used. Expand to see the default.

config.repository_config = Repository Configuration
config.enable_size_limit = Enable Size Limit
config.repo_size_limit = Default Repository Size Limit
config.invalid_repo_size = Invalid repository size %s
config.save_repo_size_setting_failed = Failed to save global repository settings %s
config.repository_setting_success = Global repository setting has been updated

config.git_config = Git Configuration
config.git_disable_diff_highlight = Disable Diff Syntax Highlight
config.git_max_diff_lines = Max Diff Lines (for a single file)
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
TrustModel: repo_model.ToTrustModel(opt.TrustModel),
IsTemplate: opt.Template,
ObjectFormatName: opt.ObjectFormatName,
SizeLimit: opt.SizeLimit,
})
if err != nil {
if repo_model.IsErrRepoAlreadyExist(err) {
Expand Down Expand Up @@ -743,6 +744,10 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
repo.DefaultBranch = *opts.DefaultBranch
}

if opts.SizeLimit != nil {
repo.SizeLimit = *opts.SizeLimit
}

if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateRepository", err)
return err
Expand Down
Loading
Loading