mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-20 19:08:29 +02:00
improvement
This commit is contained in:
parent
abf95a76db
commit
9dfdb4fc08
@ -65,9 +65,9 @@ func Tree(ctx *context.Context) {
|
|||||||
var results []*files_service.TreeViewNode
|
var results []*files_service.TreeViewNode
|
||||||
var err error
|
var err error
|
||||||
if !recursive {
|
if !recursive {
|
||||||
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, ctx.Repo.TreePath, ctx.Repo.RefFullName, false)
|
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.TreePath, ctx.Repo.RefFullName, false)
|
||||||
} else {
|
} else {
|
||||||
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, ctx.Repo.TreePath, ctx.Repo.RefFullName)
|
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, ctx.Repo.TreePath, ctx.Repo.RefFullName)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetTreeInformation", err)
|
ctx.ServerError("GetTreeInformation", err)
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/gitrepo"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
@ -194,7 +193,7 @@ Example 3: (path: d3/d3d1)
|
|||||||
"path": "d3/d3d1/d3d1f2"
|
"path": "d3/d3d1/d3d1f2"
|
||||||
}]
|
}]
|
||||||
*/
|
*/
|
||||||
func GetTreeList(ctx context.Context, repo *repo_model.Repository, treePath string, ref git.RefName, recursive bool) ([]*TreeViewNode, error) {
|
func GetTreeList(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, treePath string, ref git.RefName, recursive bool) ([]*TreeViewNode, error) {
|
||||||
if repo.IsEmpty {
|
if repo.IsEmpty {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -211,12 +210,6 @@ func GetTreeList(ctx context.Context, repo *repo_model.Repository, treePath stri
|
|||||||
}
|
}
|
||||||
treePath = cleanTreePath
|
treePath = cleanTreePath
|
||||||
|
|
||||||
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer closer.Close()
|
|
||||||
|
|
||||||
// Get the commit object for the ref
|
// Get the commit object for the ref
|
||||||
commit, err := gitRepo.GetCommit(ref.String())
|
commit, err := gitRepo.GetCommit(ref.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -390,7 +383,7 @@ Example 4: (path: d2/d2f1)
|
|||||||
"path": "f1"
|
"path": "f1"
|
||||||
},]
|
},]
|
||||||
*/
|
*/
|
||||||
func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePath string, ref git.RefName) ([]*TreeViewNode, error) {
|
func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, treePath string, ref git.RefName) ([]*TreeViewNode, error) {
|
||||||
if repo.IsEmpty {
|
if repo.IsEmpty {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -407,12 +400,6 @@ func GetTreeInformation(ctx context.Context, repo *repo_model.Repository, treePa
|
|||||||
}
|
}
|
||||||
treePath = cleanTreePath
|
treePath = cleanTreePath
|
||||||
|
|
||||||
gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer closer.Close()
|
|
||||||
|
|
||||||
// Get the commit object for the ref
|
// Get the commit object for the ref
|
||||||
commit, err := gitRepo.GetCommit(ref.String())
|
commit, err := gitRepo.GetCommit(ref.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,7 +63,7 @@ func Test_GetTreeList(t *testing.T) {
|
|||||||
|
|
||||||
refName := git.RefNameFromBranch(ctx1.Repo.Repository.DefaultBranch)
|
refName := git.RefNameFromBranch(ctx1.Repo.Repository.DefaultBranch)
|
||||||
|
|
||||||
treeList, err := GetTreeList(ctx1, ctx1.Repo.Repository, "", refName, true)
|
treeList, err := GetTreeList(ctx1, ctx1.Repo.Repository, ctx1.Repo.GitRepo, "", refName, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 1)
|
assert.Len(t, treeList, 1)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Name)
|
assert.EqualValues(t, "README.md", treeList[0].Name)
|
||||||
@ -80,7 +80,7 @@ func Test_GetTreeList(t *testing.T) {
|
|||||||
|
|
||||||
refName = git.RefNameFromBranch(ctx2.Repo.Repository.DefaultBranch)
|
refName = git.RefNameFromBranch(ctx2.Repo.Repository.DefaultBranch)
|
||||||
|
|
||||||
treeList, err = GetTreeList(ctx2, ctx2.Repo.Repository, "", refName, true)
|
treeList, err = GetTreeList(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "", refName, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
|
|
||||||
refName := git.RefNameFromBranch(ctx1.Repo.Repository.DefaultBranch)
|
refName := git.RefNameFromBranch(ctx1.Repo.Repository.DefaultBranch)
|
||||||
|
|
||||||
treeList, err := GetTreeInformation(ctx1, ctx1.Repo.Repository, "", refName)
|
treeList, err := GetTreeInformation(ctx1, ctx1.Repo.Repository, ctx1.Repo.GitRepo, "", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 1)
|
assert.Len(t, treeList, 1)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Name)
|
assert.EqualValues(t, "README.md", treeList[0].Name)
|
||||||
@ -119,7 +119,7 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
assert.EqualValues(t, "blob", treeList[0].Type)
|
assert.EqualValues(t, "blob", treeList[0].Type)
|
||||||
assert.Empty(t, treeList[0].Children)
|
assert.Empty(t, treeList[0].Children)
|
||||||
|
|
||||||
treeList, err = GetTreeInformation(ctx1, ctx1.Repo.Repository, "README.md", refName)
|
treeList, err = GetTreeInformation(ctx1, ctx1.Repo.Repository, ctx1.Repo.GitRepo, "README.md", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 1)
|
assert.Len(t, treeList, 1)
|
||||||
assert.EqualValues(t, "README.md", treeList[0].Name)
|
assert.EqualValues(t, "README.md", treeList[0].Name)
|
||||||
@ -136,7 +136,7 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
|
|
||||||
refName = git.RefNameFromBranch(ctx2.Repo.Repository.DefaultBranch)
|
refName = git.RefNameFromBranch(ctx2.Repo.Repository.DefaultBranch)
|
||||||
|
|
||||||
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "", refName)
|
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
assert.EqualValues(t, "blob", treeList[1].Type)
|
assert.EqualValues(t, "blob", treeList[1].Type)
|
||||||
assert.Empty(t, treeList[1].Children)
|
assert.Empty(t, treeList[1].Children)
|
||||||
|
|
||||||
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc", refName)
|
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "doc", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
assert.EqualValues(t, "doc", treeList[0].Name)
|
assert.EqualValues(t, "doc", treeList[0].Name)
|
||||||
@ -168,7 +168,7 @@ func Test_GetTreeInformation(t *testing.T) {
|
|||||||
assert.EqualValues(t, "blob", treeList[1].Type)
|
assert.EqualValues(t, "blob", treeList[1].Type)
|
||||||
assert.Empty(t, treeList[1].Children)
|
assert.Empty(t, treeList[1].Children)
|
||||||
|
|
||||||
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, "doc/doc.md", refName)
|
treeList, err = GetTreeInformation(ctx2, ctx2.Repo.Repository, ctx2.Repo.GitRepo, "doc/doc.md", refName)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, treeList, 2)
|
assert.Len(t, treeList, 2)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user