refactor(ermitegit): move tree route selection onto Routes
- commit
- 806d83dcf803abc84fc6becea3b31f7bd1c32ba1
- author
- brice · · 2026-10-11 18:43 UTC
- parent
- 4fbe895
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· 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 { | |||
| 100 | 100 | 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 | 115 | // AllRoutes returns routes that send every method to b. The tests and the | |
| 104 | 116 | // benchmarks use it to exercise a backend whatever the production routes are. | |
| 105 | 117 | func AllRoutes(b Backend) Routes { | |
| @@ -322,14 +334,7 @@ func (a *Adapter) ResolveRefPath(ctx context.Context, repo domain.RepoName, path | |||
| 322 | 334 | // GetTree lists a directory. | |
| 323 | 335 | func (a *Adapter) GetTree(ctx context.Context, repo domain.RepoName, rev domain.Revision, path domain.TreePath, includeLastCommit bool) (domain.Tree, error) { | |
| 324 | 336 | 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 { | |
| 333 | 338 | return cli() | |
| 334 | 339 | } | |
| 335 | 340 | return serve(ctx, a, repo, func(r *git.Repo) (domain.Tree, error) { | |
| @@ -100,6 +100,18 @@ type Routes struct { | |||||
| 100 | ListCommitsPath Backend | 100 | 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 the | 115 | // 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.GetTree | 337 | + | 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) { | ||