parent
4e7eb5be9d
commit
23eec25274
14 changed files with 304 additions and 164 deletions
|
@ -20,6 +20,17 @@ const (
|
|||
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) {
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
|
@ -109,6 +120,69 @@ func SearchCommits(ctx *middleware.Context) {
|
|||
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) {
|
||||
ctx.Data["IsRepoToolbarCommits"] = true
|
||||
|
||||
|
@ -230,66 +304,3 @@ func CompareDiff(ctx *middleware.Context) {
|
|||
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", afterCommitId)
|
||||
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) {
|
||||
treename := ctx.Params("*")
|
||||
|
||||
blob, err := ctx.Repo.Commit.GetBlobByPath(treename)
|
||||
blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreeName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetBlobByPath", err)
|
||||
return
|
||||
|
@ -23,7 +21,7 @@ func SingleDownload(ctx *middleware.Context) {
|
|||
|
||||
dataRc, err := blob.Data()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "repo.SingleDownload(Data)", err)
|
||||
ctx.Handle(500, "Data", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,7 +35,7 @@ func SingleDownload(ctx *middleware.Context) {
|
|||
_, isImageFile := base.IsImageFile(buf)
|
||||
ctx.Resp.Header().Set("Content-Type", contentType)
|
||||
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.Write(buf)
|
||||
|
|
|
@ -22,21 +22,38 @@ func Releases(ctx *middleware.Context) {
|
|||
ctx.Data["Title"] = "Releases"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
ctx.Data["IsRepoReleaseNew"] = false
|
||||
|
||||
rawTags, err := ctx.Repo.GitRepo.GetTags()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "release.Releases(GetTags)", err)
|
||||
ctx.Handle(500, "GetTags", err)
|
||||
return
|
||||
}
|
||||
|
||||
rels, err := models.GetReleasesByRepoId(ctx.Repo.Repository.Id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "release.Releases(GetReleasesByRepoId)", err)
|
||||
ctx.Handle(500, "GetReleasesByRepoId", err)
|
||||
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 {
|
||||
ctx.Handle(500, "GetBranches", err)
|
||||
return
|
||||
}
|
||||
refName = brs[0]
|
||||
}
|
||||
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(refName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "release.Releases(CommitsCount)", err)
|
||||
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
commitsCount, err := commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -59,18 +76,18 @@ 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.GetCommitOfTag(rel.TagName)
|
||||
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(ctx.Repo.BranchName)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommitOfTag", err)
|
||||
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||
return
|
||||
}
|
||||
countCache[rel.Target], err = commit.CommitsCount()
|
||||
countCache[ctx.Repo.BranchName], err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsCount2", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
rel.NumCommitsBehind = countCache[rel.Target] - rel.NumCommits
|
||||
rel.NumCommitsBehind = countCache[ctx.Repo.BranchName] - rel.NumCommits
|
||||
} else {
|
||||
rel.NumCommitsBehind = commitsCount - rel.NumCommits
|
||||
}
|
||||
|
@ -134,14 +151,20 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
|||
return
|
||||
}
|
||||
|
||||
commitsCount, err := ctx.Repo.Commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "release.ReleasesNewPost(CommitsCount)", err)
|
||||
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.target_branch_not_exist"), RELEASE_NEW, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.GitRepo.IsBranchExist(form.Target) {
|
||||
ctx.RenderWithErr("Target branch does not exist", "release/new", &form)
|
||||
commit, err := ctx.Repo.GitRepo.GetCommitOfBranch(form.Target)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommitOfBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
commitsCount, err := commit.CommitsCount()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsCount", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -151,7 +174,7 @@ func NewReleasePost(ctx *middleware.Context, form auth.NewReleaseForm) {
|
|||
Title: form.Title,
|
||||
TagName: form.TagName,
|
||||
Target: form.Target,
|
||||
Sha1: ctx.Repo.Commit.Id.String(),
|
||||
Sha1: commit.Id.String(),
|
||||
NumCommits: commitsCount,
|
||||
Note: form.Content,
|
||||
IsDraft: len(form.Draft) > 0,
|
||||
|
|
|
@ -34,7 +34,7 @@ func Home(ctx *middleware.Context) {
|
|||
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
||||
|
||||
// Get tree path
|
||||
treename := ctx.Params("*")
|
||||
treename := ctx.Repo.TreeName
|
||||
|
||||
if len(treename) > 0 && treename[len(treename)-1] == '/' {
|
||||
ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue