aboutsummaryrefslogtreecommitdiff
path: root/internal/route/repo/wiki.go
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-08 19:09:31 +0800
committerGitHub <noreply@github.com>2020-03-08 19:09:31 +0800
commit6437d0180b97a26319b50c2e22927dac7c94fcdd (patch)
tree3d0d097e7f498e4b970065096e7500876d365a8b /internal/route/repo/wiki.go
parentc65b5b9f84dee21dc362311b299694e8e00f6ac6 (diff)
git: migrate to github.com/gogs/git-module@v1.0.0 (#5958)
* WIP * Finish `internal/db/git_diff.go` * FInish internal/db/mirror.go * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo.go * Finish internal/db/repo_branch.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Save my work * Add license header * Compile! * Merge master * Finish internal/cmd/hook.go * Finish internal/conf/static.go * Finish internal/context/repo.go * Finish internal/db/action.go * Finish internal/db/git_diff.go * Fix submodule URL inferring * Finish internal/db/mirror.go * Updat to beta.4 * css: update fonts * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo_branch.go * Finish internal/db/wiki.go * gitutil: enhance infer submodule UR * Finish internal/route/api/v1/repo/commits.go * mirror: only collect branch commits after sync * mirror: fix tag support * Finish internal/db/repo.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Finish internal/gitutil/pull_request.go * Make it compile * Finish internal/route/repo/setting.go * Finish internal/route/repo/branch.go * Finish internal/route/api/v1/repo/file.go * Finish internal/route/repo/download.go * Finish internal/route/repo/editor.go * Use helper * Finish internal/route/repo/issue.go * Finish internal/route/repo/pull.go * Finish internal/route/repo/release.go * Finish internal/route/repo/repo.go * Finish internal/route/repo/wiki.go * Finish internal/route/repo/commit.go * Finish internal/route/repo/view.go * Finish internal/gitutil/tag.go * go.sum
Diffstat (limited to 'internal/route/repo/wiki.go')
-rw-r--r--internal/route/repo/wiki.go67
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
}