aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/commit.go56
1 files changed, 51 insertions, 5 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index d9547cc51d..5bb26ffe41 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -23,6 +23,7 @@ import (
const (
tplCommits base.TplName = "repo/commits"
tplGraph base.TplName = "repo/graph"
+ tplGraphDiv base.TplName = "repo/graph/div"
tplCommitPage base.TplName = "repo/commit_page"
)
@@ -88,6 +89,7 @@ func Commits(ctx *context.Context) {
// Graph render commit graph - show commits from all branches.
func Graph(ctx *context.Context) {
+ ctx.Data["Title"] = ctx.Tr("repo.commit_graph")
ctx.Data["PageIsCommits"] = true
ctx.Data["PageIsViewCode"] = true
mode := strings.ToLower(ctx.QueryTrim("mode"))
@@ -95,6 +97,18 @@ func Graph(ctx *context.Context) {
mode = "color"
}
ctx.Data["Mode"] = mode
+ hidePRRefs := ctx.QueryBool("hide-pr-refs")
+ ctx.Data["HidePRRefs"] = hidePRRefs
+ branches := ctx.QueryStrings("branch")
+ realBranches := make([]string, len(branches))
+ copy(realBranches, branches)
+ for i, branch := range realBranches {
+ if strings.HasPrefix(branch, "--") {
+ realBranches[i] = "refs/heads/" + branch
+ }
+ }
+ ctx.Data["SelectedBranches"] = realBranches
+ files := ctx.QueryStrings("file")
commitsCount, err := ctx.Repo.GetCommitsCount()
if err != nil {
@@ -102,28 +116,60 @@ func Graph(ctx *context.Context) {
return
}
- allCommitsCount, err := ctx.Repo.GitRepo.GetAllCommitsCount()
+ graphCommitsCount, err := ctx.Repo.GetCommitGraphsCount(hidePRRefs, realBranches, files)
if err != nil {
- ctx.ServerError("GetAllCommitsCount", err)
- return
+ log.Warn("GetCommitGraphsCount error for generate graph exclude prs: %t branches: %s in %-v, Will Ignore branches and try again. Underlying Error: %v", hidePRRefs, branches, ctx.Repo.Repository, err)
+ realBranches = []string{}
+ branches = []string{}
+ graphCommitsCount, err = ctx.Repo.GetCommitGraphsCount(hidePRRefs, realBranches, files)
+ if err != nil {
+ ctx.ServerError("GetCommitGraphsCount", err)
+ return
+ }
}
page := ctx.QueryInt("page")
- graph, err := gitgraph.GetCommitGraph(ctx.Repo.GitRepo, page, 0)
+ graph, err := gitgraph.GetCommitGraph(ctx.Repo.GitRepo, page, 0, hidePRRefs, realBranches, files)
if err != nil {
ctx.ServerError("GetCommitGraph", err)
return
}
+ if err := graph.LoadAndProcessCommits(ctx.Repo.Repository, ctx.Repo.GitRepo); err != nil {
+ ctx.ServerError("LoadAndProcessCommits", err)
+ return
+ }
+
ctx.Data["Graph"] = graph
+
+ gitRefs, err := ctx.Repo.GitRepo.GetRefs()
+ if err != nil {
+ ctx.ServerError("GitRepo.GetRefs", err)
+ return
+ }
+
+ ctx.Data["AllRefs"] = gitRefs
+
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["CommitCount"] = commitsCount
ctx.Data["Branch"] = ctx.Repo.BranchName
- paginator := context.NewPagination(int(allCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
+ paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
paginator.AddParam(ctx, "mode", "Mode")
+ paginator.AddParam(ctx, "hide-pr-refs", "HidePRRefs")
+ for _, branch := range branches {
+ paginator.AddParamString("branch", branch)
+ }
+ for _, file := range files {
+ paginator.AddParamString("file", file)
+ }
ctx.Data["Page"] = paginator
+ if ctx.QueryBool("div-only") {
+ ctx.HTML(200, tplGraphDiv)
+ return
+ }
+
ctx.HTML(200, tplGraph)
}