Skip to content

Commit fd25c32

Browse files
committed
fix
1 parent a0f492d commit fd25c32

16 files changed

+128
-363
lines changed

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.
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 (
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

modules/git/tree.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@ import (
1111
"code.gitea.io/gitea/modules/git/gitcmd"
1212
)
1313

14+
type TreeCommon struct {
15+
ID ObjectID
16+
ResolvedID ObjectID
17+
18+
repo *Repository
19+
ptree *Tree // parent tree
20+
}
21+
1422
// NewTree create a new tree according the repository and tree id
1523
func NewTree(repo *Repository, id ObjectID) *Tree {
1624
return &Tree{
17-
ID: id,
18-
repo: repo,
25+
TreeCommon: TreeCommon{
26+
ID: id,
27+
repo: repo,
28+
},
1929
}
2030
}
2131

modules/git/tree_blob_gogit.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@ import (
1111
"strings"
1212

1313
"github.com/go-git/go-git/v5/plumbing"
14-
"github.com/go-git/go-git/v5/plumbing/filemode"
15-
"github.com/go-git/go-git/v5/plumbing/object"
1614
)
1715

1816
// GetTreeEntryByPath get the tree entries according the sub dir
1917
func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
2018
if len(relpath) == 0 {
2119
return &TreeEntry{
22-
ID: t.ID,
23-
// Type: ObjectTree,
24-
ptree: t,
25-
gogitTreeEntry: &object.TreeEntry{
26-
Name: "",
27-
Mode: filemode.Dir,
28-
Hash: plumbing.Hash(t.ID.RawValue()),
29-
},
20+
ID: t.ID,
21+
ptree: t,
22+
name: "",
23+
entryMode: EntryModeTree,
3024
}, nil
3125
}
3226

modules/git/tree_entry.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,54 @@ import (
1212
"code.gitea.io/gitea/modules/util"
1313
)
1414

15+
// TreeEntry the leaf in the git tree
16+
type TreeEntry struct {
17+
ID ObjectID
18+
19+
name string
20+
ptree *Tree
21+
22+
entryMode EntryMode
23+
24+
size int64
25+
sized bool
26+
}
27+
28+
// Name returns the name of the entry (base name)
29+
func (te *TreeEntry) Name() string {
30+
return te.name
31+
}
32+
33+
// Mode returns the mode of the entry
34+
func (te *TreeEntry) Mode() EntryMode {
35+
return te.entryMode
36+
}
37+
38+
// IsSubModule if the entry is a submodule
39+
func (te *TreeEntry) IsSubModule() bool {
40+
return te.entryMode.IsSubModule()
41+
}
42+
43+
// IsDir if the entry is a sub dir
44+
func (te *TreeEntry) IsDir() bool {
45+
return te.entryMode.IsDir()
46+
}
47+
48+
// IsLink if the entry is a symlink
49+
func (te *TreeEntry) IsLink() bool {
50+
return te.entryMode.IsLink()
51+
}
52+
53+
// IsRegular if the entry is a regular file
54+
func (te *TreeEntry) IsRegular() bool {
55+
return te.entryMode.IsRegular()
56+
}
57+
58+
// IsExecutable if the entry is an executable file (not necessarily binary)
59+
func (te *TreeEntry) IsExecutable() bool {
60+
return te.entryMode.IsExecutable()
61+
}
62+
1563
// Type returns the type of the entry (commit, tree, blob)
1664
func (te *TreeEntry) Type() string {
1765
switch te.Mode() {

0 commit comments

Comments
 (0)