diff --git a/modules/wikis/content.go b/modules/wikis/content.go index 1962ab9dc..f182d5f12 100644 --- a/modules/wikis/content.go +++ b/modules/wikis/content.go @@ -1,7 +1,7 @@ package wikis import ( - //"code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" wiki_service "code.gitea.io/gitea/services/wiki" @@ -9,233 +9,6 @@ import ( "net/url" ) -//type ContentType string -//const ( -// // ContentTypeRegular regular content type (file) -// ContentTypeRegular ContentType = "file" -// // ContentTypeDir dir content type (dir) -// ContentTypeDir ContentType = "dir" -// // ContentLink link content type (symlink) -// ContentTypeLink ContentType = "symlink" -// // ContentTag submodule content type (submodule) -// ContentTypeSubmodule ContentType = "submodule" -//) -// -//func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { -// startTotal := time.Now() -// log.Info("Enter time:%v", startTotal.Format("2006-01-02 15:04:05.000")) -// defer func() { -// log.Info("***GetContentsOrList耗时:%v", time.Now().Sub(startTotal)) -// }() -// start := time.Now() -// if repo.IsEmpty { -// return make([]interface{}, 0), nil -// } -// if ref == "" { -// ref = repo.DefaultBranch -// } -// origRef := ref -// -// start = time.Now() -// // Check that the path given in opts.treePath is valid (not a git path) -// cleanTreePath := repofiles.CleanUploadFileName(treePath) -// if cleanTreePath == "" && treePath != "" { -// return nil, models.ErrFilenameInvalid{ -// Path: treePath, -// } -// } -// log.Info("*****************GetContentsOrList.CleanUploadFileName:%v", time.Now().Sub(start)) -// start = time.Now() -// treePath = cleanTreePath -// gitRepo, err := git.OpenRepository(repo.RepoPath()) -// if err != nil { -// return nil, err -// } -// defer gitRepo.Close() -// log.Info("*****************GetContentsOrList.OpenRepository:%v", time.Now().Sub(start)) -// start = time.Now() -// // Get the commit object for the ref -// commit, err := gitRepo.GetCommit(ref) -// if err != nil { -// return nil, err -// } -// log.Info("*****************GetContentsOrList.GetCommit:ret:%s treepath:%s", ref, treePath) -// log.Info("*****************GetContentsOrList.GetCommit:%v", time.Now().Sub(start), " ref:", ref, " treePath:", treePath) -// start = time.Now() -// entry, err := commit.GetTreeEntryByPath(treePath) -// if err != nil { -// return nil, err -// } -// log.Info("*****************GetContentsOrList.GetTreeEntryByPath:%v", time.Now().Sub(start)) -// if entry.Type() != "tree" { -// a, b := repofiles.GetContents(repo, treePath, origRef, false) -// log.Info("*****************GetContentsOrList.GetContents***:%v", time.Now().Sub(start)) -// return a, b -// } -// -// // We are in a directory, so we return a list of FileContentResponse objects -// var fileList []*api.Wiki -// start = time.Now() -// gitTree, err := commit.SubTree(treePath) -// if err != nil { -// return nil, err -// } -// log.Info("*****************GetContentsOrList.SubTree:%v", time.Now().Sub(start)) -// entries, err := gitTree.ListEntries() -// if err != nil { -// return nil, err -// } -// start = time.Now() -// //add by qiubing -// commitsInfo, _, err := entries.GetCommitsInfo(commit, treePath, nil) -// if err != nil { -// return nil, err -// } -// //end by qiubing -// start1 := time.Now() -// log.Info("****GetContentsOrList.GetCommitsInfo:%v", time.Now().Sub(start)) -// for _, e := range entries { -// subTreePath := path.Join(treePath, e.Name()) -// start2 := time.Now() -// fileContentResponse, err := GetContentsExt(gitRepo, commit, repo, subTreePath, origRef, true) -// log.Info("*****GetContentsOrList.GetContents:%s %v", e.Name(), time.Now().Sub(start2)) -// // add by qiubing -// for _, commitInfo := range commitsInfo { -// if treeEntry, ok := commitInfo[0].(*git.TreeEntry); ok { -// if treeEntry.Name() == fileContentResponse.Name { -// var entryCommit *git.Commit -// if value, ok := commitInfo[1].(*git.Commit); ok { -// entryCommit = value -// } else if value, ok := commitInfo[1].(*git.SubModuleFile); ok { -// entryCommit = value.Commit -// } -// fileContentResponse.LatestCommit = api.ContentsResponseCommi{ -// Message: entryCommit.CommitMessage, -// //LatestCommitSha: entryCommit.ID.String(), -// Created: entryCommit.Author.When.Unix(), -// } -// break -// } -// } -// } -// // end by qiubing -// -// if err != nil { -// return nil, err -// } -// fileList = append(fileList, fileContentResponse) -// } -// log.Info("*****************GetContentsOrList.for-entries:%v", time.Now().Sub(start1)) -// return fileList, nil -//} -// -//func GetContentsExt(gitRepo *git.Repository, commit *git.Commit, repo *models.Repository, treePath, ref string, forList bool) (*api.Wiki, error) { -// if ref == "" { -// ref = repo.DefaultBranch -// } -// origRef := ref -// -// // Check that the path given in opts.treePath is valid (not a git path) -// cleanTreePath := repofiles.CleanUploadFileName(treePath) -// if cleanTreePath == "" && treePath != "" { -// return nil, models.ErrFilenameInvalid{ -// Path: treePath, -// } -// } -// treePath = cleanTreePath -// commitID := commit.ID.String() -// if len(ref) >= 4 && strings.HasPrefix(commitID, ref) { -// ref = commit.ID.String() -// } -// //start1:=time.Now() -// entry, err := commit.GetTreeEntryByPath(treePath) -// if err != nil { -// return nil, err -// } -// //fmt.Println("****GetContents.commit.GetTreeEntryByPath:",treePath," ",time.Now().Sub(start1)) -// refType := gitRepo.GetRefType(ref) -// if refType == "invalid" { -// return nil, fmt.Errorf("no commit found for the ref [ref: %s]", ref) -// } -// -// selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", repo.APIURL(), treePath, origRef)) -// if err != nil { -// return nil, err -// } -// selfURLString := selfURL.String() -// -// // All content types have these fields in populated -// contentsResponse := &api.Wiki{ -// Name: entry.Name(), -// Path: treePath, -// //SHA: entry.ID.String(), -// Size: entry.Size(), -// URL: &selfURLString, -// //Links: &api.FileLinksResponse{ -// // Self: &selfURLString, -// //}, -// -// } -// -// // Now populate the rest of the ContentsResponse based on entry type -// if entry.IsRegular() || entry.IsExecutable() { -// contentsResponse.Type = string(ContentTypeRegular) -// if blobResponse, err := repofiles.GetBlobBySHA(repo, entry.ID.String()); err != nil { -// return nil, err -// } else if !forList { -// // We don't show the content if we are getting a list of FileContentResponses -// contentsResponse.Encoding = &blobResponse.Encoding -// contentsResponse.Content = &blobResponse.Content -// } -// } else if entry.IsDir() { -// contentsResponse.Type = string(ContentTypeDir) -// } else if entry.IsLink() { -// contentsResponse.Type = string(ContentTypeLink) -// // The target of a symlink file is the content of the file -// //targetFromContent, err := entry.Blob().GetBlobContent() -// //if err != nil { -// // return nil, err -// //} -// ////contentsResponse.Target = &targetFromContent -// //} else if entry.IsSubModule() { -// // contentsResponse.Type = string(ContentTypeSubmodule) -// // submodule, err := commit.GetSubModule(treePath) -// // if err != nil { -// // return nil, err -// // } -// //if submodule != nil { -// // contentsResponse.SubmoduleGitURL = &submodule.URL -// //} -// } -// // Handle links -// if entry.IsRegular() || entry.IsLink() { -// downloadURL, err := url.Parse(fmt.Sprintf("%s/raw/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) -// if err != nil { -// return nil, err -// } -// downloadURLString := downloadURL.String() -// contentsResponse.DownloadURL = &downloadURLString -// } -// if !entry.IsSubModule() { -// htmlURL, err := url.Parse(fmt.Sprintf("%s/src/%s/%s/%s", repo.HTMLURL(), refType, ref, treePath)) -// if err != nil { -// return nil, err -// } -// htmlURLString := htmlURL.String() -// contentsResponse.HTMLURL = &htmlURLString -// //contentsResponse.Links.HTMLURL = &htmlURLString -// -// gitURL, err := url.Parse(fmt.Sprintf("%s/git/blobs/%s", repo.APIURL(), entry.ID.String())) -// if err != nil { -// return nil, err -// } -// gitURLString := gitURL.String() -// contentsResponse.GitURL = &gitURLString -// //contentsResponse.Links.GitURL = &gitURLString -// } -// -// return contentsResponse, nil -//} func FindWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit, error) { wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath()) @@ -295,15 +68,3 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) []byte { } return content } - -//func (repo *models.Repository) ComposeDocumentMetas() map[string]string { -// if len(repo.DocumentRenderingMetas) == 0 { -// metas := map[string]string{} -// for k, v := range repo.ComposeMetas() { -// metas[k] = v -// } -// metas["mode"] = "document" -// repo.DocumentRenderingMetas = metas -// } -// return repo.DocumentRenderingMetas -//} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 47a4dd8a5..3c73f29e1 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -654,8 +654,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID) - //reqRepoWikiWriter := context.RequireRepoWriter(models.UnitTypeWiki) - // + m.Group("/repos", func() { m.Get("/search", repo.Search) @@ -708,10 +707,6 @@ func RegisterRoutes(m *macaron.Macaron) { Get(reqToken(), notify.ListRepoNotifications). Put(reqToken(), notify.ReadRepoNotifications) m.Group("/wiki", func() { - //m.Get("/*", repo.CreateNewWiki) - //m.Group("/:id",func(){ - // m.Get("/wiki", repo.ListWiki) - //}) m.Group("/content", func() { m.Get("/?:page",repo.WikiContent) }) diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index de3b9c69a..a5ae81b9b 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -8,7 +8,6 @@ import ( "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/wikis" wiki_service "code.gitea.io/gitea/services/wiki" - "fmt" //"fmt" //"golang.org/x/sys/windows" "net/http" @@ -61,9 +60,6 @@ func WikiPages(ctx *context.APIContext) { wikiRepo, commit, err := wikis.FindWikiRepoCommit(ctx) - fmt.Println("wikirepo = ",wikiRepo) - fmt.Println("commit = ", commit) - fmt.Println("err = ", err) entries, err := commit.ListEntries() if err != nil {