Skip to content

Keep languages defined in .gitattributes #21403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/git/repo_language_stats_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
defer deferable()

sizes := make(map[string]int64)
keepLanguage := make(map[string]struct{})
err = tree.Files().ForEach(func(f *object.File) error {
if f.Size == 0 {
return nil
Expand Down Expand Up @@ -76,7 +77,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
}

sizes[language] += f.Size

keepLanguage[language] = struct{}{}
return nil
} else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" {
// strip off a ? if present
Expand All @@ -91,6 +92,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
}

sizes[language] += f.Size
keepLanguage[language] = struct{}{}
return nil
}
}
Expand Down Expand Up @@ -137,7 +139,9 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
for language := range sizes {
langtype := enry.GetLanguageType(language)
if langtype != enry.Programming && langtype != enry.Markup {
delete(sizes, language)
if _, keep := keepLanguage[language]; !keep {
delete(sizes, language)
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion modules/git/repo_language_stats_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
contentBuf := bytes.Buffer{}
var content []byte
sizes := make(map[string]int64)
keepLanguage := make(map[string]struct{})
for _, f := range entries {
select {
case <-repo.Ctx.Done():
Expand Down Expand Up @@ -108,6 +109,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
}

sizes[language] += f.Size()
keepLanguage[language] = struct{}{}
continue
} else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" {
// strip off a ? if present
Expand All @@ -122,6 +124,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
}

sizes[language] += f.Size()
keepLanguage[language] = struct{}{}
continue
}
}
Expand Down Expand Up @@ -189,7 +192,9 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
for language := range sizes {
langtype := enry.GetLanguageType(language)
if langtype != enry.Programming && langtype != enry.Markup {
delete(sizes, language)
if _, keep := keepLanguage[language]; !keep {
delete(sizes, language)
}
}
}
}
Expand Down