mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-18 06:32:51 +02:00
Use the old infrustructure about getting refullname
This commit is contained in:
parent
4890434b1e
commit
bdd78dfdcb
@ -84,19 +84,6 @@ func RefNameFromCommit(shortName string) RefName {
|
||||
return RefName(shortName)
|
||||
}
|
||||
|
||||
func RefNameFromTypeAndShortName(tp RefType, shortName string) RefName {
|
||||
switch tp {
|
||||
case RefTypeBranch:
|
||||
return RefNameFromBranch(shortName)
|
||||
case RefTypeTag:
|
||||
return RefNameFromTag(shortName)
|
||||
case RefTypeCommit:
|
||||
return RefNameFromCommit(shortName)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func (ref RefName) String() string {
|
||||
return string(ref)
|
||||
}
|
||||
|
@ -55,20 +55,19 @@ func isExcludedEntry(entry *git.TreeEntry) bool {
|
||||
}
|
||||
|
||||
func Tree(ctx *context.Context) {
|
||||
treePath := ctx.PathParam("*")
|
||||
recursive := ctx.FormBool("recursive")
|
||||
refFullName := git.RefNameFromTypeAndShortName(git.RefType(ctx.FormTrim("ref_type")), ctx.FormTrim("ref_name"))
|
||||
if refFullName == "" {
|
||||
ctx.Error(http.StatusBadRequest, "RefNameFromTypeAndShortName", "ref_type or ref_name is invalid")
|
||||
|
||||
if ctx.Repo.RefFullName == "" {
|
||||
ctx.Error(http.StatusBadRequest, "RefFullName", "ref_name is invalid")
|
||||
return
|
||||
}
|
||||
|
||||
var results []*files_service.TreeViewNode
|
||||
var err error
|
||||
if !recursive {
|
||||
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, treePath, refFullName, false)
|
||||
results, err = files_service.GetTreeList(ctx, ctx.Repo.Repository, ctx.Repo.TreePath, ctx.Repo.RefFullName, false)
|
||||
} else {
|
||||
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, treePath, refFullName)
|
||||
results, err = files_service.GetTreeInformation(ctx, ctx.Repo.Repository, ctx.Repo.TreePath, ctx.Repo.RefFullName)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.ServerError("GetTreeInformation", err)
|
||||
|
@ -1163,8 +1163,9 @@ func registerRoutes(m *web.Router) {
|
||||
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
|
||||
})
|
||||
m.Group("/tree", func() {
|
||||
m.Get("", repo.Tree)
|
||||
m.Get("/*", repo.Tree)
|
||||
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Tree)
|
||||
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.Tree)
|
||||
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.Tree)
|
||||
})
|
||||
m.Get("/compare", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
|
||||
m.Combo("/compare/*", repo.MustBeNotEmpty, repo.SetEditorconfigIfExists).
|
||||
|
@ -13,5 +13,6 @@
|
||||
data-tree-path="{{$.TreePath}}"
|
||||
data-current-ref-type="{{.RefFullName.RefType}}"
|
||||
data-current-ref-short-name="{{.RefFullName.ShortName}}"
|
||||
data-current-ref-type-name-sub-url="{{.RefTypeNameSubURL}}"
|
||||
></div>
|
||||
</div>
|
||||
|
@ -31,9 +31,8 @@ async function toggleSidebar(visibility, isSigned) {
|
||||
async function loadChildren(item, recursive?: boolean) {
|
||||
const fileTree = document.querySelector('#view-file-tree');
|
||||
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
|
||||
const refType = fileTree.getAttribute('data-current-ref-type');
|
||||
const refName = fileTree.getAttribute('data-current-ref-short-name');
|
||||
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?ref_type=${refType}&ref_name=${refName}&recursive=${recursive ?? false}`);
|
||||
const refTypeNameSubURL = fileTree.getAttribute('data-current-ref-type-name-sub-url');
|
||||
const response = await GET(`${apiBaseUrl}/tree/${refTypeNameSubURL}/${item ? item.path : ''}?recursive=${recursive ?? false}`);
|
||||
const json = await response.json();
|
||||
if (json instanceof Array) {
|
||||
return json.map((i) => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user