mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-24 11:13:47 +00:00
[v12.0/forgejo] fix: correctly get stats for API commits (#8758)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8758 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
parent
3740bcc837
commit
1ef2c321be
4 changed files with 115 additions and 7 deletions
|
@ -183,6 +183,17 @@ func (repo *Repository) GetDiffShortStat(base, head string) (numFiles, totalAddi
|
|||
return numFiles, totalAdditions, totalDeletions, err
|
||||
}
|
||||
|
||||
// GetCommitStat returns the number of files, total additions and total deletions the commit has.
|
||||
func (repo *Repository) GetCommitShortStat(commitID string) (numFiles, totalAdditions, totalDeletions int, err error) {
|
||||
cmd := NewCommand(repo.Ctx, "diff-tree", "--shortstat", "--no-commit-id", "--root").AddDynamicArguments(commitID)
|
||||
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repo.Path})
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
return parseDiffStat(stdout)
|
||||
}
|
||||
|
||||
// GetDiffShortStat counts number of changed files, number of additions and deletions
|
||||
func GetDiffShortStat(ctx context.Context, repoPath string, trustedArgs TrustedCmdArgs, dynamicArgs ...string) (numFiles, totalAdditions, totalDeletions int, err error) {
|
||||
// Now if we call:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue