mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 23:53:52 +03:00
parent
4e7eb5be9d
commit
23eec25274
14 changed files with 304 additions and 164 deletions
20
cmd/web.go
20
cmd/web.go
|
@ -370,7 +370,7 @@ func runWeb(*cli.Context) {
|
||||||
m.Group("/:username/:reponame", func() {
|
m.Group("/:username/:reponame", func() {
|
||||||
m.Post("/releases/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
|
m.Post("/releases/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
|
||||||
m.Post("/releases/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
|
m.Post("/releases/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
|
||||||
}, reqSignIn, middleware.RepoAssignment(true, true))
|
}, reqSignIn, middleware.RepoAssignment(true))
|
||||||
|
|
||||||
m.Group("/:username/:reponame", func() {
|
m.Group("/:username/:reponame", func() {
|
||||||
m.Get("/issues", repo.Issues)
|
m.Get("/issues", repo.Issues)
|
||||||
|
@ -382,20 +382,18 @@ func runWeb(*cli.Context) {
|
||||||
}, ignSignIn, middleware.RepoAssignment(true))
|
}, ignSignIn, middleware.RepoAssignment(true))
|
||||||
|
|
||||||
m.Group("/:username/:reponame", func() {
|
m.Group("/:username/:reponame", func() {
|
||||||
m.Get("/src/:branchname", repo.Home)
|
m.Group("", func() {
|
||||||
m.Get("/src/:branchname/*", repo.Home)
|
m.Get("/src/*", repo.Home)
|
||||||
m.Get("/raw/:branchname/*", repo.SingleDownload)
|
m.Get("/raw/*", repo.SingleDownload)
|
||||||
m.Get("/commits/:branchname", repo.Commits)
|
m.Get("/commits/*", repo.RefCommits)
|
||||||
m.Get("/commits/:branchname/search", repo.SearchCommits)
|
m.Get("/commit/*", repo.Diff)
|
||||||
m.Get("/commits/:branchname/*", repo.FileHistory)
|
}, middleware.RepoRef())
|
||||||
m.Get("/commit/:branchname", repo.Diff)
|
|
||||||
m.Get("/commit/:branchname/*", repo.Diff)
|
|
||||||
m.Get("/releases", repo.Releases)
|
m.Get("/releases", repo.Releases)
|
||||||
m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff)
|
m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff)
|
||||||
}, ignSignIn, middleware.RepoAssignment(true, true))
|
}, ignSignIn, middleware.RepoAssignment(true))
|
||||||
|
|
||||||
m.Group("/:username", func() {
|
m.Group("/:username", func() {
|
||||||
m.Get("/:reponame", ignSignIn, middleware.RepoAssignment(true, true, true), repo.Home)
|
m.Get("/:reponame", ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef(), repo.Home)
|
||||||
m.Any("/:reponame/*", ignSignInAndCsrf, repo.Http)
|
m.Any("/:reponame/*", ignSignInAndCsrf, repo.Http)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -168,6 +168,8 @@ org_still_own_repo = This organization still have ownership of repository, you h
|
||||||
|
|
||||||
still_own_user = This authentication still has used by some users, you should move them and then delete again.
|
still_own_user = This authentication still has used by some users, you should move them and then delete again.
|
||||||
|
|
||||||
|
target_branch_not_exist = Target branch does not exist
|
||||||
|
|
||||||
[user]
|
[user]
|
||||||
change_avatar = Change your avatar at gravatar.com
|
change_avatar = Change your avatar at gravatar.com
|
||||||
join_on = Joined on
|
join_on = Joined on
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.5.7.1105 Beta"
|
const APP_VER = "0.5.7.1106 Beta"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -53,6 +53,7 @@ type Context struct {
|
||||||
GitRepo *git.Repository
|
GitRepo *git.Repository
|
||||||
BranchName string
|
BranchName string
|
||||||
TagName string
|
TagName string
|
||||||
|
TreeName string
|
||||||
CommitId string
|
CommitId string
|
||||||
RepoLink string
|
RepoLink string
|
||||||
CloneLink struct {
|
CloneLink struct {
|
||||||
|
@ -176,7 +177,10 @@ func Contexter() macaron.Handler {
|
||||||
ctx.IsSigned = true
|
ctx.IsSigned = true
|
||||||
ctx.Data["IsSigned"] = ctx.IsSigned
|
ctx.Data["IsSigned"] = ctx.IsSigned
|
||||||
ctx.Data["SignedUser"] = ctx.User
|
ctx.Data["SignedUser"] = ctx.User
|
||||||
|
ctx.Data["SignedUserName"] = ctx.User.Name
|
||||||
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
|
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
|
||||||
|
} else {
|
||||||
|
ctx.Data["SignedUserName"] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
|
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
|
||||||
|
|
|
@ -18,17 +18,110 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RepoRef handles repository reference name including those contain `/`.
|
||||||
|
func RepoRef() macaron.Handler {
|
||||||
|
return func(ctx *Context) {
|
||||||
|
var (
|
||||||
|
refName string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get default branch.
|
||||||
|
if len(ctx.Params("*")) == 0 {
|
||||||
|
refName = ctx.Repo.Repository.DefaultBranch
|
||||||
|
if !ctx.Repo.GitRepo.IsBranchExist(refName) {
|
||||||
|
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetBranches", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refName = brs[0]
|
||||||
|
}
|
||||||
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfBranch(refName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
ctx.Repo.IsBranch = true
|
||||||
|
ctx.Repo.BranchName = refName
|
||||||
|
|
||||||
|
} else {
|
||||||
|
hasMatched := false
|
||||||
|
parts := strings.Split(ctx.Params("*"), "/")
|
||||||
|
for i, part := range parts {
|
||||||
|
refName = strings.TrimPrefix(refName+"/"+part, "/")
|
||||||
|
|
||||||
|
if ctx.Repo.GitRepo.IsBranchExist(refName) ||
|
||||||
|
ctx.Repo.GitRepo.IsTagExist(refName) {
|
||||||
|
if i < len(parts)-1 {
|
||||||
|
ctx.Repo.TreeName = strings.Join(parts[i+1:], "/")
|
||||||
|
}
|
||||||
|
hasMatched = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasMatched && len(parts[0]) == 40 {
|
||||||
|
refName = parts[0]
|
||||||
|
ctx.Repo.TreeName = strings.Join(parts[1:], "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Repo.GitRepo.IsBranchExist(refName) {
|
||||||
|
ctx.Repo.IsBranch = true
|
||||||
|
|
||||||
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfBranch(refName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
|
||||||
|
} else if ctx.Repo.GitRepo.IsTagExist(refName) {
|
||||||
|
ctx.Repo.IsTag = true
|
||||||
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetCommitOfTag", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
} else if len(refName) == 40 {
|
||||||
|
ctx.Repo.IsCommit = true
|
||||||
|
ctx.Repo.CommitId = refName
|
||||||
|
|
||||||
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(404, "GetCommit", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Handle(404, "RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Repo.BranchName = refName
|
||||||
|
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||||
|
ctx.Data["CommitId"] = ctx.Repo.CommitId
|
||||||
|
ctx.Data["IsBranch"] = ctx.Repo.IsBranch
|
||||||
|
ctx.Data["IsTag"] = ctx.Repo.IsTag
|
||||||
|
ctx.Data["IsCommit"] = ctx.Repo.IsCommit
|
||||||
|
|
||||||
|
ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "CommitsCount", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
var (
|
var (
|
||||||
validBranch bool // To valid brach name.
|
|
||||||
displayBare bool // To display bare page if it is a bare repo.
|
displayBare bool // To display bare page if it is a bare repo.
|
||||||
)
|
)
|
||||||
if len(args) >= 1 {
|
if len(args) >= 1 {
|
||||||
validBranch = args[0]
|
displayBare = args[0]
|
||||||
}
|
|
||||||
if len(args) >= 2 {
|
|
||||||
displayBare = args[1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -201,71 +294,71 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// when repo is bare, not valid branch
|
// when repo is bare, not valid branch
|
||||||
if !ctx.Repo.Repository.IsBare && validBranch {
|
// if !ctx.Repo.Repository.IsBare && validBranch {
|
||||||
detect:
|
// detect:
|
||||||
if len(refName) > 0 {
|
// if len(refName) > 0 {
|
||||||
if gitRepo.IsBranchExist(refName) {
|
// if gitRepo.IsBranchExist(refName) {
|
||||||
ctx.Repo.IsBranch = true
|
// ctx.Repo.IsBranch = true
|
||||||
ctx.Repo.BranchName = refName
|
// ctx.Repo.BranchName = refName
|
||||||
|
|
||||||
ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName)
|
// ctx.Repo.Commit, err = gitRepo.GetCommitOfBranch(refName)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Handle(500, "RepoAssignment invalid branch", err)
|
// ctx.Handle(500, "RepoAssignment invalid branch", err)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
// ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
|
|
||||||
} else if gitRepo.IsTagExist(refName) {
|
// } else if gitRepo.IsTagExist(refName) {
|
||||||
ctx.Repo.IsTag = true
|
// ctx.Repo.IsTag = true
|
||||||
ctx.Repo.BranchName = refName
|
// ctx.Repo.BranchName = refName
|
||||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName)
|
// ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Handle(500, "Fail to get tag commit", err)
|
// ctx.Handle(500, "Fail to get tag commit", err)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
// ctx.Repo.CommitId = ctx.Repo.Commit.Id.String()
|
||||||
} else if len(refName) == 40 {
|
// } else if len(refName) == 40 {
|
||||||
ctx.Repo.IsCommit = true
|
// ctx.Repo.IsCommit = true
|
||||||
ctx.Repo.CommitId = refName
|
// ctx.Repo.CommitId = refName
|
||||||
ctx.Repo.BranchName = refName
|
// ctx.Repo.BranchName = refName
|
||||||
|
|
||||||
ctx.Repo.Commit, err = gitRepo.GetCommit(refName)
|
// ctx.Repo.Commit, err = gitRepo.GetCommit(refName)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Handle(404, "RepoAssignment invalid commit", nil)
|
// ctx.Handle(404, "RepoAssignment invalid commit", nil)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
ctx.Handle(404, "RepoAssignment invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
|
// ctx.Handle(404, "RepoAssignment invalid repo", fmt.Errorf("branch or tag not exist: %s", refName))
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
} else {
|
// } else {
|
||||||
if len(refName) == 0 {
|
// if len(refName) == 0 {
|
||||||
if gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
|
// if gitRepo.IsBranchExist(ctx.Repo.Repository.DefaultBranch) {
|
||||||
refName = ctx.Repo.Repository.DefaultBranch
|
// refName = ctx.Repo.Repository.DefaultBranch
|
||||||
} else {
|
// } else {
|
||||||
brs, err := gitRepo.GetBranches()
|
// brs, err := gitRepo.GetBranches()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Handle(500, "GetBranches", err)
|
// ctx.Handle(500, "GetBranches", err)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
refName = brs[0]
|
// refName = brs[0]
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
goto detect
|
// goto detect
|
||||||
}
|
// }
|
||||||
|
|
||||||
ctx.Data["IsBranch"] = ctx.Repo.IsBranch
|
// ctx.Data["IsBranch"] = ctx.Repo.IsBranch
|
||||||
ctx.Data["IsTag"] = ctx.Repo.IsTag
|
// ctx.Data["IsTag"] = ctx.Repo.IsTag
|
||||||
ctx.Data["IsCommit"] = ctx.Repo.IsCommit
|
// ctx.Data["IsCommit"] = ctx.Repo.IsCommit
|
||||||
|
|
||||||
ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
|
// ctx.Repo.CommitsCount, err = ctx.Repo.Commit.CommitsCount()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Handle(500, "CommitsCount", err)
|
// ctx.Handle(500, "CommitsCount", err)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
// ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
||||||
}
|
// }
|
||||||
|
|
||||||
// repo is bare and display enable
|
// repo is bare and display enable
|
||||||
if ctx.Repo.Repository.IsBare {
|
if ctx.Repo.Repository.IsBare {
|
||||||
|
|
|
@ -240,6 +240,9 @@ img.avatar-100 {
|
||||||
.text-black {
|
.text-black {
|
||||||
color: #444444;
|
color: #444444;
|
||||||
}
|
}
|
||||||
|
.text-gold {
|
||||||
|
color: #a1882b;
|
||||||
|
}
|
||||||
.table {
|
.table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
|
@ -259,6 +259,9 @@ clear: both;
|
||||||
.text-black {
|
.text-black {
|
||||||
color: #444444;
|
color: #444444;
|
||||||
}
|
}
|
||||||
|
.text-gold {
|
||||||
|
color: #a1882b;
|
||||||
|
}
|
||||||
.table {
|
.table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
|
|
|
@ -20,6 +20,17 @@ const (
|
||||||
DIFF base.TplName = "repo/diff"
|
DIFF base.TplName = "repo/diff"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func RefCommits(ctx *middleware.Context) {
|
||||||
|
switch {
|
||||||
|
case len(ctx.Repo.TreeName) == 0:
|
||||||
|
Commits(ctx)
|
||||||
|
case ctx.Repo.TreeName == "search":
|
||||||
|
SearchCommits(ctx)
|
||||||
|
default:
|
||||||
|
FileHistory(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Commits(ctx *middleware.Context) {
|
func Commits(ctx *middleware.Context) {
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
|
|
||||||
|
@ -109,6 +120,69 @@ func SearchCommits(ctx *middleware.Context) {
|
||||||
ctx.HTML(200, COMMITS)
|
ctx.HTML(200, COMMITS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FileHistory(ctx *middleware.Context) {
|
||||||
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
|
|
||||||
|
fileName := ctx.Repo.TreeName
|
||||||
|
if len(fileName) == 0 {
|
||||||
|
Commits(ctx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
userName := ctx.Repo.Owner.Name
|
||||||
|
repoName := ctx.Repo.Repository.Name
|
||||||
|
branchName := ctx.Repo.BranchName
|
||||||
|
|
||||||
|
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetBranches", err)
|
||||||
|
return
|
||||||
|
} else if len(brs) == 0 {
|
||||||
|
ctx.Handle(404, "GetBranches", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
|
||||||
|
return
|
||||||
|
} else if commitsCount == 0 {
|
||||||
|
ctx.Handle(404, "repo.FileHistory", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate and validate page number.
|
||||||
|
page := com.StrTo(ctx.Query("p")).MustInt()
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
lastPage := page - 1
|
||||||
|
if lastPage < 0 {
|
||||||
|
lastPage = 0
|
||||||
|
}
|
||||||
|
nextPage := page + 1
|
||||||
|
if nextPage*50 > commitsCount {
|
||||||
|
nextPage = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
|
||||||
|
branchName, fileName, page)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
commits = models.ValidateCommitsWithEmails(commits)
|
||||||
|
|
||||||
|
ctx.Data["Commits"] = commits
|
||||||
|
ctx.Data["Username"] = userName
|
||||||
|
ctx.Data["Reponame"] = repoName
|
||||||
|
ctx.Data["FileName"] = fileName
|
||||||
|
ctx.Data["CommitCount"] = commitsCount
|
||||||
|
ctx.Data["LastPageNum"] = lastPage
|
||||||
|
ctx.Data["NextPageNum"] = nextPage
|
||||||
|
ctx.HTML(200, COMMITS)
|
||||||
|
}
|
||||||
|
|
||||||
func Diff(ctx *middleware.Context) {
|
func Diff(ctx *middleware.Context) {
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
ctx.Data["IsRepoToolbarCommits"] = true
|
||||||
|
|
||||||
|
@ -230,66 +304,3 @@ func CompareDiff(ctx *middleware.Context) {
|
||||||
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", afterCommitId)
|
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", afterCommitId)
|
||||||
ctx.HTML(200, DIFF)
|
ctx.HTML(200, DIFF)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileHistory(ctx *middleware.Context) {
|
|
||||||
ctx.Data["IsRepoToolbarCommits"] = true
|
|
||||||
|
|
||||||
fileName := ctx.Params("*")
|
|
||||||
if len(fileName) == 0 {
|
|
||||||
Commits(ctx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
userName := ctx.Repo.Owner.Name
|
|
||||||
repoName := ctx.Repo.Repository.Name
|
|
||||||
branchName := ctx.Params(":branchname")
|
|
||||||
|
|
||||||
brs, err := ctx.Repo.GitRepo.GetBranches()
|
|
||||||
if err != nil {
|
|
||||||
ctx.Handle(500, "GetBranches", err)
|
|
||||||
return
|
|
||||||
} else if len(brs) == 0 {
|
|
||||||
ctx.Handle(404, "GetBranches", nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
|
|
||||||
if err != nil {
|
|
||||||
ctx.Handle(500, "repo.FileHistory(GetCommitsCount)", err)
|
|
||||||
return
|
|
||||||
} else if commitsCount == 0 {
|
|
||||||
ctx.Handle(404, "repo.FileHistory", nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate and validate page number.
|
|
||||||
page := com.StrTo(ctx.Query("p")).MustInt()
|
|
||||||
if page < 1 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
lastPage := page - 1
|
|
||||||
if lastPage < 0 {
|
|
||||||
lastPage = 0
|
|
||||||
}
|
|
||||||
nextPage := page + 1
|
|
||||||
if nextPage*50 > commitsCount {
|
|
||||||
nextPage = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(
|
|
||||||
branchName, fileName, page)
|
|
||||||
if err != nil {
|
|
||||||
ctx.Handle(500, "repo.FileHistory(CommitsByRange)", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
commits = models.ValidateCommitsWithEmails(commits)
|
|
||||||
|
|
||||||
ctx.Data["Commits"] = commits
|
|
||||||
ctx.Data["Username"] = userName
|
|
||||||
ctx.Data["Reponame"] = repoName
|
|
||||||
ctx.Data["FileName"] = fileName
|
|
||||||
ctx.Data["CommitCount"] = commitsCount
|
|
||||||
ctx.Data["LastPageNum"] = lastPage
|
|
||||||
ctx.Data["NextPageNum"] = nextPage
|
|
||||||
ctx.HTML(200, COMMITS)
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,9 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func SingleDownload(ctx *middleware.Context) {
|
func SingleDownload(ctx *middleware.Context) {
|
||||||
treename := ctx.Params("*")
|
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
|
||||||
|
|
||||||
blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetBlobByPath", err)
|
ctx.Handle(500, "GetBlobByPath", err)
|
||||||
return
|
return
|
||||||
|
@ -23,7 +21,7 @@ func SingleDownload(ctx *middleware.Context) {
|
||||||
|
|
||||||
dataRc, err := blob.Data()
|
dataRc, err := blob.Data()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "repo.SingleDownload(Data)", err)
|
ctx.Handle(500, "Data", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ func SingleDownload(ctx *middleware.Context) {
|
||||||
_, isImageFile := base.IsImageFile(buf)
|
_, isImageFile := base.IsImageFile(buf)
|
||||||
ctx.Resp.Header().Set("Content-Type", contentType)
|
ctx.Resp.Header().Set("Content-Type", contentType)
|
||||||
if !isTextFile && !isImageFile {
|
if !isTextFile && !isImageFile {
|
||||||
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(treename))
|
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+path.Base(ctx.Repo.TreeName))
|
||||||
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
|
ctx.Resp.Header().Set("Content-Transfer-Encoding", "binary")
|
||||||
}
|
}
|
||||||
ctx.Resp.Write(buf)
|
ctx.Resp.Write(buf)
|
||||||
|
|
|
@ -22,21 +22,38 @@ func Releases(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = "Releases"
|
ctx.Data["Title"] = "Releases"
|
||||||
ctx.Data["IsRepoToolbarReleases"] = true
|
ctx.Data["IsRepoToolbarReleases"] = true
|
||||||
ctx.Data["IsRepoReleaseNew"] = false
|
ctx.Data["IsRepoReleaseNew"] = false
|
||||||
|
|
||||||
rawTags, err := ctx.Repo.GitRepo.GetTags()
|
rawTags, err := ctx.Repo.GitRepo.GetTags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "release.Releases(GetTags)", err)
|
ctx.Handle(500, "GetTags", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.Id)
|
rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "release.Releases(GetReleasesByRepoId)", err)
|
ctx.Handle(500, "GetReleasesByRepoId", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commitsCount, err := ctx.Repo.Commit.CommitsCount()
|
// Get default branch.
|
||||||
|
refName := ctx.Repo.Repository.DefaultBranch
|
||||||
|
if !ctx.Repo.GitRepo.IsBranchExist(refName) {
|
||||||
|
brs, err := ctx.Repo.GitRepo.GetBranches()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "release.Releases(CommitsCount)", err)
|
ctx.Handle(500, "GetBranches", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
refName = brs[0]
|
||||||
|
}
|
||||||
|
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(refName)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commitsCount, err := commit.CommitsCount()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "CommitsCount", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,18 +76,18 @@ func Releases(ctx *middleware.Context) {
|
||||||
if ctx.Repo.BranchName != rel.Target {
|
if ctx.Repo.BranchName != rel.Target {
|
||||||
// Get count if not exists.
|
// Get count if not exists.
|
||||||
if _, ok := countCache[rel.Target]; !ok {
|
if _, ok := countCache[rel.Target]; !ok {
|
||||||
commit, err := ctx.Repo.GitRepo.GetCommitOfTag(rel.TagName)
|
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(ctx.Repo.BranchName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "GetCommitOfTag", err)
|
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countCache[rel.Target], err = commit.CommitsCount()
|
countCache[ctx.Repo.BranchName], err = commit.CommitsCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "CommitsCount2", err)
|
ctx.Handle(500, "CommitsCount2", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rel.NumCommitsBehind = countCache[rel.Target] - rel.NumCommits
|
rel.NumCommitsBehind = countCache[ctx.Repo.BranchName] - rel.NumCommits
|
||||||
} else {
|
} else {
|
||||||
rel.NumCommitsBehind = commitsCount - rel.NumCommits
|
rel.NumCommitsBehind = commitsCount - rel.NumCommits
|
||||||
}
|
}
|
||||||
|
@ -134,14 +151,20 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
commitsCount, err := ctx.Repo.Commit.CommitsCount()
|
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
|
||||||
if err != nil {
|
ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), RELEASE_NEW, &form)
|
||||||
ctx.Handle(500, "release.ReleasesNewPost(CommitsCount)", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
|
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(form.Target)
|
||||||
ctx.RenderWithErr("Target branch does not exist", "release/new", &form)
|
if err != nil {
|
||||||
|
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commitsCount, err := commit.CommitsCount()
|
||||||
|
if err != nil {
|
||||||
|
ctx.Handle(500, "CommitsCount", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +174,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
||||||
Title: form.Title,
|
Title: form.Title,
|
||||||
TagName: form.TagName,
|
TagName: form.TagName,
|
||||||
Target: form.Target,
|
Target: form.Target,
|
||||||
Sha1: ctx.Repo.Commit.Id.String(),
|
Sha1: commit.Id.String(),
|
||||||
NumCommits: commitsCount,
|
NumCommits: commitsCount,
|
||||||
Note: form.Content,
|
Note: form.Content,
|
||||||
IsDraft: len(form.Draft) > 0,
|
IsDraft: len(form.Draft) > 0,
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Home(ctx *middleware.Context) {
|
||||||
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
||||||
|
|
||||||
// Get tree path
|
// Get tree path
|
||||||
treename := ctx.Params("*")
|
treename := ctx.Repo.TreeName
|
||||||
|
|
||||||
if len(treename) > 0 && treename[len(treename)-1] == '/' {
|
if len(treename) > 0 && treename[len(treename)-1] == '/' {
|
||||||
ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1])
|
ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1])
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.5.7.1105 Beta
|
0.5.7.1106 Beta
|
|
@ -54,7 +54,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</li>
|
</li>
|
||||||
<li id="repo-commits-jump" class="repo-jump right">
|
<!-- <li id="repo-commits-jump" class="repo-jump right">
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<button class="btn btn-small btn-gray btn-right-radius"><i class="octicon octicon-git-commit"></i></button>
|
<button class="btn btn-small btn-gray btn-right-radius"><i class="octicon octicon-git-commit"></i></button>
|
||||||
</a>
|
</a>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<button class="btn btn-small btn btn-small btn-gray btn-left-radius"><i class="octicon octicon-list-unordered"></i></button>
|
<button class="btn btn-small btn btn-small btn-gray btn-left-radius"><i class="octicon octicon-list-unordered"></i></button>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li> -->
|
||||||
</ul>
|
</ul>
|
||||||
{{if .IsFile}}
|
{{if .IsFile}}
|
||||||
{{template "repo/view_file" .}}
|
{{template "repo/view_file" .}}
|
||||||
|
|
|
@ -70,13 +70,18 @@
|
||||||
<div class="tab-pane active">
|
<div class="tab-pane active">
|
||||||
<div id="org-repo-list">
|
<div id="org-repo-list">
|
||||||
{{range .Repos}}
|
{{range .Repos}}
|
||||||
{{if not .IsPrivate}}
|
{{if or (not .IsPrivate) (.HasAccess $.SignedUserName)}}
|
||||||
<div class="org-repo-item">
|
<div class="org-repo-item">
|
||||||
<ul class="org-repo-status right">
|
<ul class="org-repo-status right">
|
||||||
<li><i class="octicon octicon-star"></i> {{.NumStars}}</li>
|
<li><i class="octicon octicon-star"></i> {{.NumStars}}</li>
|
||||||
<li><i class="octicon octicon-git-branch"></i> {{.NumForks}}</li>
|
<li><i class="octicon octicon-git-branch"></i> {{.NumForks}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h2><a href="{{AppSubUrl}}/{{$.Owner.Name}}/{{.Name}}">{{.Name}}</a></h2>
|
<h2>
|
||||||
|
<a href="{{AppSubUrl}}/{{$.Owner.Name}}/{{.Name}}">{{.Name}}</a>
|
||||||
|
{{if .IsPrivate}}
|
||||||
|
<span class="text-gold"><i class="octicon octicon-lock"></i></span>
|
||||||
|
{{end}}
|
||||||
|
</h2>
|
||||||
<p class="org-repo-description">{{.Description}}</p>
|
<p class="org-repo-description">{{.Description}}</p>
|
||||||
<p class="org-repo-updated">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
|
<p class="org-repo-updated">{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue