Skip to content

Commit d57c755

Browse files
committed
Merge branch 'master' into fix_star_num
2 parents 9c1e588 + 6891b90 commit d57c755

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

modules/git/repo_language_stats.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,8 @@ import (
1717
"github.com/go-git/go-git/v5/plumbing/object"
1818
)
1919

20-
const fileSizeLimit int64 = 16 * 1024 * 1024
21-
22-
// specialLanguages defines list of languages that are excluded from the calculation
23-
// unless they are the only language present in repository. Only languages which under
24-
// normal circumstances are not considered to be code should be listed here.
25-
var specialLanguages = []string{
26-
"XML",
27-
"JSON",
28-
"TOML",
29-
"YAML",
30-
"INI",
31-
"SVG",
32-
"Text",
33-
"Markdown",
34-
}
20+
const fileSizeLimit int64 = 16 * 1024 // 16 KiB
21+
const bigFileSize int64 = 1024 * 1024 // 1 MiB
3522

3623
// GetLanguageStats calculates language stats for git repository at specified commit
3724
func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, error) {
@@ -62,8 +49,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
6249
return nil
6350
}
6451

65-
// If content can not be read just do detection by filename
66-
content, _ := readFile(f, fileSizeLimit)
52+
// If content can not be read or file is too big just do detection by filename
53+
var content []byte
54+
if f.Size <= bigFileSize {
55+
content, _ = readFile(f, fileSizeLimit)
56+
}
6757
if enry.IsGenerated(f.Name, content) {
6858
return nil
6959
}
@@ -91,8 +81,11 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
9181

9282
// filter special languages unless they are the only language
9383
if len(sizes) > 1 {
94-
for _, language := range specialLanguages {
95-
delete(sizes, language)
84+
for language := range sizes {
85+
langtype := enry.GetLanguageType(language)
86+
if langtype != enry.Programming && langtype != enry.Markup {
87+
delete(sizes, language)
88+
}
9689
}
9790
}
9891

modules/repofiles/action.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"fmt"
1010
"html"
11+
"strings"
1112

1213
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/git"
@@ -111,7 +112,7 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
111112
continue
112113
}
113114

114-
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(c.Message))
115+
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, html.EscapeString(strings.SplitN(c.Message, "\n", 2)[0]))
115116
if err = models.CreateRefComment(doer, refRepo, refIssue, message, c.Sha1); err != nil {
116117
return err
117118
}

templates/user/dashboard/feeds.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
{{ $repoLink := .GetRepoLink}}
8080
{{if $push.Commits}}
8181
{{range $push.Commits}}
82-
<li><img class="img-8" src="{{$push.AvatarLink .AuthorEmail}}"> <a class="commit-id" href="{{$repoLink}}/commit/{{.Sha1}}">{{ShortSha .Sha1}}</a> <span class="text truncate light grey">{{.Message}}</span></li>
82+
{{ $commitLink := printf "%s/commit/%s" $repoLink .Sha1}}
83+
<li><img class="img-8" src="{{$push.AvatarLink .AuthorEmail}}"> <a class="commit-id" href="{{$commitLink}}">{{ShortSha .Sha1}}</a> <span class="text truncate light grey">{{RenderCommitMessage .Message $repoLink $.ComposeMetas}}</span></li>
8384
{{end}}
8485
{{end}}
8586
{{if and (gt $push.Len 1) $push.CompareURL}}<li><a href="{{AppSubUrl}}/{{$push.CompareURL}}">{{$.i18n.Tr "action.compare_commits" $push.Len}} »</a></li>{{end}}

0 commit comments

Comments
 (0)