Skip to content

Commit b57c09b

Browse files
author
Gusted
authored
Merge branch 'main' into publickey-auth-push-mirror
2 parents 4adf2e1 + 06e4687 commit b57c09b

File tree

126 files changed

+891
-584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+891
-584
lines changed

cmd/dump.go

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package cmd
77

88
import (
99
"fmt"
10+
"io"
1011
"os"
1112
"path"
1213
"path/filepath"
@@ -25,10 +26,21 @@ import (
2526
"github.com/urfave/cli"
2627
)
2728

28-
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
29+
func addReader(w archiver.Writer, r io.ReadCloser, info os.FileInfo, customName string, verbose bool) error {
2930
if verbose {
30-
log.Info("Adding file %s\n", filePath)
31+
log.Info("Adding file %s", customName)
3132
}
33+
34+
return w.Write(archiver.File{
35+
FileInfo: archiver.FileInfo{
36+
FileInfo: info,
37+
CustomName: customName,
38+
},
39+
ReadCloser: r,
40+
})
41+
}
42+
43+
func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
3244
file, err := os.Open(absPath)
3345
if err != nil {
3446
return err
@@ -39,13 +51,7 @@ func addFile(w archiver.Writer, filePath, absPath string, verbose bool) error {
3951
return err
4052
}
4153

42-
return w.Write(archiver.File{
43-
FileInfo: archiver.FileInfo{
44-
FileInfo: fileInfo,
45-
CustomName: filePath,
46-
},
47-
ReadCloser: file,
48-
})
54+
return addReader(w, file, fileInfo, filePath, verbose)
4955
}
5056

5157
func isSubdir(upper, lower string) (bool, error) {
@@ -136,6 +142,10 @@ It can be used for backup and capture Gitea server image to send to maintainer`,
136142
Name: "skip-attachment-data",
137143
Usage: "Skip attachment data",
138144
},
145+
cli.BoolFlag{
146+
Name: "skip-package-data",
147+
Usage: "Skip package data",
148+
},
139149
cli.GenericFlag{
140150
Name: "type",
141151
Value: outputTypeEnum,
@@ -241,13 +251,7 @@ func runDump(ctx *cli.Context) error {
241251
return err
242252
}
243253

244-
return w.Write(archiver.File{
245-
FileInfo: archiver.FileInfo{
246-
FileInfo: info,
247-
CustomName: path.Join("data", "lfs", objPath),
248-
},
249-
ReadCloser: object,
250-
})
254+
return addReader(w, object, info, path.Join("data", "lfs", objPath), verbose)
251255
}); err != nil {
252256
fatal("Failed to dump LFS objects: %v", err)
253257
}
@@ -326,6 +330,7 @@ func runDump(ctx *cli.Context) error {
326330
excludes = append(excludes, setting.RepoRootPath)
327331
excludes = append(excludes, setting.LFS.Path)
328332
excludes = append(excludes, setting.Attachment.Path)
333+
excludes = append(excludes, setting.Packages.Path)
329334
excludes = append(excludes, setting.LogRootPath)
330335
excludes = append(excludes, absFileName)
331336
if err := addRecursiveExclude(w, "data", setting.AppDataPath, excludes, verbose); err != nil {
@@ -341,17 +346,24 @@ func runDump(ctx *cli.Context) error {
341346
return err
342347
}
343348

344-
return w.Write(archiver.File{
345-
FileInfo: archiver.FileInfo{
346-
FileInfo: info,
347-
CustomName: path.Join("data", "attachments", objPath),
348-
},
349-
ReadCloser: object,
350-
})
349+
return addReader(w, object, info, path.Join("data", "attachments", objPath), verbose)
351350
}); err != nil {
352351
fatal("Failed to dump attachments: %v", err)
353352
}
354353

354+
if ctx.IsSet("skip-package-data") && ctx.Bool("skip-package-data") {
355+
log.Info("Skip dumping package data")
356+
} else if err := storage.Packages.IterateObjects(func(objPath string, object storage.Object) error {
357+
info, err := object.Stat()
358+
if err != nil {
359+
return err
360+
}
361+
362+
return addReader(w, object, info, path.Join("data", "packages", objPath), verbose)
363+
}); err != nil {
364+
fatal("Failed to dump packages: %v", err)
365+
}
366+
355367
// Doesn't check if LogRootPath exists before processing --skip-log intentionally,
356368
// ensuring that it's clear the dump is skipped whether the directory's initialized
357369
// yet or not.

contrib/upgrade.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
function giteacmd {
2626
if [[ $sudocmd = "su" ]]; then
27-
"$sudocmd" - "$giteauser" -c "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
27+
# `-c` only accept one string as argument.
28+
"$sudocmd" - "$giteauser" -c "$(printf "%q " "$giteabin" "--config" "$giteaconf" "--work-path" "$giteahome" "$@")"
2829
else
2930
"$sudocmd" --user "$giteauser" "$giteabin" --config "$giteaconf" --work-path "$giteahome" "$@"
3031
fi

custom/conf/app.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ INTERNAL_TOKEN=
398398
;; By modifying the Gitea database, users can gain Gitea administrator privileges.
399399
;; It also enables them to access other resources available to the user on the operating system that is running the Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
400400
;; WARNING: This maybe harmful to you website or your operating system.
401+
;; WARNING: Setting this to true does not change existing hooks in git repos; adjust it before if necessary.
401402
;DISABLE_GIT_HOOKS = true
402403
;;
403404
;; Set to true to disable webhooks feature.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
497497
It also enables them to access other resources available to the user on the operating system that is running the
498498
Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
499499
This maybe harmful to you website or your operating system.
500+
Setting this to true does not change existing hooks in git repos; adjust it before if necessary.
500501
- `DISABLE_WEBHOOKS`: **false**: Set to `true` to disable webhooks feature.
501502
- `ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET`: **true**: Set to `false` to allow local users to push to gitea-repositories without setting up the Gitea environment. This is not recommended and if you want local users to push to Gitea repositories you should set the environment appropriately.
502503
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.

docs/content/doc/installation/with-docker.fr-fr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Vous devriez avoir une instance fonctionnelle de Gitea. Pour accèder à l'inter
4343

4444
## Named Volumes
4545

46-
Ce guide aboutira à une installation avec les données Gita et PostgreSQL stockées dans des volumes nommés. Cela permet une sauvegarde, une restauration et des mises à niveau en toute simplicité.
46+
Ce guide aboutira à une installation avec les données Gitea et PostgreSQL stockées dans des volumes nommés. Cela permet une sauvegarde, une restauration et des mises à niveau en toute simplicité.
4747

4848
### The Database
4949

docs/content/doc/usage/command-line.en-us.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,13 @@ in the current directory.
313313
- `--tempdir path`, `-t path`: Path to the temporary directory used. Optional. (default: /tmp).
314314
- `--skip-repository`, `-R`: Skip the repository dumping. Optional.
315315
- `--skip-custom-dir`: Skip dumping of the custom dir. Optional.
316+
- `--skip-lfs-data`: Skip dumping of LFS data. Optional.
317+
- `--skip-attachment-data`: Skip dumping of attachment data. Optional.
318+
- `--skip-package-data`: Skip dumping of package data. Optional.
319+
- `--skip-log`: Skip dumping of log data. Optional.
316320
- `--database`, `-d`: Specify the database SQL syntax. Optional.
317321
- `--verbose`, `-V`: If provided, shows additional details. Optional.
322+
- `--type`: Set the dump output format. Optional. (default: zip)
318323
- Examples:
319324
- `gitea dump`
320325
- `gitea dump --verbose`

integrations/integration_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ func TestMain(m *testing.M) {
112112
}
113113
}
114114

115+
os.Unsetenv("GIT_AUTHOR_NAME")
116+
os.Unsetenv("GIT_AUTHOR_EMAIL")
117+
os.Unsetenv("GIT_AUTHOR_DATE")
118+
os.Unsetenv("GIT_COMMITTER_NAME")
119+
os.Unsetenv("GIT_COMMITTER_EMAIL")
120+
os.Unsetenv("GIT_COMMITTER_DATE")
121+
115122
err := unittest.InitFixtures(
116123
unittest.FixturesOptions{
117124
Dir: filepath.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),

models/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ func notifyWatchers(ctx context.Context, actions ...*Action) error {
508508
permPR[i] = false
509509
continue
510510
}
511-
perm, err := getUserRepoPermission(ctx, repo, user)
511+
perm, err := GetUserRepoPermission(ctx, repo, user)
512512
if err != nil {
513513
permCode[i] = false
514514
permIssue[i] = false

models/branches.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,57 +337,57 @@ type WhitelistOptions struct {
337337
// If ID is 0, it creates a new record. Otherwise, updates existing record.
338338
// This function also performs check if whitelist user and team's IDs have been changed
339339
// to avoid unnecessary whitelist delete and regenerate.
340-
func UpdateProtectBranch(repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
341-
if err = repo.GetOwner(db.DefaultContext); err != nil {
340+
func UpdateProtectBranch(ctx context.Context, repo *repo_model.Repository, protectBranch *ProtectedBranch, opts WhitelistOptions) (err error) {
341+
if err = repo.GetOwner(ctx); err != nil {
342342
return fmt.Errorf("GetOwner: %v", err)
343343
}
344344

345-
whitelist, err := updateUserWhitelist(repo, protectBranch.WhitelistUserIDs, opts.UserIDs)
345+
whitelist, err := updateUserWhitelist(ctx, repo, protectBranch.WhitelistUserIDs, opts.UserIDs)
346346
if err != nil {
347347
return err
348348
}
349349
protectBranch.WhitelistUserIDs = whitelist
350350

351-
whitelist, err = updateUserWhitelist(repo, protectBranch.MergeWhitelistUserIDs, opts.MergeUserIDs)
351+
whitelist, err = updateUserWhitelist(ctx, repo, protectBranch.MergeWhitelistUserIDs, opts.MergeUserIDs)
352352
if err != nil {
353353
return err
354354
}
355355
protectBranch.MergeWhitelistUserIDs = whitelist
356356

357-
whitelist, err = updateApprovalWhitelist(repo, protectBranch.ApprovalsWhitelistUserIDs, opts.ApprovalsUserIDs)
357+
whitelist, err = updateApprovalWhitelist(ctx, repo, protectBranch.ApprovalsWhitelistUserIDs, opts.ApprovalsUserIDs)
358358
if err != nil {
359359
return err
360360
}
361361
protectBranch.ApprovalsWhitelistUserIDs = whitelist
362362

363363
// if the repo is in an organization
364-
whitelist, err = updateTeamWhitelist(repo, protectBranch.WhitelistTeamIDs, opts.TeamIDs)
364+
whitelist, err = updateTeamWhitelist(ctx, repo, protectBranch.WhitelistTeamIDs, opts.TeamIDs)
365365
if err != nil {
366366
return err
367367
}
368368
protectBranch.WhitelistTeamIDs = whitelist
369369

370-
whitelist, err = updateTeamWhitelist(repo, protectBranch.MergeWhitelistTeamIDs, opts.MergeTeamIDs)
370+
whitelist, err = updateTeamWhitelist(ctx, repo, protectBranch.MergeWhitelistTeamIDs, opts.MergeTeamIDs)
371371
if err != nil {
372372
return err
373373
}
374374
protectBranch.MergeWhitelistTeamIDs = whitelist
375375

376-
whitelist, err = updateTeamWhitelist(repo, protectBranch.ApprovalsWhitelistTeamIDs, opts.ApprovalsTeamIDs)
376+
whitelist, err = updateTeamWhitelist(ctx, repo, protectBranch.ApprovalsWhitelistTeamIDs, opts.ApprovalsTeamIDs)
377377
if err != nil {
378378
return err
379379
}
380380
protectBranch.ApprovalsWhitelistTeamIDs = whitelist
381381

382382
// Make sure protectBranch.ID is not 0 for whitelists
383383
if protectBranch.ID == 0 {
384-
if _, err = db.GetEngine(db.DefaultContext).Insert(protectBranch); err != nil {
384+
if _, err = db.GetEngine(ctx).Insert(protectBranch); err != nil {
385385
return fmt.Errorf("Insert: %v", err)
386386
}
387387
return nil
388388
}
389389

390-
if _, err = db.GetEngine(db.DefaultContext).ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
390+
if _, err = db.GetEngine(ctx).ID(protectBranch.ID).AllCols().Update(protectBranch); err != nil {
391391
return fmt.Errorf("Update: %v", err)
392392
}
393393

@@ -416,15 +416,15 @@ func IsProtectedBranch(repoID int64, branchName string) (bool, error) {
416416

417417
// updateApprovalWhitelist checks whether the user whitelist changed and returns a whitelist with
418418
// the users from newWhitelist which have explicit read or write access to the repo.
419-
func updateApprovalWhitelist(repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
419+
func updateApprovalWhitelist(ctx context.Context, repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
420420
hasUsersChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
421421
if !hasUsersChanged {
422422
return currentWhitelist, nil
423423
}
424424

425425
whitelist = make([]int64, 0, len(newWhitelist))
426426
for _, userID := range newWhitelist {
427-
if reader, err := IsRepoReader(repo, userID); err != nil {
427+
if reader, err := IsRepoReader(ctx, repo, userID); err != nil {
428428
return nil, err
429429
} else if !reader {
430430
continue
@@ -437,19 +437,19 @@ func updateApprovalWhitelist(repo *repo_model.Repository, currentWhitelist, newW
437437

438438
// updateUserWhitelist checks whether the user whitelist changed and returns a whitelist with
439439
// the users from newWhitelist which have write access to the repo.
440-
func updateUserWhitelist(repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
440+
func updateUserWhitelist(ctx context.Context, repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
441441
hasUsersChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
442442
if !hasUsersChanged {
443443
return currentWhitelist, nil
444444
}
445445

446446
whitelist = make([]int64, 0, len(newWhitelist))
447447
for _, userID := range newWhitelist {
448-
user, err := user_model.GetUserByID(userID)
448+
user, err := user_model.GetUserByIDCtx(ctx, userID)
449449
if err != nil {
450450
return nil, fmt.Errorf("GetUserByID [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
451451
}
452-
perm, err := GetUserRepoPermission(repo, user)
452+
perm, err := GetUserRepoPermission(ctx, repo, user)
453453
if err != nil {
454454
return nil, fmt.Errorf("GetUserRepoPermission [user_id: %d, repo_id: %d]: %v", userID, repo.ID, err)
455455
}
@@ -466,13 +466,13 @@ func updateUserWhitelist(repo *repo_model.Repository, currentWhitelist, newWhite
466466

467467
// updateTeamWhitelist checks whether the team whitelist changed and returns a whitelist with
468468
// the teams from newWhitelist which have write access to the repo.
469-
func updateTeamWhitelist(repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
469+
func updateTeamWhitelist(ctx context.Context, repo *repo_model.Repository, currentWhitelist, newWhitelist []int64) (whitelist []int64, err error) {
470470
hasTeamsChanged := !util.IsSliceInt64Eq(currentWhitelist, newWhitelist)
471471
if !hasTeamsChanged {
472472
return currentWhitelist, nil
473473
}
474474

475-
teams, err := organization.GetTeamsWithAccessToRepo(repo.OwnerID, repo.ID, perm.AccessModeRead)
475+
teams, err := organization.GetTeamsWithAccessToRepo(ctx, repo.OwnerID, repo.ID, perm.AccessModeRead)
476476
if err != nil {
477477
return nil, fmt.Errorf("GetTeamsWithAccessToRepo [org_id: %d, repo_id: %d]: %v", repo.OwnerID, repo.ID, err)
478478
}

models/branches_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package models
77
import (
88
"testing"
99

10+
"code.gitea.io/gitea/models/db"
1011
repo_model "code.gitea.io/gitea/models/repo"
1112
"code.gitea.io/gitea/models/unittest"
1213

@@ -99,11 +100,14 @@ func TestRenameBranch(t *testing.T) {
99100
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
100101
_isDefault := false
101102

102-
err := UpdateProtectBranch(repo1, &ProtectedBranch{
103+
ctx, committer, err := db.TxContext()
104+
defer committer.Close()
105+
assert.NoError(t, err)
106+
assert.NoError(t, UpdateProtectBranch(ctx, repo1, &ProtectedBranch{
103107
RepoID: repo1.ID,
104108
BranchName: "master",
105-
}, WhitelistOptions{})
106-
assert.NoError(t, err)
109+
}, WhitelistOptions{}))
110+
assert.NoError(t, committer.Commit())
107111

108112
assert.NoError(t, RenameBranch(repo1, "master", "main", func(isDefault bool) error {
109113
_isDefault = isDefault

models/commit_status.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,13 @@ type CommitStatusIndex struct {
232232

233233
// GetLatestCommitStatus returns all statuses with a unique context for a given commit.
234234
func GetLatestCommitStatus(repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, int64, error) {
235-
return getLatestCommitStatus(db.GetEngine(db.DefaultContext), repoID, sha, listOptions)
235+
return GetLatestCommitStatusCtx(db.DefaultContext, repoID, sha, listOptions)
236236
}
237237

238-
func getLatestCommitStatus(e db.Engine, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, int64, error) {
238+
// GetLatestCommitStatusCtx returns all statuses with a unique context for a given commit.
239+
func GetLatestCommitStatusCtx(ctx context.Context, repoID int64, sha string, listOptions db.ListOptions) ([]*CommitStatus, int64, error) {
239240
ids := make([]int64, 0, 10)
240-
sess := e.Table(&CommitStatus{}).
241+
sess := db.GetEngine(ctx).Table(&CommitStatus{}).
241242
Where("repo_id = ?", repoID).And("sha = ?", sha).
242243
Select("max( id ) as id").
243244
GroupBy("context_hash").OrderBy("max( id ) desc")
@@ -252,7 +253,7 @@ func getLatestCommitStatus(e db.Engine, repoID int64, sha string, listOptions db
252253
if len(ids) == 0 {
253254
return statuses, count, nil
254255
}
255-
return statuses, count, e.In("id", ids).Find(&statuses)
256+
return statuses, count, db.GetEngine(ctx).In("id", ids).Find(&statuses)
256257
}
257258

258259
// FindRepoRecentCommitStatusContexts returns repository's recent commit status contexts

0 commit comments

Comments
 (0)