Skip to content

Commit 76da070

Browse files
authored
Merge branch 'master' into pr-2edf7af9-56b4-48f6-ace2-decb1a5eaa3b
2 parents 876d7b1 + 0c0445c commit 76da070

File tree

19 files changed

+264
-149
lines changed

19 files changed

+264
-149
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fmt:
232232
vet:
233233
@echo "Running go vet..."
234234
@$(GO) vet $(GO_PACKAGES)
235-
@$(GO) build -mod=vendor code.gitea.io/gitea-vet
235+
@GOOS= GOARCH= $(GO) build -mod=vendor code.gitea.io/gitea-vet
236236
@$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
237237

238238
.PHONY: $(TAGS_EVIDENCE)

custom/conf/app.example.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,10 @@ MAX_GIT_DIFF_LINES = 1000
10981098
MAX_GIT_DIFF_LINE_CHARACTERS = 5000
10991099
; Max number of files shown in diff view
11001100
MAX_GIT_DIFF_FILES = 100
1101+
; Set the default commits range size
1102+
COMMITS_RANGE_SIZE = 50
1103+
; Set the default branches range size
1104+
BRANCHES_RANGE_SIZE = 20
11011105
; Arguments for command 'git gc', e.g. "--aggressive --auto"
11021106
; see more on http://git-scm.com/docs/git-gc/
11031107
GC_ARGS =

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false`
752752
- `MAX_GIT_DIFF_LINES`: **100**: Max number of lines allowed of a single file in diff view.
753753
- `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view.
754754
- `MAX_GIT_DIFF_FILES`: **100**: Max number of files shown in diff view.
755+
- `COMMITS_RANGE_SIZE`: **50**: Set the default commits range size
756+
- `BRANCHES_RANGE_SIZE`: **20**: Set the default branches range size
755757
- `GC_ARGS`: **\<empty\>**: Arguments for command `git gc`, e.g. `--aggressive --auto`. See more on http://git-scm.com/docs/git-gc/
756758
- `ENABLE_AUTO_GIT_WIRE_PROTOCOL`: **true**: If use git wire protocol version 2 when git version >= 2.18, default is true, set to false when you always want git wire protocol version 1
757759
- `PULL_REQUEST_PUSH_MESSAGE`: **true**: Respond to pushes to a non-default branch with a URL for creating a Pull Request (if the repository has them enabled)

docs/content/doc/usage/backup-and-restore.en-us.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ involves moving files to their correct locations and restoring a database dump.
7272
Example:
7373

7474
```sh
75-
apt-get install gitea
76-
unzip gitea-dump-1482906742.zip
77-
cd gitea-dump-1482906742
78-
mv custom/conf/app.ini /etc/gitea/conf/app.ini # or mv app.ini /etc/gitea/conf/app.ini
79-
unzip gitea-repo.zip
80-
mv gitea-repo/* /var/lib/gitea/repositories/
81-
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/
75+
unzip gitea-dump-1610949662.zip
76+
cd gitea-dump-1610949662
77+
mv data/conf/app.ini /etc/gitea/conf/app.ini
78+
mv data/* /var/lib/gitea/data/
79+
mv log/* /var/lib/gitea/log/
80+
mv repos/* /var/lib/gitea/repositories/
81+
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea
82+
83+
# mysql
8284
mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE <gitea-db.sql
83-
# or sqlite3 $DATABASE_PATH <gitea-db.sql
85+
# sqlite3
86+
sqlite3 $DATABASE_PATH <gitea-db.sql
87+
# postgres
88+
psql -U $USER -d $DATABASE < gitea-db.sql
89+
8490
service gitea restart
8591
```
8692

docs/content/doc/usage/backup-and-restore.zh-cn.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ Gitea 已经实现了 `dump` 命令可以用来备份所有需要的文件到一
4646

4747
例如:
4848

