fix: use linguist-generated for language stats (#7685)

- Adds code comment to explain behavior of the `linguist-generated` gitattribute.
- Adjusts the code to ignore the file if `linguist-generated` is true.
- Resolves forgejo/forgejo#7677
- Adds unit testing.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7685
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:
Gusted 2025-04-27 23:29:21 +00:00 committed by Gusted
parent 055fc6e0c3
commit 31cd8c6d38
23 changed files with 18 additions and 6 deletions

View file

@ -204,7 +204,13 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
return nil, err
}
}
if !isTrue(isGenerated) && enry.IsGenerated(f.Name(), content) {
// We consider three cases:
// 1. linguist-generated=true, then we ignore the file.
// 2. linguist-generated=false, we don't ignore the file.
// 3. linguist-generated is not set, then `enry.IsGenerated` determines if the file is generated.
if isTrue(isGenerated) || !isFalse(isGenerated) && enry.IsGenerated(f.Name(), content) {
log.Trace("Ignore %q for language stats, because it is generated", f.Name())
continue
}