chore: fix legacy git ref problems (#38827)

1. add correct "refs/heads" prefix to the branch name for commit graph
2. fix incorrect cache key in GetCommitGraphsCount
3. remove the "--" trim for the tag name, there is no security vulnerability, we never do so anywhere else

Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
wxiaoguang
2026-08-08 07:04:36 +08:00
committed by GitHub
parent 09f78aed19
commit f899dfd6e0
5 changed files with 31 additions and 27 deletions
+4 -4
View File
@@ -14,7 +14,7 @@ import (
)
// GetCommitGraph return a list of commit (GraphItems) from all branches
func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllowedColors int, hidePRRefs bool, branches, files []string) (*Graph, error) {
func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllowedColors int, hidePRRefs bool, refs, files []string) (*Graph, error) {
format := "DATA:%D|%H|%ad|%h|%s"
if page == 0 {
@@ -27,7 +27,7 @@ func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllow
graphCmd.AddArguments("--exclude=" + git.PullPrefix + "*")
}
if len(branches) == 0 {
if len(refs) == 0 {
graphCmd.AddArguments("--tags", "--branches")
}
@@ -35,8 +35,8 @@ func GetCommitGraph(ctx context.Context, gitRepo *git.Repository, page, maxAllow
AddOptionFormat("-n %d", setting.UI.GraphMaxCommitNum*page).
AddOptionFormat("--pretty=format:%s", format)
if len(branches) > 0 {
graphCmd.AddDynamicArguments(branches...)
if len(refs) > 0 {
graphCmd.AddDynamicArguments(refs...)
}
if len(files) > 0 {
graphCmd.AddDashesAndList(files...)