aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/repo_stats.go
diff options
context:
space:
mode:
authorMartin Scholz <martin.scholz83@outlook.com>2022-02-11 13:47:22 +0100
committerGitHub <noreply@github.com>2022-02-11 13:47:22 +0100
commit26718a785ac49f17eab51ad0f5324d036b810f73 (patch)
tree9c8371e01460dacf8e65c88b3526e2123525c717 /modules/git/repo_stats.go
parent393ea86ae192325e45d7fac0fc6a277da8fb0fca (diff)
downloadgitea-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.go24
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)
}