49-
```
50-
apt-get install gitea
51-
unzip gitea-dump-1482906742.zip
52-
cd gitea-dump-1482906742
53-
mv custom/conf/app.ini /etc/gitea/conf/app.ini
54-
unzip gitea-repo.zip
55-
mv gitea-repo/* /var/lib/gitea/repositories/
56-
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/
49+
```sh
50+
unzip gitea-dump-1610949662.zip
51+
cd gitea-dump-1610949662
52+
mv data/conf/app.ini /etc/gitea/conf/app.ini
53+
mv data/* /var/lib/gitea/data/
54+
mv log/* /var/lib/gitea/log/
55+
mv repos/* /var/lib/gitea/repositories/
56+
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea
57+
58+
# mysql
5759
mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE <gitea-db.sql
58-
# or sqlite3 $DATABASE_PATH <gitea-db.sql
60+
# sqlite3
61+
sqlite3 $DATABASE_PATH <gitea-db.sql
62+
# postgres
63+
psql -U $USER -d $DATABASE < gitea-db.sql
64+
5965
service gitea restart
6066
```

docs/content/doc/usage/backup-and-restore.zh-tw.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ Gitea 目前支援 `dump` 指令,用來將資料備份成 zip 檔案,後續
4343
## 還原指令 (`restore`)
4444

4545
持續更新中: 此文件尚未完成.
46+
47+
例:
48+
```sh
49+
unzip gitea-dump-1610949662.zip
50+
cd gitea-dump-1610949662
51+
mv data/conf/app.ini /etc/gitea/conf/app.ini
52+
mv data/* /var/lib/gitea/data/
53+
mv log/* /var/lib/gitea/log/
54+
mv repos/* /var/lib/gitea/repositories/
55+
chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea
56+
57+
# mysql
58+
mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE <gitea-db.sql
59+
# sqlite3
60+
sqlite3 $DATABASE_PATH <gitea-db.sql
61+
# postgres
62+
psql -U $USER -d $DATABASE < gitea-db.sql
63+
64+
service gitea restart
65+
```

models/issue_label.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type Label struct {
4747
func GetLabelTemplateFile(name string) ([][3]string, error) {
4848
data, err := GetRepoInitFile("label", name)
4949
if err != nil {
50-
return nil, fmt.Errorf("GetRepoInitFile: %v", err)
50+
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)}
5151
}
5252

5353
lines := strings.Split(string(data), "\n")
@@ -62,15 +62,15 @@ func GetLabelTemplateFile(name string) ([][3]string, error) {
6262

6363
fields := strings.SplitN(parts[0], " ", 2)
6464
if len(fields) != 2 {
65-
return nil, fmt.Errorf("line is malformed: %s", line)
65+
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("line is malformed: %s", line)}
6666
}
6767

6868
color := strings.Trim(fields[0], " ")
6969
if len(color) == 6 {
7070
color = "#" + color
7171
}
7272
if !LabelColorPattern.MatchString(color) {
73-
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
73+
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("bad HTML color code in line: %s", line)}
7474
}
7575

7676
var description string
@@ -167,7 +167,7 @@ func (label *Label) ForegroundColor() template.CSS {
167167
func loadLabels(labelTemplate string) ([]string, error) {
168168
list, err := GetLabelTemplateFile(labelTemplate)
169169
if err != nil {
170-
return nil, ErrIssueLabelTemplateLoad{labelTemplate, err}
170+
return nil, err
171171
}
172172

173173
labels := make([]string, len(list))
@@ -186,7 +186,7 @@ func LoadLabelsFormatted(labelTemplate string) (string, error) {
186186
func initializeLabels(e Engine, id int64, labelTemplate string, isOrg bool) error {
187187
list, err := GetLabelTemplateFile(labelTemplate)
188188
if err != nil {
189-
return ErrIssueLabelTemplateLoad{labelTemplate, err}
189+
return err
190190
}
191191

192192
labels := make([]*Label, len(list))

models/repo.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,26 +1511,27 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
15111511
}
15121512

15131513
// DeleteRepository deletes a repository for a user or organization.
1514+
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
15141515
func DeleteRepository(doer *User, uid, repoID int64) error {
1516+
sess := x.NewSession()
1517+
defer sess.Close()
1518+
if err := sess.Begin(); err != nil {
1519+
return err
1520+
}
1521+
15151522
// In case is a organization.
1516-
org, err := GetUserByID(uid)
1523+
org, err := getUserByID(sess, uid)
15171524
if err != nil {
15181525
return err
15191526
}
15201527
if org.IsOrganization() {
1521-
if err = org.GetTeams(&SearchTeamOptions{}); err != nil {
1528+
if err = org.getTeams(sess); err != nil {
15221529
return err
15231530
}
15241531
}
15251532

1526-
sess := x.NewSession()
1527-
defer sess.Close()
1528-
if err = sess.Begin(); err != nil {
1529-
return err
1530-
}
1531-
1532-
repo := &Repository{ID: repoID, OwnerID: uid}
1533-
has, err := sess.Get(repo)
1533+
repo := &Repository{OwnerID: uid}
1534+
has, err := sess.ID(repoID).Get(repo)
15341535
if err != nil {
15351536
return err
15361537
} else if !has {
@@ -1679,14 +1680,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
16791680
}
16801681

16811682
if err = sess.Commit(); err != nil {
1682-
sess.Close()
1683-
if len(deployKeys) > 0 {
1684-
// We need to rewrite the public keys because the commit failed
1685-
if err2 := RewriteAllPublicKeys(); err2 != nil {
1686-
return fmt.Errorf("Commit: %v SSH Keys: %v", err, err2)
1687-
}
1688-
}
1689-
return fmt.Errorf("Commit: %v", err)
1683+
return err
16901684
}
16911685

16921686
sess.Close()

modules/git/repo_commit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
110110
// CommitsRangeSize the default commits range size
111111
var CommitsRangeSize = 50
112112

113+
// BranchesRangeSize the default branches range size
114+
var BranchesRangeSize = 20
115+
113116
func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) (*list.List, error) {
114117
stdout, err := NewCommand("log", id.String(), "--skip="+strconv.Itoa((page-1)*pageSize),
115118
"--max-count="+strconv.Itoa(pageSize), prettyLogFormat).RunInDirBytes(repo.Path)

modules/repository/create.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
2727
opts.DefaultBranch = setting.Repository.DefaultBranch
2828
}
2929

30+
// Check if label template exist
31+
if len(opts.IssueLabels) > 0 {
32+
if _, err := models.GetLabelTemplateFile(opts.IssueLabels); err != nil {
33+
return nil, err
34+
}
35+
}
36+
3037
repo := &models.Repository{
3138
OwnerID: u.ID,
3239
Owner: u,
@@ -45,6 +52,8 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
4552
TrustModel: opts.TrustModel,
4653
}
4754

55+
var rollbackRepo *models.Repository
56+
4857
if err := models.WithTx(func(ctx models.DBContext) error {
4958
if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil {
5059
return err
@@ -76,7 +85,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
7685
}
7786
}
7887

79-
if err := initRepository(ctx, repoPath, doer, repo, opts); err != nil {
88+
if err = initRepository(ctx, repoPath, doer, repo, opts); err != nil {
8089
if err2 := util.RemoveAll(repoPath); err2 != nil {
8190
log.Error("initRepository: %v", err)
8291
return fmt.Errorf(
@@ -87,10 +96,9 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
8796

8897
// Initialize Issue Labels if selected
8998
if len(opts.IssueLabels) > 0 {
90-
if err := models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
91-
if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
92-
log.Error("Rollback deleteRepository: %v", errDelete)
93-
}
99+
if err = models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
100+
rollbackRepo = repo
101+
rollbackRepo.OwnerID = u.ID
94102
return fmt.Errorf("InitializeLabels: %v", err)
95103
}
96104
}
@@ -99,13 +107,18 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
99107
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
100108
RunInDir(repoPath); err != nil {
101109
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
102-
if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
103-
log.Error("Rollback deleteRepository: %v", errDelete)
104-
}
110+
rollbackRepo = repo
111+
rollbackRepo.OwnerID = u.ID
105112
return fmt.Errorf("CreateRepository(git update-server-info): %v", err)
106113
}
107114
return nil
108115
}); err != nil {
116+
if rollbackRepo != nil {
117+
if errDelete := models.DeleteRepository(doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil {
118+
log.Error("Rollback deleteRepository: %v", errDelete)
119+
}
120+
}
121+
109122
return nil, err
110123
}
111124

modules/setting/git.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var (
1919
MaxGitDiffLines int
2020
MaxGitDiffLineCharacters int
2121
MaxGitDiffFiles int
22+
CommitsRangeSize int
23+
BranchesRangeSize int
2224
VerbosePush bool
2325
VerbosePushDelay time.Duration
2426
GCArgs []string `ini:"GC_ARGS" delim:" "`
@@ -37,6 +39,8 @@ var (
3739
MaxGitDiffLines: 1000,
3840
MaxGitDiffLineCharacters: 5000,
3941
MaxGitDiffFiles: 100,
42+
CommitsRangeSize: 50,
43+
BranchesRangeSize: 20,
4044
VerbosePush: true,
4145
VerbosePushDelay: 5 * time.Second,
4246
GCArgs: []string{},
@@ -91,5 +95,8 @@ func newGit() {
9195
args = append(args, "Version 2") // for focus color
9296
}
9397

98+
git.CommitsRangeSize = Git.CommitsRangeSize
99+
git.BranchesRangeSize = Git.BranchesRangeSize
100+
94101
log.Info(format, args...)
95102
}

modules/structs/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type CreateRepoOption struct {
106106
Description string `json:"description" binding:"MaxSize(255)"`
107107
// Whether the repository is private
108108
Private bool `json:"private"`
109-
// Issue Label set to use
109+
// Label-Set to use
110110
IssueLabels string `json:"issue_labels"`
111111
// Whether the repository should be auto-intialized?
112112
AutoInit bool `json:"auto_init"`

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ or_enter_secret = Or enter the secret: %s
625625
then_enter_passcode = And enter the passcode shown in the application:
626626
passcode_invalid = The passcode is incorrect. Try again.
627627
twofa_enrolled = Your account has been enrolled into two-factor authentication. Store your scratch token (%s) in a safe place as it is only shown once!
628+
twofa_failed_get_secret = Failed to get secret.
628629

629630
u2f_desc = Security keys are hardware devices containing cryptographic keys. They can be used for two-factor authentication. Security keys must support the <a rel="noreferrer" href="https://fidoalliance.org/">FIDO U2F</a> standard.
630631
u2f_require_twofa = Your account must be enrolled in two-factor authentication to use security keys.

0 commit comments

Comments
 (0)