Skip to content

Commit 847b023

Browse files
committed
fix
1 parent a0f492d commit 847b023

24 files changed

+192
-449
lines changed

modules/base/natural_sort.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func naturalSortAdvance(str string, pos int) (end int, isNumber bool) {
4141
return end, isNumber
4242
}
4343

44-
// NaturalSortLess compares two strings so that they could be sorted in natural order
45-
func NaturalSortLess(s1, s2 string) bool {
44+
// NaturalSortCompare compares two strings so that they could be sorted in natural order
45+
func NaturalSortCompare(s1, s2 string) int {
4646
// There is a bug in Golang's collate package: https://github.com/golang/go/issues/67997
4747
// text/collate: CompareString(collate.Numeric) returns wrong result for "0.0" vs "1.0" #67997
4848
// So we need to handle the number parts by ourselves
@@ -55,16 +55,16 @@ func NaturalSortLess(s1, s2 string) bool {
5555
if isNum1 && isNum2 {
5656
if part1 != part2 {
5757
if len(part1) != len(part2) {
58-
return len(part1) < len(part2)
58+
return len(part1) - len(part2)
5959
}
60-
return part1 < part2
60+
return c.CompareString(part1, part2)
6161
}
6262
} else {
6363
if cmp := c.CompareString(part1, part2); cmp != 0 {
64-
return cmp < 0
64+
return cmp
6565
}
6666
}
6767
pos1, pos2 = end1, end2
6868
}
69-
return len(s1) < len(s2)
69+
return len(s1) - len(s2)
7070
}

modules/base/natural_sort_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111

1212
func TestNaturalSortLess(t *testing.T) {
1313
testLess := func(s1, s2 string) {
14-
assert.True(t, NaturalSortLess(s1, s2), "s1<s2 should be true: s1=%q, s2=%q", s1, s2)
15-
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2)
14+
assert.Negative(t, NaturalSortCompare(s1, s2), "s1<s2 should be true: s1=%q, s2=%q", s1, s2)
1615
}
1716
testEqual := func(s1, s2 string) {
18-
assert.False(t, NaturalSortLess(s1, s2), "s1<s2 should be false: s1=%q, s2=%q", s1, s2)
19-
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2)
17+
assert.Zero(t, NaturalSortCompare(s1, s2), "s1<s2 should be false: s1=%q, s2=%q", s1, s2)
2018
}
2119

2220
testEqual("", "")

modules/git/commit_info_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
173173
} else if entries, err = commit.Tree.ListEntries(); err != nil {
174174
b.Fatal(err)
175175
}
176-
entries.Sort()
177176
b.ResetTimer()
178177
b.Run(benchmark.name, func(b *testing.B) {
179178
for b.Loop() {

modules/git/notes_gogit.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package git
77

88
import (
99
"context"
10+
"fmt"
1011
"io"
1112

1213
"code.gitea.io/gitea/modules/log"
@@ -30,7 +31,11 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
3031

3132
remainingCommitID := commitID
3233
path := ""
33-
currentTree := notes.Tree.gogitTree
34+
currentTree, err := notes.Tree.gogitTreeObject()
35+
if err != nil {
36+
return fmt.Errorf("unable to get tree object for notes commit %q: %w", notes.ID.String(), err)
37+
}
38+
3439
log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", currentTree.Entries[0].Name, commitID)
3540
var file *object.File
3641
for len(remainingCommitID) > 2 {

modules/git/parse_gogit.go

Lines changed: 0 additions & 96 deletions
This file was deleted.

modules/git/parse_gogit_test.go

Lines changed: 0 additions & 78 deletions
This file was deleted.

modules/git/parse_nogogit.go renamed to modules/git/parse_treeentry.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2018 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//go:build !gogit
5-
64
package git
75

86
import (

modules/git/parse_nogogit_test.go renamed to modules/git/parse_treeentry_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2021 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4-
//go:build !gogit
5-
64
package git
75

86
import (

modules/git/repo_commit_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
107107
}
108108

109109
commit.Tree.ID = ParseGogitHash(tree.Hash)
110-
commit.Tree.gogitTree = tree
110+
commit.Tree.resolvedGogitTreeObject = tree
111111

112112
return commit, nil
113113
}

modules/git/repo_tree_gogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
2626
}
2727

2828
tree := NewTree(repo, id)
29-
tree.gogitTree = gogitTree
29+
tree.resolvedGogitTreeObject = gogitTree
3030
return tree, nil
3131
}
3232

0 commit comments

Comments
 (0)