Skip to content

Commit 110afce

Browse files
committed
refactor
1 parent 12a9b8a commit 110afce

File tree

15 files changed

+191
-361
lines changed

15 files changed

+191
-361
lines changed

options/locale/locale_en-US.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,6 @@ delete_preexisting = Delete pre-existing files
891891
delete_preexisting_content = Delete files in %s
892892
delete_preexisting_success = Deleted unadopted files in %s
893893
blame_prior = View blame prior to this change
894-
filter_repo_files_no_matching = No matching files found
895894
896895
transfer.accept = Accept Transfer
897896
transfer.accept_desc = Transfer to "%s"
@@ -2285,6 +2284,9 @@ topic.done = Done
22852284
topic.count_prompt = You can not select more than 25 topics
22862285
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22872286

2287+
find_file.go_to_file = Go to file
2288+
find_file.no_matching = No matching file found
2289+
22882290
error.csv.too_large = Can't render this file because it is too large.
22892291
error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d.
22902292
error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d.
@@ -2976,7 +2978,6 @@ review_dismissed_reason = Reason:
29762978
create_branch = created branch <a href="%[2]s">%[3]s</a> in <a href="%[1]s">%[4]s</a>
29772979
starred_repo = starred <a href="%[1]s">%[2]s</a>
29782980
watched_repo = started watching <a href="%[1]s">%[2]s</a>
2979-
find_file = Go to file
29802981

29812982
[tool]
29822983
ago = %s ago

routers/api/v1/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,6 @@ func Routes() *web.Route {
826826
Put(reqAdmin(), repo.AddTeam).
827827
Delete(reqAdmin(), repo.DeleteTeam)
828828
}, reqToken())
829-
m.Get("/find/*", context.ReferencesGitRepo(), context.RepoRefForAPI, repo.GetRepoFiles)
830829
m.Get("/raw/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFile)
831830
m.Get("/media/*", context.ReferencesGitRepo(), context.RepoRefForAPI, reqRepoReader(unit.TypeCode), repo.GetRawFileOrLFS)
832831
m.Get("/archive/*", reqRepoReader(unit.TypeCode), repo.GetArchive)

routers/api/v1/repo/find_files.go

Lines changed: 0 additions & 118 deletions
This file was deleted.

routers/web/repo/find.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 The Gitea Authors. All rights reserved.
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
22
// Use of this source code is governed by a MIT-style
33
// license that can be found in the LICENSE file.
44

@@ -15,22 +15,8 @@ const (
1515

1616
// FindFiles render the page to find repository files
1717
func FindFiles(ctx *context.Context) {
18-
ctx.Data["PageIsFindFiles"] = true
19-
ctx.Data["PageIsViewCode"] = true
20-
21-
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
22-
treeLink := branchLink
23-
24-
if len(ctx.Repo.TreePath) > 0 {
25-
treeLink += "/" + ctx.Repo.TreePath
26-
}
27-
28-
ctx.Data["BranchName"] = ctx.Repo.BranchName
29-
ctx.Data["OwnerName"] = ctx.Repo.Owner.Name
30-
ctx.Data["RepoName"] = ctx.Repo.Repository.Name
31-
32-
ctx.Data["RepoLink"] = ctx.Repo.RepoLink
33-
ctx.Data["TreeLink"] = treeLink
34-
18+
path := ctx.Params("*")
19+
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + path
20+
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + path
3521
ctx.HTML(200, tplFindFiles)
3622
}

routers/web/repo/treelist.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2022 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package repo
6+
7+
import (
8+
"code.gitea.io/gitea/modules/base"
9+
"code.gitea.io/gitea/modules/context"
10+
"code.gitea.io/gitea/modules/git"
11+
"github.com/go-enry/go-enry/v2"
12+
"net/http"
13+
)
14+
15+
// TreeList get all files' entries of a repository
16+
func TreeList(ctx *context.Context) {
17+
tree, err := ctx.Repo.Commit.SubTree("/")
18+
if err != nil {
19+
ctx.ServerError("Repo.Commit.SubTree", err)
20+
return
21+
}
22+
23+
entries, err := tree.ListEntriesRecursive()
24+
if err != nil {
25+
ctx.ServerError("Repo.Commit.SubTree", err)
26+
return
27+
}
28+
entries.CustomSort(base.NaturalSortLess)
29+
30+
var files []string
31+
for _, entry := range entries {
32+
if !isExcludedEntry(entry) {
33+
files = append(files, entry.Name())
34+
}
35+
}
36+
ctx.JSON(http.StatusOK, files)
37+
}
38+
39+
func isExcludedEntry(entry *git.TreeEntry) bool {
40+
if entry.IsDir() {
41+
return true
42+
}
43+
44+
if entry.IsSubModule() {
45+
return true
46+
}
47+
48+
if enry.IsVendor(entry.Name()) {
49+
return true
50+
}
51+
52+
return false
53+
}

routers/web/web.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,12 @@ func RegisterRoutes(m *web.Route) {
831831
m.Group("/milestone", func() {
832832
m.Get("/{id}", repo.MilestoneIssuesAndPulls)
833833
}, reqRepoIssuesOrPullsReader, context.RepoRef())
834-
m.Get("/find/*", context.RepoRefByType(context.RepoRefBranch), repo.FindFiles)
834+
m.Get("/find/*", repo.FindFiles)
835+
m.Group("/tree-list", func() {
836+
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.TreeList)
837+
m.Get("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.TreeList)
838+
m.Get("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.TreeList)
839+
})
835840
m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
836841
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
837842
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).

templates/repo/find/files.tmpl

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11
{{template "base/head" .}}
2-
<div class="page-content repository file list">
2+
<div class="page-content repository">
33
{{template "repo/header" .}}
4-
<div class="ui container" id="repo-file-find-container">
5-
<input type="hidden" id="owner-name" value="{{.OwnerName}}">
6-
<input type="hidden" id="repo-name" value="{{.RepoName}}">
7-
<input type="hidden" id="branch-name" value="{{.BranchName}}">
8-
<input type="hidden" id="tree-link" value="{{.TreeLink}}">
9-
<div class="repo-title">
4+
<div class="ui container">
5+
<div class="df ac">
106
<a href="{{$.RepoLink}}">{{.RepoName}}</a>
117
<span class="mr-3 ml-3">/</span>
12-
<input id="repo-file-find-input" type="text" style="border:none;outline:none;" autofocus="autofocus">
8+
<div class="ui input f1">
9+
<input id="repo-file-find-input" type="text" autofocus data-url-data-link="{{.DataLink}}" data-url-tree-link="{{.TreeLink}}">
10+
</div>
1311
</div>
14-
<table id="repo-find-files-table" class="ui single line table">
12+
<table id="repo-find-file-table" class="ui single line table">
1513
<tbody>
16-
{{/* {{range $entry := .Files}}
17-
<tr>
18-
<td class="name four wide">
19-
<span class="truncate">
20-
{{svg (printf "octicon-%s" (EntryIcon $entry))}}
21-
<a class="find-file-name" href="{{EscapePound $.TreeLink}}/{{EscapePound $entry.Name}}" title="{{$entry.Name}}">{{$entry.Name}}</a>
22-
</span>
23-
</td>
24-
</tr>
25-
{{end}} */}}
2614
</tbody>
2715
</table>
28-
<div id="no-hit-prompt" class="ui row center" style="margin-top: 60px;display:none;">
29-
<h3>{{.i18n.Tr "repo.filter_repo_files_no_matching"}}</h3>
16+
<div id="repo-find-file-no-result" class="ui row center mt-5" style="display:none;">
17+
<h3>{{.i18n.Tr "repo.find_file.no_matching"}}</h3>
3018
</div>
3119
</div>
3220
</div>

templates/repo/home.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
</div>
7575
{{end}}
7676
<div class="fitted item mx-0">
77-
<a href="{{.BaseRepo.Link}}/find/{{.BranchName | PathEscapeSegments}}">
78-
<button id="go-to-file" class="ui compact basic button">{{.i18n.Tr "action.find_file"}}</button>
77+
<a href="{{.BaseRepo.Link}}/find/{{.BranchNameSubURL}}">
78+
<button id="go-to-file" class="ui compact basic button">{{.i18n.Tr "repo.find_file.go_to_file"}}</button>
7979
</a>
8080
</div>
8181
{{else}}

templates/swagger/v1_json.tmpl

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,46 +3732,6 @@
37323732
}
37333733
}
37343734
},
3735-
"/repos/{owner}/{repo}/find/{branchname}": {
3736-
"get": {
3737-
"produces": [
3738-
"application/json"
3739-
],
3740-
"tags": [
3741-
"repository"
3742-
],
3743-
"summary": "Get all files' entries of a repository",
3744-
"operationId": "repoFindFiles",
3745-
"parameters": [
3746-
{
3747-
"type": "string",
3748-
"description": "owner of the repo",
3749-
"name": "owner",
3750-
"in": "path",
3751-
"required": true
3752-
},
3753-
{
3754-
"type": "string",
3755-
"description": "name of the repo",
3756-
"name": "repo",
3757-
"in": "path",
3758-
"required": true
3759-
},
3760-
{
3761-
"type": "string",
3762-
"description": "branch name of the repo",
3763-
"name": "branchname",
3764-
"in": "path",
3765-
"required": true
3766-
}
3767-
],
3768-
"responses": {
3769-
"200": {
3770-
"description": "success"
3771-
}
3772-
}
3773-
}
3774-
},
37753735
"/repos/{owner}/{repo}/forks": {
37763736
"get": {
37773737
"produces": [

0 commit comments

Comments
 (0)