Skip to content

Commit 23853f9

Browse files
committed
Refactor to use TryGetContentLanguage instead of dealing with linguist seperatly
1 parent fb7e9a3 commit 23853f9

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

services/markup/processorhelper.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/gitea/modules/log"
2020
"code.gitea.io/gitea/modules/markup"
2121
"code.gitea.io/gitea/modules/translation"
22+
file_service "code.gitea.io/gitea/services/repository/files"
2223
)
2324

2425
func ProcessorHelper() *markup.ProcessorHelper {
@@ -70,29 +71,9 @@ func ProcessorHelper() *markup.ProcessorHelper {
7071
return nil, err
7172
}
7273

73-
language := ""
74-
indexFilename, worktree, deleteTemporaryFile, err := gitRepo.ReadTreeToTemporaryIndex(commitSha)
75-
if err == nil {
76-
defer deleteTemporaryFile()
77-
78-
filename2attribute2info, err := gitRepo.CheckAttribute(git.CheckAttributeOpts{
79-
CachedOnly: true,
80-
Attributes: []string{"linguist-language", "gitlab-language"},
81-
Filenames: []string{filePath},
82-
IndexFile: indexFilename,
83-
WorkTree: worktree,
84-
})
85-
if err != nil {
86-
log.Error("Unable to load attributes for %-v:%s. Error: %v", repo, filePath, err)
87-
}
88-
89-
language = filename2attribute2info[filePath]["linguist-language"]
90-
if language == "" || language == "unspecified" {
91-
language = filename2attribute2info[filePath]["gitlab-language"]
92-
}
93-
if language == "unspecified" {
94-
language = ""
95-
}
74+
language, err := file_service.TryGetContentLanguage(gitRepo, commitSha, filePath)
75+
if err != nil {
76+
log.Error("Unable to get file language for %-v:%s. Error: %v", repo, filePath, err)
9677
}
9778

9879
blob, err := commit.GetBlobByPath(filePath)

0 commit comments

Comments
 (0)