diff --git a/Makefile b/Makefile index dc8faf817d8c5..4e03581785ff5 100644 --- a/Makefile +++ b/Makefile @@ -232,7 +232,7 @@ fmt: vet: @echo "Running go vet..." @$(GO) vet $(GO_PACKAGES) - @$(GO) build -mod=vendor code.gitea.io/gitea-vet + @GOOS= GOARCH= $(GO) build -mod=vendor code.gitea.io/gitea-vet @$(GO) vet -vettool=gitea-vet $(GO_PACKAGES) .PHONY: $(TAGS_EVIDENCE) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 4ceaaef20e53a..00461bc969db8 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -1124,6 +1124,10 @@ MAX_GIT_DIFF_LINES = 1000 MAX_GIT_DIFF_LINE_CHARACTERS = 5000 ; Max number of files shown in diff view MAX_GIT_DIFF_FILES = 100 +; Set the default commits range size +COMMITS_RANGE_SIZE = 50 +; Set the default branches range size +BRANCHES_RANGE_SIZE = 20 ; Arguments for command 'git gc', e.g. "--aggressive --auto" ; see more on http://git-scm.com/docs/git-gc/ GC_ARGS = diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 5b86cadd445f8..50d6a072276f2 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -752,6 +752,8 @@ NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false` - `MAX_GIT_DIFF_LINES`: **100**: Max number of lines allowed of a single file in diff view. - `MAX_GIT_DIFF_LINE_CHARACTERS`: **5000**: Max character count per line highlighted in diff view. - `MAX_GIT_DIFF_FILES`: **100**: Max number of files shown in diff view. +- `COMMITS_RANGE_SIZE`: **50**: Set the default commits range size +- `BRANCHES_RANGE_SIZE`: **20**: Set the default branches range size - `GC_ARGS`: **\**: Arguments for command `git gc`, e.g. `--aggressive --auto`. See more on http://git-scm.com/docs/git-gc/ - `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 - `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) diff --git a/docs/content/doc/usage/backup-and-restore.en-us.md b/docs/content/doc/usage/backup-and-restore.en-us.md index 5e822dc05e7b1..fb0216cd1f52f 100644 --- a/docs/content/doc/usage/backup-and-restore.en-us.md +++ b/docs/content/doc/usage/backup-and-restore.en-us.md @@ -72,15 +72,21 @@ involves moving files to their correct locations and restoring a database dump. Example: ```sh -apt-get install gitea -unzip gitea-dump-1482906742.zip -cd gitea-dump-1482906742 -mv custom/conf/app.ini /etc/gitea/conf/app.ini # or mv app.ini /etc/gitea/conf/app.ini -unzip gitea-repo.zip -mv gitea-repo/* /var/lib/gitea/repositories/ -chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea/repositories/ +unzip gitea-dump-1610949662.zip +cd gitea-dump-1610949662 +mv data/conf/app.ini /etc/gitea/conf/app.ini +mv data/* /var/lib/gitea/data/ +mv log/* /var/lib/gitea/log/ +mv repos/* /var/lib/gitea/repositories/ +chown -R gitea:gitea /etc/gitea/conf/app.ini /var/lib/gitea + +# mysql mysql --default-character-set=utf8mb4 -u$USER -p$PASS $DATABASE git.BranchesRangeSize { + pageSize = git.BranchesRangeSize + } + + branches, branchesCount := loadBranches(ctx, page, pageSize) + if ctx.Written() { + return + } + ctx.Data["Branches"] = branches + pager := context.NewPagination(int(branchesCount), git.BranchesRangeSize, page, 5) + pager.SetDefaultParams(ctx) + ctx.Data["Page"] = pager + ctx.HTML(200, tplBranch) } @@ -176,17 +194,25 @@ func deleteBranch(ctx *context.Context, branchName string) error { return nil } -func loadBranches(ctx *context.Context) []*Branch { +// loadBranches loads branches from the repository limited by page & pageSize. +// NOTE: May write to context on error. page & pageSize must be > 0 +func loadBranches(ctx *context.Context, page, pageSize int) ([]*Branch, int) { + defaultBranch, err := repo_module.GetBranch(ctx.Repo.Repository, ctx.Repo.Repository.DefaultBranch) + if err != nil { + ctx.ServerError("GetDefaultBranch", err) + return nil, 0 + } + rawBranches, err := repo_module.GetBranches(ctx.Repo.Repository) if err != nil { ctx.ServerError("GetBranches", err) - return nil + return nil, 0 } protectedBranches, err := ctx.Repo.Repository.GetProtectedBranches() if err != nil { ctx.ServerError("GetProtectedBranches", err) - return nil + return nil, 0 } repoIDToRepo := map[int64]*models.Repository{} @@ -195,100 +221,129 @@ func loadBranches(ctx *context.Context) []*Branch { repoIDToGitRepo := map[int64]*git.Repository{} repoIDToGitRepo[ctx.Repo.Repository.ID] = ctx.Repo.GitRepo - branches := make([]*Branch, len(rawBranches)) - for i := range rawBranches { - commit, err := rawBranches[i].GetCommit() + var totalNumOfBranches = len(rawBranches) + var startIndex = (page - 1) * pageSize + if startIndex > totalNumOfBranches { + startIndex = totalNumOfBranches - 1 + } + var endIndex = startIndex + pageSize + if endIndex > totalNumOfBranches { + endIndex = totalNumOfBranches - 1 + } + + var branches []*Branch + for i := startIndex; i < endIndex; i++ { + var branch = loadOneBranch(ctx, rawBranches[i], protectedBranches, repoIDToRepo, repoIDToGitRepo) + if branch == nil { + return nil, 0 + } + + if branch.Name == ctx.Repo.Repository.DefaultBranch { + // Skip default branch + continue + } + + branches = append(branches, branch) + } + + // Always add the default branch + branches = append(branches, loadOneBranch(ctx, defaultBranch, protectedBranches, repoIDToRepo, repoIDToGitRepo)) + + if ctx.Repo.CanWrite(models.UnitTypeCode) { + deletedBranches, err := getDeletedBranches(ctx) if err != nil { - ctx.ServerError("GetCommit", err) - return nil + ctx.ServerError("getDeletedBranches", err) + return nil, 0 } + branches = append(branches, deletedBranches...) + } - var isProtected bool - branchName := rawBranches[i].Name - for _, b := range protectedBranches { - if b.BranchName == branchName { - isProtected = true - break - } + return branches, len(rawBranches) - 1 +} + +func loadOneBranch(ctx *context.Context, rawBranch *git.Branch, protectedBranches []*models.ProtectedBranch, + repoIDToRepo map[int64]*models.Repository, + repoIDToGitRepo map[int64]*git.Repository) *Branch { + + commit, err := rawBranch.GetCommit() + if err != nil { + ctx.ServerError("GetCommit", err) + return nil + } + + branchName := rawBranch.Name + var isProtected bool + for _, b := range protectedBranches { + if b.BranchName == branchName { + isProtected = true + break } + } + + divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, git.BranchPrefix+branchName) + if divergenceError != nil { + ctx.ServerError("CountDivergingCommits", divergenceError) + return nil + } + + pr, err := models.GetLatestPullRequestByHeadInfo(ctx.Repo.Repository.ID, branchName) + if err != nil { + ctx.ServerError("GetLatestPullRequestByHeadInfo", err) + return nil + } + headCommit := commit.ID.String() - divergence, divergenceError := repofiles.CountDivergingCommits(ctx.Repo.Repository, git.BranchPrefix+branchName) - if divergenceError != nil { - ctx.ServerError("CountDivergingCommits", divergenceError) + mergeMovedOn := false + if pr != nil { + pr.HeadRepo = ctx.Repo.Repository + if err := pr.LoadIssue(); err != nil { + ctx.ServerError("pr.LoadIssue", err) return nil } - - pr, err := models.GetLatestPullRequestByHeadInfo(ctx.Repo.Repository.ID, branchName) - if err != nil { - ctx.ServerError("GetLatestPullRequestByHeadInfo", err) + if repo, ok := repoIDToRepo[pr.BaseRepoID]; ok { + pr.BaseRepo = repo + } else if err := pr.LoadBaseRepo(); err != nil { + ctx.ServerError("pr.LoadBaseRepo", err) return nil + } else { + repoIDToRepo[pr.BaseRepoID] = pr.BaseRepo } - headCommit := commit.ID.String() + pr.Issue.Repo = pr.BaseRepo - mergeMovedOn := false - if pr != nil { - pr.HeadRepo = ctx.Repo.Repository - if err := pr.LoadIssue(); err != nil { - ctx.ServerError("pr.LoadIssue", err) - return nil + if pr.HasMerged { + baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID] + if !ok { + baseGitRepo, err = git.OpenRepository(pr.BaseRepo.RepoPath()) + if err != nil { + ctx.ServerError("OpenRepository", err) + return nil + } + defer baseGitRepo.Close() + repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo } - if repo, ok := repoIDToRepo[pr.BaseRepoID]; ok { - pr.BaseRepo = repo - } else if err := pr.LoadBaseRepo(); err != nil { - ctx.ServerError("pr.LoadBaseRepo", err) + pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName()) + if err != nil && !git.IsErrNotExist(err) { + ctx.ServerError("GetBranchCommitID", err) return nil - } else { - repoIDToRepo[pr.BaseRepoID] = pr.BaseRepo } - pr.Issue.Repo = pr.BaseRepo - - if pr.HasMerged { - baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID] - if !ok { - baseGitRepo, err = git.OpenRepository(pr.BaseRepo.RepoPath()) - if err != nil { - ctx.ServerError("OpenRepository", err) - return nil - } - defer baseGitRepo.Close() - repoIDToGitRepo[pr.BaseRepoID] = baseGitRepo - } - pullCommit, err := baseGitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil && !git.IsErrNotExist(err) { - ctx.ServerError("GetBranchCommitID", err) - return nil - } - if err == nil && headCommit != pullCommit { - // the head has moved on from the merge - we shouldn't delete - mergeMovedOn = true - } + if err == nil && headCommit != pullCommit { + // the head has moved on from the merge - we shouldn't delete + mergeMovedOn = true } } - - isIncluded := divergence.Ahead == 0 && ctx.Repo.Repository.DefaultBranch != branchName - - branches[i] = &Branch{ - Name: branchName, - Commit: commit, - IsProtected: isProtected, - IsIncluded: isIncluded, - CommitsAhead: divergence.Ahead, - CommitsBehind: divergence.Behind, - LatestPullRequest: pr, - MergeMovedOn: mergeMovedOn, - } } - if ctx.Repo.CanWrite(models.UnitTypeCode) { - deletedBranches, err := getDeletedBranches(ctx) - if err != nil { - ctx.ServerError("getDeletedBranches", err) - return nil - } - branches = append(branches, deletedBranches...) + isIncluded := divergence.Ahead == 0 && ctx.Repo.Repository.DefaultBranch != branchName + return &Branch{ + Name: branchName, + Commit: commit, + IsProtected: isProtected, + IsIncluded: isIncluded, + CommitsAhead: divergence.Ahead, + CommitsBehind: divergence.Behind, + LatestPullRequest: pr, + MergeMovedOn: mergeMovedOn, } - - return branches } func getDeletedBranches(ctx *context.Context) ([]*Branch, error) { diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index cf7c22462966f..8176738ff60b3 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -127,6 +127,7 @@ + {{template "base/paginate" .}} {{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index c8cc454928eb5..3a21a9271b2a2 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -527,18 +527,15 @@ {{ if and .IsRepoAdmin (not .Repository.IsArchived) }}
-
- - -
+