From c05a8abc762f868e67dd131d34f45218a0fb95ab Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 8 Nov 2020 17:21:54 +0000 Subject: Multiple GitGraph improvements: Exclude PR heads, Add branch/PR links, Show only certain branches, (#12766) * Multiple GitGraph improvements. Add backend support for excluding PRs, selecting branches and files. Fix #10327 Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * Only show refs in dropdown we display on the graph Signed-off-by: Andrew Thornton * as per @silverwind Signed-off-by: Andrew Thornton * use flexbox for ui header Signed-off-by: Andrew Thornton * Move Hide Pull Request button to the dropdown Signed-off-by: Andrew Thornton * Add SHA and user pictures Signed-off-by: Andrew Thornton * fix test Signed-off-by: Andrew Thornton * fix test 2 Signed-off-by: Andrew Thornton * fixes * async * more tweaks * use tabs in tmpl Signed-off-by: Andrew Thornton * remove commented thing Signed-off-by: Andrew Thornton * fix linting Signed-off-by: Andrew Thornton * Update web_src/js/features/gitgraph.js Co-authored-by: silverwind * graph tweaks * more tweaks * add title Signed-off-by: Andrew Thornton * fix loading indicator z-index and position Co-authored-by: silverwind Co-authored-by: techknowlogick Co-authored-by: Lauris BH --- modules/gitgraph/graph.go | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'modules/gitgraph/graph.go') diff --git a/modules/gitgraph/graph.go b/modules/gitgraph/graph.go index 257e4f3af0..8505678639 100644 --- a/modules/gitgraph/graph.go +++ b/modules/gitgraph/graph.go @@ -17,23 +17,42 @@ import ( ) // GetCommitGraph return a list of commit (GraphItems) from all branches -func GetCommitGraph(r *git.Repository, page int, maxAllowedColors int) (*Graph, error) { - format := "DATA:%d|%H|%ad|%an|%ae|%h|%s" +func GetCommitGraph(r *git.Repository, page int, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) { + format := "DATA:%D|%H|%ad|%h|%s" if page == 0 { page = 1 } - graphCmd := git.NewCommand("log") - graphCmd.AddArguments("--graph", - "--date-order", - "--all", + args := make([]string, 0, 12+len(branches)+len(files)) + + args = append(args, "--graph", "--date-order", "--decorate=full") + + if hidePRRefs { + args = append(args, "--exclude=refs/pull/*") + } + + if len(branches) == 0 { + args = append(args, "--all") + } + + args = append(args, "-C", "-M", fmt.Sprintf("-n %d", setting.UI.GraphMaxCommitNum*page), "--date=iso", - fmt.Sprintf("--pretty=format:%s", format), - ) + fmt.Sprintf("--pretty=format:%s", format)) + + if len(branches) > 0 { + args = append(args, branches...) + } + args = append(args, "--") + if len(files) > 0 { + args = append(args, files...) + } + + graphCmd := git.NewCommand("log") + graphCmd.AddArguments(args...) graph := NewGraph() stderr := new(strings.Builder) -- cgit v1.2.3