v0.8.1 b8e893f

browse.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6	"context"
7	"io"
8
9	"bnema.dev/ermite/internal/domain"
10	"bnema.dev/ermite/internal/ports"
11)
12
13// The reads of the pages go through BrowseService as the caller of the
14// request. The revisions and paths the URLs carry are text: they are parsed
15// here, and one the domain refuses is an invalid argument, which the pages
16// answer like a missing one (fail).
17
18// commitList reads a page of the history that starts at rev, limited to path
19// when it is not empty.
20func (s *Server) commitList(ctx context.Context, repo domain.RepoName, rev, path string, size int, token string) (ports.HistoryPage, error) {
21	r, err := domain.ParseRevision(rev)
22	if err != nil {
23		return ports.HistoryPage{}, err
24	}
25	p, err := domain.ParseTreePath(path)
26	if err != nil {
27		return ports.HistoryPage{}, err
28	}
29	return s.cfg.Browse.ListCommits(ctx, principal(ctx), repo, ports.ListCommitsParams{
30		Revision: r, Path: p, PageSize: size, PageToken: token,
31	})
32}
33
34// getTree lists the directory path of the commit rev.
35func (s *Server) getTree(ctx context.Context, repo domain.RepoName, rev, path string, lastCommit bool) (domain.Tree, error) {
36	r, err := domain.ParseRevision(rev)
37	if err != nil {
38		return domain.Tree{}, err
39	}
40	p, err := domain.ParseTreePath(path)
41	if err != nil {
42		return domain.Tree{}, err
43	}
44	return s.cfg.Browse.GetTree(ctx, principal(ctx), repo, r, p, lastCommit)
45}
46
47// getCommit reads a commit with its diff.
48func (s *Server) getCommit(ctx context.Context, repo domain.RepoName, rev string) (domain.CommitDetail, error) {
49	r, err := domain.ParseRevision(rev)
50	if err != nil {
51		return domain.CommitDetail{}, err
52	}
53	return s.cfg.Browse.GetCommit(ctx, principal(ctx), repo, r)
54}
55
56// openBlobAt opens the file path of the commit rev. The caller closes the
57// body.
58func (s *Server) openBlobAt(ctx context.Context, repo domain.RepoName, rev, path string) (domain.BlobInfo, io.ReadCloser, error) {
59	r, err := domain.ParseRevision(rev)
60	if err != nil {
61		return domain.BlobInfo{}, nil, err
62	}
63	if path == "" {
64		return domain.BlobInfo{}, nil, errNotFound
65	}
66	p, err := domain.ParseTreePath(path)
67	if err != nil {
68		return domain.BlobInfo{}, nil, err
69	}
70	return s.cfg.Browse.OpenBlob(ctx, principal(ctx), repo, r, p)
71}
72
73// resolveRevision resolves rev to the commit it designates.
74//
75//hexcheck:ignore suspicious-business-logic-in-adapter parses the URL text and calls the use case; no rule is decided here
76func (s *Server) resolveRevision(ctx context.Context, repo domain.RepoName, rev string) (domain.ResolvedRevision, error) {
77	r, err := domain.ParseRevision(rev)
78	if err != nil {
79		return domain.ResolvedRevision{}, err
80	}
81	return s.cfg.Browse.ResolveRevision(ctx, principal(ctx), repo, r)
82}
83
84// listPaths lists the file paths of the commit rev.
85func (s *Server) listPaths(ctx context.Context, repo domain.RepoName, rev string) (domain.PathList, error) {
86	r, err := domain.ParseRevision(rev)
87	if err != nil {
88		return domain.PathList{}, err
89	}
90	return s.cfg.Browse.ListPaths(ctx, principal(ctx), repo, r)
91}

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