mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Change git.cmd to RunWithContext (#18693)
Change all `cmd...Pipeline` commands to `cmd.RunWithContext`. #18553 Co-authored-by: Martin Scholz <martin.scholz@versasec.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user