detached 806d83d

refactor(ermitegit): move tree route selection onto Routes

commit
806d83dcf803abc84fc6becea3b31f7bd1c32ba1
author
brice · · 2026-10-11 18:43 UTC
parent
4fbe895
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +13 -8
M internal/adapters/ermitegit/ermitegit.go +13 -8
@@ -100,6 +100,18 @@ type Routes struct {
100100 ListCommitsPath Backend
101101 }
102102
103+// tree picks the route of a directory listing.
104+func (r Routes) tree(path domain.TreePath, lastCommits bool) Backend {
105+ switch {
106+ case !lastCommits:
107+ return r.GetTree
108+ case path.IsRoot():
109+ return r.GetTreeLastCommits
110+ default:
111+ return r.GetTreeSubdirLastCommits
112+ }
113+}
114+
103115 // AllRoutes returns routes that send every method to b. The tests and the
104116 // benchmarks use it to exercise a backend whatever the production routes are.
105117 func AllRoutes(b Backend) Routes {
@@ -322,14 +334,7 @@ func (a *Adapter) ResolveRefPath(ctx context.Context, repo domain.RepoName, path
322334 // GetTree lists a directory.
323335 func (a *Adapter) GetTree(ctx context.Context, repo domain.RepoName, rev domain.Revision, path domain.TreePath, includeLastCommit bool) (domain.Tree, error) {
324336 cli := func() (domain.Tree, error) { return a.cli.GetTree(ctx, repo, rev, path, includeLastCommit) }
325- route := a.routes.GetTree
326- if includeLastCommit {
327- route = a.routes.GetTreeSubdirLastCommits
328- if path.IsRoot() {
329- route = a.routes.GetTreeLastCommits
330- }
331- }
332- if route == CLI {
337+ if a.routes.tree(path, includeLastCommit) == CLI {
333338 return cli()
334339 }
335340 return serve(ctx, a, repo, func(r *git.Repo) (domain.Tree, error) {
@@ -100,6 +100,18 @@ type Routes struct {
100 ListCommitsPath Backend100 ListCommitsPath Backend
101 }101 }
102 102
103+// tree picks the route of a directory listing.
104+func (r Routes) tree(path domain.TreePath, lastCommits bool) Backend {
105+ switch {
106+ case !lastCommits:
107+ return r.GetTree
108+ case path.IsRoot():
109+ return r.GetTreeLastCommits
110+ default:
111+ return r.GetTreeSubdirLastCommits
112+ }
113+}
114+
103 // AllRoutes returns routes that send every method to b. The tests and the115 // AllRoutes returns routes that send every method to b. The tests and the
104 // benchmarks use it to exercise a backend whatever the production routes are.116 // benchmarks use it to exercise a backend whatever the production routes are.
105 func AllRoutes(b Backend) Routes {117 func AllRoutes(b Backend) Routes {
@@ -322,14 +334,7 @@ func (a *Adapter) ResolveRefPath(ctx context.Context, repo domain.RepoName, path
322 // GetTree lists a directory.334 // GetTree lists a directory.
323 func (a *Adapter) GetTree(ctx context.Context, repo domain.RepoName, rev domain.Revision, path domain.TreePath, includeLastCommit bool) (domain.Tree, error) {335 func (a *Adapter) GetTree(ctx context.Context, repo domain.RepoName, rev domain.Revision, path domain.TreePath, includeLastCommit bool) (domain.Tree, error) {
324 cli := func() (domain.Tree, error) { return a.cli.GetTree(ctx, repo, rev, path, includeLastCommit) }336 cli := func() (domain.Tree, error) { return a.cli.GetTree(ctx, repo, rev, path, includeLastCommit) }
325- route := a.routes.GetTree337+ if a.routes.tree(path, includeLastCommit) == CLI {
326- if includeLastCommit {
327- route = a.routes.GetTreeSubdirLastCommits
328- if path.IsRoot() {
329- route = a.routes.GetTreeLastCommits
330- }
331- }
332- if route == CLI {
333 return cli()338 return cli()
334 }339 }
335 return serve(ctx, a, repo, func(r *git.Repo) (domain.Tree, error) {340 return serve(ctx, a, repo, func(r *git.Repo) (domain.Tree, error) {

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 2

Tags 45

↑↓ moveenter openesc close