1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

move out git module and #1573 send push hook

This commit is contained in:
Unknwon
2015-12-09 20:46:05 -05:00
parent bd5dc626e8
commit 9a2e43bff2
45 changed files with 185 additions and 2002 deletions

View File

@@ -5,8 +5,9 @@
package repo
import (
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/routers/repo"
)
@@ -20,7 +21,7 @@ func GetRawFile(ctx *middleware.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
if err != nil {
if err == git.ErrNotExist {
if git.IsErrNotExist(err) {
ctx.Error(404)
} else {
ctx.APIError(500, "GetBlobByPath", err)

View File

@@ -10,9 +10,10 @@ import (
"github.com/Unknwon/paginater"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
@@ -55,7 +56,7 @@ func Commits(ctx *middleware.Context) {
if page <= 1 {
page = 1
}
ctx.Data["Page"] = paginater.New(commitsCount, git.CommitsRangeSize, page, 5)
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
// Both `git log branchName` and `git log commitId` work.
commits, err := ctx.Repo.Commit.CommitsByRange(page)
@@ -123,7 +124,7 @@ func FileHistory(ctx *middleware.Context) {
if page <= 1 {
page = 1
}
ctx.Data["Page"] = paginater.New(commitsCount, git.CommitsRangeSize, page, 5)
ctx.Data["Page"] = paginater.New(int(commitsCount), git.CommitsRangeSize, page, 5)
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
if err != nil {
@@ -159,7 +160,7 @@ func Diff(ctx *middleware.Context) {
parents := make([]string, commit.ParentCount())
for i := 0; i < commit.ParentCount(); i++ {
sha, err := commit.ParentId(i)
sha, err := commit.ParentID(i)
parents[i] = sha.String()
if err != nil {
ctx.Handle(404, "repo.Diff", err)

View File

@@ -8,8 +8,9 @@ import (
"io"
"path"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/middleware"
)
@@ -21,7 +22,7 @@ func ServeData(ctx *middleware.Context, name string, reader io.Reader) error {
}
_, isTextFile := base.IsTextFile(buf)
if ! isTextFile {
if !isTextFile {
_, isImageFile := base.IsImageFile(buf)
if !isImageFile {
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
@@ -45,7 +46,7 @@ func ServeBlob(ctx *middleware.Context, blob *git.Blob) error {
func SingleDownload(ctx *middleware.Context) {
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
if err != nil {
if err == git.ErrNotExist {
if git.IsErrNotExist(err) {
ctx.Handle(404, "GetBlobByPath", nil)
} else {
ctx.Handle(500, "GetBlobByPath", err)

View File

@@ -12,10 +12,11 @@ import (
"github.com/Unknwon/com"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
@@ -328,9 +329,9 @@ func ViewPullFiles(ctx *middleware.Context) {
return
}
headCommitID, err := headGitRepo.GetCommitIdOfBranch(pull.HeadBranch)
headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
if err != nil {
ctx.Handle(500, "GetCommitIdOfBranch", err)
ctx.Handle(500, "GetBranchCommitID", err)
return
}
@@ -492,9 +493,9 @@ func PrepareCompareDiff(
// Get diff information.
ctx.Data["CommitRepoLink"] = headRepo.RepoLink()
headCommitID, err := headGitRepo.GetCommitIdOfBranch(headBranch)
headCommitID, err := headGitRepo.GetBranchCommitID(headBranch)
if err != nil {
ctx.Handle(500, "GetCommitIdOfBranch", err)
ctx.Handle(500, "GetBranchCommitID", err)
return false
}
ctx.Data["AfterCommitID"] = headCommitID

View File

@@ -34,7 +34,7 @@ func Releases(ctx *middleware.Context) {
}
// Temproray cache commits count of used branches to speed up.
countCache := make(map[string]int)
countCache := make(map[string]int64)
tags := make([]*models.Release, len(rawTags))
for i, rawTag := range rawTags {
@@ -45,7 +45,7 @@ func Releases(ctx *middleware.Context) {
if rel.TagName == rawTag {
rel.Publisher, err = models.GetUserByID(rel.PublisherID)
if err != nil {
ctx.Handle(500, "GetUserById", err)
ctx.Handle(500, "GetUserByID", err)
return
}
// FIXME: duplicated code.
@@ -53,14 +53,14 @@ func Releases(ctx *middleware.Context) {
if ctx.Repo.BranchName != rel.Target {
// Get count if not exists.
if _, ok := countCache[rel.Target]; !ok {
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(ctx.Repo.BranchName)
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
if err != nil {
ctx.Handle(500, "GetCommitOfBranch", err)
ctx.Handle(500, "GetBranchCommit", err)
return
}
countCache[ctx.Repo.BranchName], err = commit.CommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount2", err)
ctx.Handle(500, "CommitsCount", err)
return
}
}
@@ -77,9 +77,9 @@ func Releases(ctx *middleware.Context) {
}
if tags[i] == nil {
commit, err := ctx.Repo.GitRepo.GetCommitOfTag(rawTag)
commit, err := ctx.Repo.GitRepo.GetTagCommit(rawTag)
if err != nil {
ctx.Handle(500, "GetCommitOfTag2", err)
ctx.Handle(500, "GetTagCommit", err)
return
}
@@ -89,7 +89,7 @@ func Releases(ctx *middleware.Context) {
Sha1: commit.ID.String(),
}
tags[i].NumCommits, err = ctx.Repo.GitRepo.CommitsCount(commit.ID.String())
tags[i].NumCommits, err = commit.CommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount", err)
return
@@ -105,7 +105,7 @@ func Releases(ctx *middleware.Context) {
rel.Publisher, err = models.GetUserByID(rel.PublisherID)
if err != nil {
ctx.Handle(500, "GetUserById", err)
ctx.Handle(500, "GetUserByID", err)
return
}
// FIXME: duplicated code.
@@ -113,14 +113,14 @@ func Releases(ctx *middleware.Context) {
if ctx.Repo.BranchName != rel.Target {
// Get count if not exists.
if _, ok := countCache[rel.Target]; !ok {
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(ctx.Repo.BranchName)
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.BranchName)
if err != nil {
ctx.Handle(500, "GetCommitOfBranch", err)
ctx.Handle(500, "GetBranchCommit", err)
return
}
countCache[ctx.Repo.BranchName], err = commit.CommitsCount()
if err != nil {
ctx.Handle(500, "CommitsCount2", err)
ctx.Handle(500, "CommitsCount", err)
return
}
}
@@ -158,9 +158,9 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
return
}
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(form.Target)
commit, err := ctx.Repo.GitRepo.GetBranchCommit(form.Target)
if err != nil {
ctx.Handle(500, "GetCommitOfBranch", err)
ctx.Handle(500, "GetBranchCommit", err)
return
}

View File

@@ -12,10 +12,11 @@ import (
"github.com/Unknwon/com"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
@@ -294,21 +295,21 @@ func Download(ctx *middleware.Context) {
)
gitRepo := ctx.Repo.GitRepo
if gitRepo.IsBranchExist(refName) {
commit, err = gitRepo.GetCommitOfBranch(refName)
commit, err = gitRepo.GetBranchCommit(refName)
if err != nil {
ctx.Handle(500, "Download", err)
ctx.Handle(500, "GetBranchCommit", err)
return
}
} else if gitRepo.IsTagExist(refName) {
commit, err = gitRepo.GetCommitOfTag(refName)
commit, err = gitRepo.GetTagCommit(refName)
if err != nil {
ctx.Handle(500, "Download", err)
ctx.Handle(500, "GetTagCommit", err)
return
}
} else if len(refName) == 40 {
commit, err = gitRepo.GetCommit(refName)
if err != nil {
ctx.Handle(404, "Download", nil)
ctx.Handle(404, "GetCommit", nil)
return
}
} else {

View File

@@ -8,10 +8,11 @@ import (
"strings"
"time"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"

View File

@@ -13,9 +13,10 @@ import (
"github.com/Unknwon/paginater"
"github.com/gogits/git-shell"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/template"
@@ -59,7 +60,7 @@ func Home(ctx *middleware.Context) {
}
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename)
if err != nil && err != git.ErrNotExist {
if err != nil && git.IsErrNotExist(err) {
ctx.Handle(404, "GetTreeEntryByPath", err)
return
}
@@ -126,7 +127,7 @@ func Home(ctx *middleware.Context) {
return
}
entries, err := tree.ListEntries(treename)
entries, err := tree.ListEntries()
if err != nil {
ctx.Handle(500, "ListEntries", err)
return
@@ -135,10 +136,10 @@ func Home(ctx *middleware.Context) {
files := make([][]interface{}, 0, len(entries))
for _, te := range entries {
if te.Type != git.COMMIT {
c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name()))
if te.Type != git.OBJECT_COMMIT {
c, err := ctx.Repo.Commit.GetCommitByPath(filepath.Join(treePath, te.Name()))
if err != nil {
ctx.Handle(500, "GetCommitOfRelPath", err)
ctx.Handle(500, "GetCommitByPath", err)
return
}
files = append(files, []interface{}{te, c})
@@ -153,9 +154,9 @@ func Home(ctx *middleware.Context) {
smUrl = sm.Url
}
c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name()))
c, err := ctx.Repo.Commit.GetCommitByPath(filepath.Join(treePath, te.Name()))
if err != nil {
ctx.Handle(500, "GetCommitOfRelPath", err)
ctx.Handle(500, "GetCommitByPath", err)
return
}
files = append(files, []interface{}{te, git.NewSubModuleFile(c, smUrl, te.ID.String())})
@@ -209,9 +210,9 @@ func Home(ctx *middleware.Context) {
lastCommit := ctx.Repo.Commit
if len(treePath) > 0 {
c, err := ctx.Repo.Commit.GetCommitOfRelPath(treePath)
c, err := ctx.Repo.Commit.GetCommitByPath(treePath)
if err != nil {
ctx.Handle(500, "GetCommitOfRelPath", err)
ctx.Handle(500, "GetCommitByPath", err)
return
}
lastCommit = c

View File

@@ -42,9 +42,9 @@ func renderWikiPage(ctx *middleware.Context, isViewPage bool) (*git.Repository,
ctx.Handle(500, "OpenRepository", err)
return nil, ""
}
commit, err := wikiRepo.GetCommitOfBranch("master")
commit, err := wikiRepo.GetBranchCommit("master")
if err != nil {
ctx.Handle(500, "GetCommitOfBranch", err)
ctx.Handle(500, "GetBranchCommit", err)
return nil, ""
}
@@ -147,9 +147,9 @@ func WikiPages(ctx *middleware.Context) {
ctx.Handle(500, "OpenRepository", err)
return
}
commit, err := wikiRepo.GetCommitOfBranch("master")
commit, err := wikiRepo.GetBranchCommit("master")
if err != nil {
ctx.Handle(500, "GetCommitOfBranch", err)
ctx.Handle(500, "GetBranchCommit", err)
return
}