mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-05 10:46:45 +02:00
fix: correctly get stats for API commits (#8756)
- Instead of generating a patch and parsing its contents, use a faster and simple way to get it via `--shortstat`. - Resolves forgejo/forgejo#8725 - Regression of forgejo/forgejo#7682 - Adds unit test. - Adds integration test. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8756 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
e4cd25057f
commit
648a75e687
4 changed files with 115 additions and 7 deletions
|
@ -15,7 +15,6 @@ import (
|
|||
api "forgejo.org/modules/structs"
|
||||
"forgejo.org/modules/util"
|
||||
ctx "forgejo.org/services/context"
|
||||
"forgejo.org/services/gitdiff"
|
||||
)
|
||||
|
||||
// ToCommitUser convert a git.Signature to an api.CommitUser
|
||||
|
@ -210,17 +209,15 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
|
|||
|
||||
// Get diff stats for commit
|
||||
if opts.Stat {
|
||||
diff, _, err := gitdiff.GetDiffSimple(ctx, gitRepo, &gitdiff.DiffOptions{
|
||||
AfterCommitID: commit.ID.String(),
|
||||
})
|
||||
_, totalAdditions, totalDeletions, err := gitRepo.GetCommitShortStat(commit.ID.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
res.Stats = &api.CommitStats{
|
||||
Total: diff.TotalAddition + diff.TotalDeletion,
|
||||
Additions: diff.TotalAddition,
|
||||
Deletions: diff.TotalDeletion,
|
||||
Total: totalAdditions + totalDeletions,
|
||||
Additions: totalAdditions,
|
||||
Deletions: totalDeletions,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue