Skip to content

Commit

Permalink
Use the old infrustructure about getting refullname
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Jan 14, 2025
1 parent 4890434 commit bdd78df
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 24 deletions.
13 changes: 0 additions & 13 deletions modules/git/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions routers/web/repo/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions templates/repo/view_file_tree_sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
5 changes: 2 additions & 3 deletions web_src/js/features/repo-view-file-tree-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down

0 comments on commit bdd78df

Please sign in to comment.