Skip to content

Commit 89ba900

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: A small refactor to use context in the service layer (go-gitea#35179) Fix repo file list partial reloading for submodules (go-gitea#35183) Update gopls to 0.20.0 (go-gitea#35180) Fix various bugs (go-gitea#35177) [skip ci] Updated translations via Crowdin [skip ci] Updated translations via Crowdin
2 parents af2cc30 + 84d31bc commit 89ba900

22 files changed

+175
-74
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.19.1
40-
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.19.1
39+
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.20.0
40+
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@v0.20.0
4141

4242
DOCKER_IMAGE ?= gitea/gitea
4343
DOCKER_TAG ?= latest

modules/git/commit_info.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33

44
package git
55

6-
import "path"
7-
86
// CommitInfo describes the first commit with the provided entry
97
type CommitInfo struct {
108
Entry *TreeEntry
119
Commit *Commit
1210
SubmoduleFile *CommitSubmoduleFile
1311
}
1412

15-
func getCommitInfoSubmoduleFile(repoLink string, entry *TreeEntry, commit *Commit, treePathDir string) (*CommitSubmoduleFile, error) {
16-
fullPath := path.Join(treePathDir, entry.Name())
13+
func GetCommitInfoSubmoduleFile(repoLink, fullPath string, commit *Commit, refCommitID ObjectID) (*CommitSubmoduleFile, error) {
1714
submodule, err := commit.GetSubModule(fullPath)
1815
if err != nil {
1916
return nil, err
2017
}
2118
if submodule == nil {
2219
// unable to find submodule from ".gitmodules" file
23-
return NewCommitSubmoduleFile(repoLink, fullPath, "", entry.ID.String()), nil
20+
return NewCommitSubmoduleFile(repoLink, fullPath, "", refCommitID.String()), nil
2421
}
25-
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, entry.ID.String()), nil
22+
return NewCommitSubmoduleFile(repoLink, fullPath, submodule.URL, refCommitID.String()), nil
2623
}

modules/git/commit_info_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
7373

7474
// If the entry is a submodule, add a submodule file for this
7575
if entry.IsSubModule() {
76-
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
76+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
7777
if err != nil {
7878
return nil, nil, err
7979
}

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, repoLink string, commit *
6464

6565
// If the entry is a submodule, add a submodule file for this
6666
if entry.IsSubModule() {
67-
commitsInfo[i].SubmoduleFile, err = getCommitInfoSubmoduleFile(repoLink, entry, commit, treePath)
67+
commitsInfo[i].SubmoduleFile, err = GetCommitInfoSubmoduleFile(repoLink, path.Join(treePath, entry.Name()), commit, entry.ID)
6868
if err != nil {
6969
return nil, nil, err
7070
}

modules/git/commit_info_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
125125
t.Run("NonExistingSubmoduleAsNil", func(t *testing.T) {
126126
commit, err := bareRepo1.GetCommit("HEAD")
127127
require.NoError(t, err)
128-
tree, err := commit.GetTreeEntryByPath("file1.txt")
128+
treeEntry, err := commit.GetTreeEntryByPath("file1.txt")
129129
require.NoError(t, err)
130-
cisf, err := getCommitInfoSubmoduleFile("/any/repo-link", tree, commit, "")
130+
cisf, err := GetCommitInfoSubmoduleFile("/any/repo-link", "file1.txt", commit, treeEntry.ID)
131131
require.NoError(t, err)
132132
assert.Equal(t, &CommitSubmoduleFile{
133133
repoLink: "/any/repo-link",

modules/git/commit_submodule_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (sf *CommitSubmoduleFile) getWebLinkInTargetRepo(ctx context.Context, moreL
4242
return nil
4343
}
4444
if strings.HasPrefix(sf.refURL, "../") {
45-
targetLink := path.Join(sf.repoLink, path.Dir(sf.fullPath), sf.refURL)
45+
targetLink := path.Join(sf.repoLink, sf.refURL)
4646
return &SubmoduleWebLink{RepoWebLink: targetLink, CommitWebLink: targetLink + moreLinkPath}
4747
}
4848
if !sf.parsed {

modules/git/commit_submodule_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestCommitSubmoduleLink(t *testing.T) {
3232
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
3333
assert.Equal(t, "/subpath/user/repo/tree/aaaa", wl.CommitWebLink)
3434

35-
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../../user/repo", "aaaa")
35+
sf = NewCommitSubmoduleFile("/subpath/any/repo-home-link", "dir/submodule", "../../user/repo", "aaaa")
3636
wl = sf.SubmoduleWebLinkCompare(t.Context(), "1111", "2222")
3737
assert.Equal(t, "/subpath/user/repo", wl.RepoWebLink)
3838
assert.Equal(t, "/subpath/user/repo/compare/1111...2222", wl.CommitWebLink)

modules/git/utils.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14+
15+
"code.gitea.io/gitea/modules/util"
1416
)
1517

1618
// ObjectCache provides thread-safe cache operations.
@@ -106,3 +108,16 @@ func HashFilePathForWebUI(s string) string {
106108
_, _ = h.Write([]byte(s))
107109
return hex.EncodeToString(h.Sum(nil))
108110
}
111+
112+
func SplitCommitTitleBody(commitMessage string, titleRuneLimit int) (title, body string) {
113+
title, body, _ = strings.Cut(commitMessage, "\n")
114+
title, title2 := util.EllipsisTruncateRunes(title, titleRuneLimit)
115+
if title2 != "" {
116+
if body == "" {
117+
body = title2
118+
} else {
119+
body = title2 + "\n" + body
120+
}
121+
}
122+
return title, body
123+
}

modules/git/utils_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ func TestHashFilePathForWebUI(t *testing.T) {
1515
HashFilePathForWebUI("foobar"),
1616
)
1717
}
18+
19+
func TestSplitCommitTitleBody(t *testing.T) {
20+
title, body := SplitCommitTitleBody("啊bcdefg", 4)
21+
assert.Equal(t, "啊…", title)
22+
assert.Equal(t, "…bcdefg", body)
23+
24+
title, body = SplitCommitTitleBody("abcdefg\n1234567", 4)
25+
assert.Equal(t, "a…", title)
26+
assert.Equal(t, "…bcdefg\n1234567", body)
27+
28+
title, body = SplitCommitTitleBody("abcdefg\n1234567", 100)
29+
assert.Equal(t, "abcdefg", title)
30+
assert.Equal(t, "1234567", body)
31+
}

modules/util/truncate.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func IsLikelyEllipsisLeftPart(s string) bool {
1919
return strings.HasSuffix(s, utf8Ellipsis) || strings.HasSuffix(s, asciiEllipsis)
2020
}
2121

22-
func ellipsisGuessDisplayWidth(r rune) int {
22+
func ellipsisDisplayGuessWidth(r rune) int {
2323
// To make the truncated string as long as possible,
2424
// CJK/emoji chars are considered as 2-ASCII width but not 3-4 bytes width.
2525
// Here we only make the best guess (better than counting them in bytes),
@@ -48,13 +48,17 @@ func ellipsisGuessDisplayWidth(r rune) int {
4848
// It appends "…" or "..." at the end of truncated string.
4949
// It guarantees the length of the returned runes doesn't exceed the limit.
5050
func EllipsisDisplayString(str string, limit int) string {
51-
s, _, _, _ := ellipsisDisplayString(str, limit)
51+
s, _, _, _ := ellipsisDisplayString(str, limit, ellipsisDisplayGuessWidth)
5252
return s
5353
}
5454

5555
// EllipsisDisplayStringX works like EllipsisDisplayString while it also returns the right part
5656
func EllipsisDisplayStringX(str string, limit int) (left, right string) {
57-
left, offset, truncated, encounterInvalid := ellipsisDisplayString(str, limit)
57+
return ellipsisDisplayStringX(str, limit, ellipsisDisplayGuessWidth)
58+
}
59+
60+
func ellipsisDisplayStringX(str string, limit int, widthGuess func(rune) int) (left, right string) {
61+
left, offset, truncated, encounterInvalid := ellipsisDisplayString(str, limit, widthGuess)
5862
if truncated {
5963
right = str[offset:]
6064
r, _ := utf8.DecodeRune(UnsafeStringToBytes(right))
@@ -68,7 +72,7 @@ func EllipsisDisplayStringX(str string, limit int) (left, right string) {
6872
return left, right
6973
}
7074

71-
func ellipsisDisplayString(str string, limit int) (res string, offset int, truncated, encounterInvalid bool) {
75+
func ellipsisDisplayString(str string, limit int, widthGuess func(rune) int) (res string, offset int, truncated, encounterInvalid bool) {
7276
if len(str) <= limit {
7377
return str, len(str), false, false
7478
}
@@ -81,7 +85,7 @@ func ellipsisDisplayString(str string, limit int) (res string, offset int, trunc
8185
for i, r := range str {
8286
encounterInvalid = encounterInvalid || r == utf8.RuneError
8387
pos = i
84-
runeWidth := ellipsisGuessDisplayWidth(r)
88+
runeWidth := widthGuess(r)
8589
if used+runeWidth+3 > limit {
8690
break
8791
}
@@ -96,7 +100,7 @@ func ellipsisDisplayString(str string, limit int) (res string, offset int, trunc
96100
if nextCnt >= 4 {
97101
break
98102
}
99-
nextWidth += ellipsisGuessDisplayWidth(r)
103+
nextWidth += widthGuess(r)
100104
nextCnt++
101105
}
102106
if nextCnt <= 3 && used+nextWidth <= limit {
@@ -114,6 +118,10 @@ func ellipsisDisplayString(str string, limit int) (res string, offset int, trunc
114118
return str[:offset] + ellipsis, offset, true, encounterInvalid
115119
}
116120

121+
func EllipsisTruncateRunes(str string, limit int) (left, right string) {
122+
return ellipsisDisplayStringX(str, limit, func(r rune) int { return 1 })
123+
}
124+
117125
// TruncateRunes returns a truncated string with given rune limit,
118126
// it returns input string if its rune length doesn't exceed the limit.
119127
func TruncateRunes(str string, limit int) string {

0 commit comments

Comments
 (0)