You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_language_stats.go 1013B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package git
  4. import (
  5. "strings"
  6. "unicode"
  7. )
  8. const (
  9. fileSizeLimit int64 = 16 * 1024 // 16 KiB
  10. bigFileSize int64 = 1024 * 1024 // 1 MiB
  11. )
  12. // mergeLanguageStats mergers language names with different cases. The name with most upper case letters is used.
  13. func mergeLanguageStats(stats map[string]int64) map[string]int64 {
  14. names := map[string]struct {
  15. uniqueName string
  16. upperCount int
  17. }{}
  18. countUpper := func(s string) (count int) {
  19. for _, r := range s {
  20. if unicode.IsUpper(r) {
  21. count++
  22. }
  23. }
  24. return count
  25. }
  26. for name := range stats {
  27. cnt := countUpper(name)
  28. lower := strings.ToLower(name)
  29. if cnt >= names[lower].upperCount {
  30. names[lower] = struct {
  31. uniqueName string
  32. upperCount int
  33. }{uniqueName: name, upperCount: cnt}
  34. }
  35. }
  36. res := make(map[string]int64, len(names))
  37. for name, num := range stats {
  38. res[names[strings.ToLower(name)].uniqueName] += num
  39. }
  40. return res
  41. }