feat: vendor gitea 1.16.2

This commit is contained in:
2026-06-02 08:36:01 +00:00
parent 247cd60f69
commit 54798b4615
2145 changed files with 162965 additions and 126447 deletions
@@ -4,24 +4,27 @@
package markup
import (
"fmt"
"slices"
"strings"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/httplib"
"code.gitea.io/gitea/modules/references"
"code.gitea.io/gitea/modules/util"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
)
type anyHashPatternResult struct {
PosStart int
PosEnd int
FullURL string
CommitID string
SubPath string
QueryHash string
PosStart int
PosEnd int
FullURL string
CommitID string
CommitExt string
SubPath string
QueryParams string
QueryHash string
}
func createCodeLink(href, content, class string) *html.Node {
@@ -56,7 +59,11 @@ func anyHashPatternExtract(s string) (ret anyHashPatternResult, ok bool) {
return ret, false
}
ret.PosStart, ret.PosEnd = m[0], m[1]
pos := 0
ret.PosStart, ret.PosEnd = m[pos], m[pos+1]
pos += 2
ret.FullURL = s[ret.PosStart:ret.PosEnd]
if strings.HasSuffix(ret.FullURL, ".") {
// if url ends in '.', it's very likely that it is not part of the actual url but used to finish a sentence.
@@ -67,14 +74,24 @@ func anyHashPatternExtract(s string) (ret anyHashPatternResult, ok bool) {
}
}
ret.CommitID = s[m[2]:m[3]]
if m[5] > 0 {
ret.SubPath = s[m[4]:m[5]]
}
ret.CommitID = s[m[pos]:m[pos+1]]
pos += 2
lastStart, lastEnd := m[len(m)-2], m[len(m)-1]
if lastEnd > 0 {
ret.QueryHash = s[lastStart:lastEnd][1:]
ret.CommitExt = s[m[pos]:m[pos+1]]
pos += 4
if m[pos] > 0 {
ret.SubPath = s[m[pos]:m[pos+1]]
}
pos += 2
if m[pos] > 0 {
ret.QueryParams = s[m[pos]:m[pos+1]]
}
pos += 2
if m[pos] > 0 {
ret.QueryHash = s[m[pos]:m[pos+1]][1:]
}
return ret, true
}
@@ -96,12 +113,20 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
continue
}
text := base.ShortSha(ret.CommitID)
if ret.CommitExt != "" {
text += ret.CommitExt
}
if ret.SubPath != "" {
text += ret.SubPath
}
if ret.QueryHash != "" {
text += " (" + ret.QueryHash + ")"
}
// only turn commit links to the current instance into hash link
if !httplib.IsCurrentGiteaSiteURL(ctx, ret.FullURL) {
node = node.NextSibling
continue
}
replaceContent(node, ret.PosStart, ret.PosEnd, createCodeLink(ret.FullURL, text, "commit"))
node = node.NextSibling.NextSibling
}
@@ -148,6 +173,12 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
}
}
// only turn compare links to the current instance into hash link
if !httplib.IsCurrentGiteaSiteURL(ctx, urlFull) {
node = node.NextSibling
continue
}
text := text1 + textDots + text2
if hash != "" {
text += " (" + hash + ")"
@@ -188,7 +219,7 @@ func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
continue
}
link := "/:root/" + util.URLJoin(ctx.RenderOptions.Metas["user"], ctx.RenderOptions.Metas["repo"], "commit", hash)
link := fmt.Sprintf("/:root/%s/%s/commit/%s", ctx.RenderOptions.Metas["user"], ctx.RenderOptions.Metas["repo"], hash)
replaceContent(node, m[2], m[3], createCodeLink(link, base.ShortSha(hash), "commit"))
start = 0
node = node.NextSibling.NextSibling
@@ -205,7 +236,7 @@ func commitCrossReferencePatternProcessor(ctx *RenderContext, node *html.Node) {
}
refText := ref.Owner + "/" + ref.Name + "@" + base.ShortSha(ref.CommitSha)
linkHref := "/:root/" + util.URLJoin(ref.Owner, ref.Name, "commit", ref.CommitSha)
linkHref := fmt.Sprintf("/:root/%s/%s/commit/%s", ref.Owner, ref.Name, ref.CommitSha)
link := createLink(ctx, linkHref, refText, "commit")
replaceContent(node, ref.RefLocation.Start, ref.RefLocation.End, link)