fixed 当目录中有子模块子代码且找不到commitid的情况下报错处理

(cherry picked from commit de2fd01271)
This commit is contained in:
xxq250 2023-10-12 10:24:45 +08:00
parent b2624f6562
commit b1142b9b68
2 changed files with 18 additions and 15 deletions

View File

@ -137,12 +137,12 @@ func GetReadmeContents(ctx *context.APIContext) {
readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"} readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"}
readmePath := "" readmePath := ""
readmePathInArrIndex := 0 readmePathInArrIndex := 0
filesListInterface, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref) filesListInterface, err := hat_files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref)
if err != nil { if err != nil {
ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err)
return return
} }
filesList, ok := filesListInterface.([]*api.ContentsResponse) filesList, ok := filesListInterface.([]*hat_api.ContentsResponse)
if ok { if ok {
for _, file := range filesList { for _, file := range filesList {
for i, sortItem := range readmeSortArr { for i, sortItem := range readmeSortArr {

View File

@ -134,21 +134,24 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
if err != nil { if err != nil {
return nil, err return nil, err
} }
var isTextFile = false
blob, err := gitRepo.GetBlob(entry.ID.String()) if !entry.IsSubModule() {
if err != nil { blob, err := gitRepo.GetBlob(entry.ID.String())
return nil, err if err != nil {
} return nil, err
dataRc, err := blob.DataAsync() }
if err != nil { dataRc, err := blob.DataAsync()
return nil, err if err != nil {
} return nil, err
buf := make([]byte, 1024) }
n, _ := util.ReadAtMost(dataRc, buf) buf := make([]byte, 1024)
buf = buf[:n] n, _ := util.ReadAtMost(dataRc, buf)
buf = buf[:n]
st := typesniffer.DetectContentType(buf) st := typesniffer.DetectContentType(buf)
isTextFile := st.IsText() isTextFile = st.IsText()
}
contentsResponse := &hat_api.ContentsResponse{ contentsResponse := &hat_api.ContentsResponse{
ContentsResponse: &gitea_api.ContentsResponse{ ContentsResponse: &gitea_api.ContentsResponse{