diff options
author | Martin Scholz <martin.scholz83@outlook.com> | 2022-02-11 13:47:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-11 13:47:22 +0100 |
commit | 26718a785ac49f17eab51ad0f5324d036b810f73 (patch) | |
tree | 9c8371e01460dacf8e65c88b3526e2123525c717 /modules/git/repo_stats.go | |
parent | 393ea86ae192325e45d7fac0fc6a277da8fb0fca (diff) | |
download | gitea-26718a785ac49f17eab51ad0f5324d036b810f73.tar.gz gitea-26718a785ac49f17eab51ad0f5324d036b810f73.zip |
Change git.cmd to RunWithContext (#18693)
Change all `cmd...Pipeline` commands to `cmd.RunWithContext`.
#18553
Co-authored-by: Martin Scholz <martin.scholz@versasec.com>
Diffstat (limited to 'modules/git/repo_stats.go')
-rw-r--r-- | modules/git/repo_stats.go | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/modules/git/repo_stats.go b/modules/git/repo_stats.go index 6f5973ebe5..598ec37a2c 100644 --- a/modules/git/repo_stats.go +++ b/modules/git/repo_stats.go @@ -67,12 +67,14 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) } stderr := new(strings.Builder) - err = NewCommand(repo.Ctx, args...).RunInDirTimeoutEnvFullPipelineFunc( - nil, -1, repo.Path, - stdoutWriter, stderr, nil, - func(ctx context.Context, cancel context.CancelFunc) error { + err = NewCommand(repo.Ctx, args...).RunWithContext(&RunContext{ + Env: []string{}, + Timeout: -1, + Dir: repo.Path, + Stdout: stdoutWriter, + Stderr: stderr, + PipelineFunc: func(ctx context.Context, cancel context.CancelFunc) error { _ = stdoutWriter.Close() - scanner := bufio.NewScanner(stdoutReader) scanner.Split(bufio.ScanLines) stats.CommitCount = 0 @@ -103,11 +105,7 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) case 4: // E-mail email := strings.ToLower(l) if _, ok := authors[email]; !ok { - authors[email] = &CodeActivityAuthor{ - Name: author, - Email: email, - Commits: 0, - } + authors[email] = &CodeActivityAuthor{Name: author, Email: email, Commits: 0} } authors[email].Commits++ default: // Changed file @@ -128,7 +126,6 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) } } } - a := make([]*CodeActivityAuthor, 0, len(authors)) for _, v := range authors { a = append(a, v) @@ -137,14 +134,13 @@ func (repo *Repository) GetCodeActivityStats(fromTime time.Time, branch string) sort.Slice(a, func(i, j int) bool { return a[i].Commits > a[j].Commits }) - stats.AuthorCount = int64(len(authors)) stats.ChangedFiles = int64(len(files)) stats.Authors = a - _ = stdoutReader.Close() return nil - }) + }, + }) if err != nil { return nil, fmt.Errorf("Failed to get GetCodeActivityStats for repository.\nError: %w\nStderr: %s", err, stderr) } |