diff options
author | Jason Song <i@wolfogre.com> | 2022-12-27 21:12:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-27 21:12:49 +0800 |
commit | 6cf09ccab402fe84a5313e1d3e755e284ebbc845 (patch) | |
tree | b1fad807c2a16fded8b6bda84583c421ec86230c /modules/context | |
parent | 90237d8abd0e6479c1464ac0f32fff6a2ce4a0b4 (diff) | |
download | gitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.tar.gz gitea-6cf09ccab402fe84a5313e1d3e755e284ebbc845.zip |
Use complete SHA to create and query commit status (#22244)
Fix #13485.
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/context')
-rw-r--r-- | modules/context/api.go | 2 | ||||
-rw-r--r-- | modules/context/repo.go | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/modules/context/api.go b/modules/context/api.go index f49997a787..1349f91ec0 100644 --- a/modules/context/api.go +++ b/modules/context/api.go @@ -387,7 +387,7 @@ func RepoRefForAPI(next http.Handler) http.Handler { return } ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() - } else if len(refName) == 40 { + } else if len(refName) == git.SHAFullLength { ctx.Repo.CommitID = refName ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommit(refName) if err != nil { diff --git a/modules/context/repo.go b/modules/context/repo.go index 71a2b3c0c6..d15d28cab7 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -817,7 +817,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string { } // For legacy and API support only full commit sha parts := strings.Split(path, "/") - if len(parts) > 0 && len(parts[0]) == 40 { + if len(parts) > 0 && len(parts[0]) == git.SHAFullLength { ctx.Repo.TreePath = strings.Join(parts[1:], "/") return parts[0] } @@ -853,7 +853,7 @@ func getRefName(ctx *Context, pathType RepoRefType) string { return getRefNameFromPath(ctx, path, ctx.Repo.GitRepo.IsTagExist) case RepoRefCommit: parts := strings.Split(path, "/") - if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= 40 { + if len(parts) > 0 && len(parts[0]) >= 7 && len(parts[0]) <= git.SHAFullLength { ctx.Repo.TreePath = strings.Join(parts[1:], "/") return parts[0] } @@ -962,7 +962,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context return } ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() - } else if len(refName) >= 7 && len(refName) <= 40 { + } else if len(refName) >= 7 && len(refName) <= git.SHAFullLength { ctx.Repo.IsViewCommit = true ctx.Repo.CommitID = refName @@ -972,7 +972,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context return } // If short commit ID add canonical link header - if len(refName) < 40 { + if len(refName) < git.SHAFullLength { ctx.RespHeader().Set("Link", fmt.Sprintf("<%s>; rel=\"canonical\"", util.URLJoin(setting.AppURL, strings.Replace(ctx.Req.URL.RequestURI(), util.PathEscapeSegments(refName), url.PathEscape(ctx.Repo.Commit.ID.String()), 1)))) } |