diff options
Diffstat (limited to 'internal/route/repo/wiki.go')
-rw-r--r-- | internal/route/repo/wiki.go | 67 |
1 files changed, 31 insertions, 36 deletions
diff --git a/internal/route/repo/wiki.go b/internal/route/repo/wiki.go index 8a48c319..91bc3c91 100644 --- a/internal/route/repo/wiki.go +++ b/internal/route/repo/wiki.go @@ -5,7 +5,6 @@ package repo import ( - "io/ioutil" "strings" "time" @@ -14,6 +13,7 @@ import ( "gogs.io/gogs/internal/context" "gogs.io/gogs/internal/db" "gogs.io/gogs/internal/form" + "gogs.io/gogs/internal/gitutil" "gogs.io/gogs/internal/markup" ) @@ -43,27 +43,27 @@ type PageMeta struct { } func renderWikiPage(c *context.Context, isViewPage bool) (*git.Repository, string) { - wikiRepo, err := git.OpenRepository(c.Repo.Repository.WikiPath()) + wikiRepo, err := git.Open(c.Repo.Repository.WikiPath()) if err != nil { - c.Handle(500, "OpenRepository", err) + c.ServerError("open repository", err) return nil, "" } - commit, err := wikiRepo.GetBranchCommit("master") + commit, err := wikiRepo.BranchCommit("master") if err != nil { - c.Handle(500, "GetBranchCommit", err) + c.ServerError("get branch commit", err) return nil, "" } // Get page list. if isViewPage { - entries, err := commit.ListEntries() + entries, err := commit.Entries() if err != nil { - c.Handle(500, "ListEntries", err) + c.ServerError("list entries", err) return nil, "" } pages := make([]PageMeta, 0, len(entries)) for i := range entries { - if entries[i].Type == git.OBJECT_BLOB && strings.HasSuffix(entries[i].Name(), ".md") { + if entries[i].Type() == git.ObjectBlob && strings.HasSuffix(entries[i].Name(), ".md") { name := strings.TrimSuffix(entries[i].Name(), ".md") pages = append(pages, PageMeta{ Name: name, @@ -86,29 +86,24 @@ func renderWikiPage(c *context.Context, isViewPage bool) (*git.Repository, strin c.Data["title"] = pageName c.Data["RequireHighlightJS"] = true - blob, err := commit.GetBlobByPath(pageName + ".md") + blob, err := commit.Blob(pageName + ".md") if err != nil { - if git.IsErrNotExist(err) { + if gitutil.IsErrRevisionNotExist(err) { c.Redirect(c.Repo.RepoLink + "/wiki/_pages") } else { - c.Handle(500, "GetBlobByPath", err) + c.ServerError("GetBlobByPath", err) } return nil, "" } - r, err := blob.Data() + p, err := blob.Bytes() if err != nil { - c.Handle(500, "Data", err) - return nil, "" - } - data, err := ioutil.ReadAll(r) - if err != nil { - c.Handle(500, "ReadAll", err) + c.ServerError("Data", err) return nil, "" } if isViewPage { - c.Data["content"] = string(markup.Markdown(data, c.Repo.RepoLink, c.Repo.Repository.ComposeMetas())) + c.Data["content"] = string(markup.Markdown(p, c.Repo.RepoLink, c.Repo.Repository.ComposeMetas())) } else { - c.Data["content"] = string(data) + c.Data["content"] = string(p) } return wikiRepo, pageName @@ -129,12 +124,12 @@ func Wiki(c *context.Context) { } // Get last change information. - lastCommit, err := wikiRepo.GetCommitByPath(pageName + ".md") + commits, err := wikiRepo.Log(git.RefsHeads+"master", git.LogOptions{Path: pageName + ".md"}) if err != nil { - c.Handle(500, "GetCommitByPath", err) + c.ServerError("get commits by path", err) return } - c.Data["Author"] = lastCommit.Author + c.Data["Author"] = commits[0].Author c.HTML(200, WIKI_VIEW) } @@ -148,35 +143,35 @@ func WikiPages(c *context.Context) { return } - wikiRepo, err := git.OpenRepository(c.Repo.Repository.WikiPath()) + wikiRepo, err := git.Open(c.Repo.Repository.WikiPath()) if err != nil { - c.Handle(500, "OpenRepository", err) + c.ServerError("open repository", err) return } - commit, err := wikiRepo.GetBranchCommit("master") + commit, err := wikiRepo.BranchCommit("master") if err != nil { - c.Handle(500, "GetBranchCommit", err) + c.ServerError("get branch commit", err) return } - entries, err := commit.ListEntries() + entries, err := commit.Entries() if err != nil { - c.Handle(500, "ListEntries", err) + c.ServerError("list entries", err) return } pages := make([]PageMeta, 0, len(entries)) for i := range entries { - if entries[i].Type == git.OBJECT_BLOB && strings.HasSuffix(entries[i].Name(), ".md") { - commit, err := wikiRepo.GetCommitByPath(entries[i].Name()) + if entries[i].Type() == git.ObjectBlob && strings.HasSuffix(entries[i].Name(), ".md") { + commits, err := wikiRepo.Log(git.RefsHeads+"master", git.LogOptions{Path: entries[i].Name()}) if err != nil { - c.ServerError("GetCommitByPath", err) + c.ServerError("get commits by path", err) return } name := strings.TrimSuffix(entries[i].Name(), ".md") pages = append(pages, PageMeta{ Name: name, URL: db.ToWikiPageURL(name), - Updated: commit.Author.When, + Updated: commits[0].Author.When, }) } } @@ -212,7 +207,7 @@ func NewWikiPost(c *context.Context, f form.NewWiki) { c.Data["Err_Title"] = true c.RenderWithErr(c.Tr("repo.wiki.page_already_exists"), WIKI_NEW, &f) } else { - c.Handle(500, "AddWikiPage", err) + c.ServerError("AddWikiPage", err) } return } @@ -249,7 +244,7 @@ func EditWikiPost(c *context.Context, f form.NewWiki) { } if err := c.Repo.Repository.EditWikiPage(c.User, f.OldTitle, f.Title, f.Content, f.Message); err != nil { - c.Handle(500, "EditWikiPage", err) + c.ServerError("EditWikiPage", err) return } @@ -264,7 +259,7 @@ func DeleteWikiPagePost(c *context.Context) { pageName := db.ToWikiPageName(pageURL) if err := c.Repo.Repository.DeleteWikiPage(c.User, pageName); err != nil { - c.Handle(500, "DeleteWikiPage", err) + c.ServerError("DeleteWikiPage", err) return } |