Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions modules/base/natural_sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func naturalSortAdvance(str string, pos int) (end int, isNumber bool) {
return end, isNumber
}

// NaturalSortLess compares two strings so that they could be sorted in natural order
func NaturalSortLess(s1, s2 string) bool {
// NaturalSortCompare compares two strings so that they could be sorted in natural order
func NaturalSortCompare(s1, s2 string) int {
// There is a bug in Golang's collate package: https://github.com/golang/go/issues/67997
// text/collate: CompareString(collate.Numeric) returns wrong result for "0.0" vs "1.0" #67997
// So we need to handle the number parts by ourselves
Expand All @@ -55,16 +55,16 @@ func NaturalSortLess(s1, s2 string) bool {
if isNum1 && isNum2 {
if part1 != part2 {
if len(part1) != len(part2) {
return len(part1) < len(part2)
return len(part1) - len(part2)
}
return part1 < part2
return c.CompareString(part1, part2)
}
} else {
if cmp := c.CompareString(part1, part2); cmp != 0 {
return cmp < 0
return cmp
}
}
pos1, pos2 = end1, end2
}
return len(s1) < len(s2)
return len(s1) - len(s2)
}
6 changes: 2 additions & 4 deletions modules/base/natural_sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import (

func TestNaturalSortLess(t *testing.T) {
testLess := func(s1, s2 string) {
assert.True(t, NaturalSortLess(s1, s2), "s1<s2 should be true: s1=%q, s2=%q", s1, s2)
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2)
assert.Negative(t, NaturalSortCompare(s1, s2), "s1<s2 should be true: s1=%q, s2=%q", s1, s2)
}
testEqual := func(s1, s2 string) {
assert.False(t, NaturalSortLess(s1, s2), "s1<s2 should be false: s1=%q, s2=%q", s1, s2)
assert.False(t, NaturalSortLess(s2, s1), "s2<s1 should be false: s1=%q, s2=%q", s1, s2)
assert.Zero(t, NaturalSortCompare(s1, s2), "s1<s2 should be false: s1=%q, s2=%q", s1, s2)
}

testEqual("", "")
Expand Down
1 change: 0 additions & 1 deletion modules/git/commit_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
} else if entries, err = commit.Tree.ListEntries(); err != nil {
b.Fatal(err)
}
entries.Sort()
b.ResetTimer()
b.Run(benchmark.name, func(b *testing.B) {
for b.Loop() {
Expand Down
7 changes: 6 additions & 1 deletion modules/git/notes_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package git

import (
"context"
"fmt"
"io"

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

remainingCommitID := commitID
path := ""
currentTree := notes.Tree.gogitTree
currentTree, err := notes.Tree.gogitTreeObject()
if err != nil {
return fmt.Errorf("unable to get tree object for notes commit %q: %w", notes.ID.String(), err)
}

log.Trace("Found tree with ID %q while searching for git note corresponding to the commit %q", currentTree.Entries[0].Name, commitID)
var file *object.File
for len(remainingCommitID) > 2 {
Expand Down
96 changes: 0 additions & 96 deletions modules/git/parse_gogit.go

This file was deleted.

78 changes: 0 additions & 78 deletions modules/git/parse_gogit_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build !gogit

package git

import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//go:build !gogit

package git

import (
Expand Down
2 changes: 1 addition & 1 deletion modules/git/repo_commit_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (repo *Repository) getCommit(id ObjectID) (*Commit, error) {
}

commit.Tree.ID = ParseGogitHash(tree.Hash)
commit.Tree.gogitTree = tree
commit.Tree.resolvedGogitTreeObject = tree

return commit, nil
}
2 changes: 1 addition & 1 deletion modules/git/repo_tree_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (repo *Repository) getTree(id ObjectID) (*Tree, error) {
}

tree := NewTree(repo, id)
tree.gogitTree = gogitTree
tree.resolvedGogitTreeObject = gogitTree
return tree, nil
}

Expand Down
14 changes: 12 additions & 2 deletions modules/git/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ import (
"code.gitea.io/gitea/modules/git/gitcmd"
)

type TreeCommon struct {
ID ObjectID
ResolvedID ObjectID

repo *Repository
ptree *Tree // parent tree
}

// NewTree create a new tree according the repository and tree id
func NewTree(repo *Repository, id ObjectID) *Tree {
return &Tree{
ID: id,
repo: repo,
TreeCommon: TreeCommon{
ID: id,
repo: repo,
},
}
}

Expand Down
14 changes: 4 additions & 10 deletions modules/git/tree_blob_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ import (
"strings"

"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/object"
)

// GetTreeEntryByPath get the tree entries according the sub dir
func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
if len(relpath) == 0 {
return &TreeEntry{
ID: t.ID,
// Type: ObjectTree,
ptree: t,
gogitTreeEntry: &object.TreeEntry{
Name: "",
Mode: filemode.Dir,
Hash: plumbing.Hash(t.ID.RawValue()),
},
ID: t.ID,
ptree: t,
name: "",
entryMode: EntryModeTree,
}, nil
}

Expand Down
Loading