Merge branch 'feature' into develop
This commit is contained in:
commit
f6d3f4d21a
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
gitea_git "code.gitea.io/gitea/modules/git"
|
||||
|
|
@ -37,7 +38,7 @@ func GetFirstAndLastCommitByPath(repo *gitea_git.Repository, revision, relpath s
|
|||
}
|
||||
|
||||
// CommitsByFileAndRange return the commits according revision file and the page
|
||||
func AllCommitsByFileAndRange(repo *gitea_git.Repository, opts gitea_git.CommitsByFileAndRangeOptions, pageSize int) ([]*gitea_git.Commit, error) {
|
||||
func AllCommitsByFileAndRange(repo *gitea_git.Repository, opts gitea_git.CommitsByFileAndRangeOptions, keyword string, pageSize int) ([]*gitea_git.Commit, error) {
|
||||
skip := (opts.Page - 1) * pageSize
|
||||
|
||||
stdoutReader, stdoutWriter := io.Pipe()
|
||||
|
|
@ -49,7 +50,8 @@ func AllCommitsByFileAndRange(repo *gitea_git.Repository, opts gitea_git.Commits
|
|||
stderr := strings.Builder{}
|
||||
gitCmd := gitea_git.NewCommand(repo.Ctx, "rev-list").
|
||||
AddOptionFormat("--max-count=%d", pageSize*opts.Page).
|
||||
AddOptionFormat("--skip=%d", skip)
|
||||
AddOptionFormat("--skip=%d", skip).
|
||||
AddOptionFormat("--grep=%s", keyword)
|
||||
gitCmd.AddDynamicArguments(opts.Revision)
|
||||
|
||||
if opts.Not != "" {
|
||||
|
|
@ -96,3 +98,18 @@ func AllCommitsByFileAndRange(repo *gitea_git.Repository, opts gitea_git.Commits
|
|||
commits = append(commits, commit)
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllCommitsCount(repo *gitea_git.Repository, keyword string) (int64, error) {
|
||||
cmd := gitea_git.NewCommand(repo.Ctx, "rev-list").
|
||||
AddOptionFormat("--grep=%s", keyword)
|
||||
cmd.AddArguments("--exclude=" + "refs/pull/" + "*")
|
||||
|
||||
cmd.AddArguments("--all", "--count")
|
||||
|
||||
stdout, _, err := cmd.RunStdString(&gitea_git.RunOpts{Dir: repo.Path})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,13 +58,13 @@ func ListBranches(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "CountBranches", err)
|
||||
return
|
||||
}
|
||||
if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
||||
totalNumOfBranches, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
||||
if err != nil {
|
||||
ctx.ServerError("SyncRepoBranches", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
// if totalNumOfBranches == 0 { // sync branches immediately because non-empty repository should have at least 1 branch
|
||||
// totalNumOfBranches, err = repo_module.SyncRepoBranches(ctx, ctx.Repo.Repository.ID, 0)
|
||||
// if err != nil {
|
||||
// ctx.ServerError("SyncRepoBranches", err)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
rules, err := git_model.FindRepoProtectedBranchRules(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ func GetRecentCommits(ctx *context.APIContext) {
|
|||
})
|
||||
return
|
||||
}
|
||||
|
||||
keyword := ctx.FormString("keyword")
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
if listOptions.Page <= 0 {
|
||||
listOptions.Page = 1
|
||||
|
|
@ -156,7 +159,7 @@ func GetRecentCommits(ctx *context.APIContext) {
|
|||
ctx.Error(http.StatusInternalServerError, "GetBranchCommit", err)
|
||||
return
|
||||
}
|
||||
commitsCountTotal, err = ctx.Repo.GitRepo.GetAllCommitsCount()
|
||||
commitsCountTotal, err = hat_git.GetAllCommitsCount(ctx.Repo.GitRepo, keyword)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CommitsCountFiles", err)
|
||||
return
|
||||
|
|
@ -167,7 +170,7 @@ func GetRecentCommits(ctx *context.APIContext) {
|
|||
Revision: baseCommit.ID.String(),
|
||||
File: ".",
|
||||
Page: listOptions.Page,
|
||||
}, listOptions.PageSize)
|
||||
}, keyword, listOptions.PageSize)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "CommitsByRange", err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue