detached 3483340

commitobjects.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package ermitegit
4
5import (
6	"context"
7	"errors"
8	"fmt"
9
10	git "bnema.dev/ermite-git"
11
12	"bnema.dev/ermite/internal/domain"
13	"bnema.dev/ermite/internal/ports"
14)
15
16var _ ports.CommitObjectReader = (*Adapter)(nil)
17
18// ReadCommitObjects reads the raw content of commits with ermite-git. Ids that
19// are missing, are not commits, or are larger than
20// domain.MaxCommitObjectBytes are left out. The read ends at the first commit
21// that would take the total over domain.MaxCommitObjectsBytes. It is not routable: the library
22// always serves it, and the wrapped reader only the repositories the library
23// cannot read.
24//
25//hexcheck:ignore suspicious-business-logic-in-adapter streams object headers and bytes; eligibility, deduplication and byte limits are decided by domain.CommitObjectBudget, request validation by domain.ValidateCommitObjects
26func (a *Adapter) ReadCommitObjects(ctx context.Context, repo domain.RepoName, ids []domain.ObjectID) (map[domain.ObjectID][]byte, error) {
27	if err := domain.ValidateCommitObjects(ids, ports.MaxCommitLimit); err != nil {
28		return nil, err
29	}
30	cli := func() (map[domain.ObjectID][]byte, error) {
31		r, ok := a.cli.(ports.CommitObjectReader)
32		if !ok {
33			return nil, fmt.Errorf("read commit objects of %q: the wrapped reader cannot read commit objects", repo)
34		}
35		return r.ReadCommitObjects(ctx, repo, ids)
36	}
37	return serve(ctx, a, repo, func(r *git.Repo) (map[domain.ObjectID][]byte, error) {
38		out := make(map[domain.ObjectID][]byte, len(ids))
39		var budget domain.CommitObjectBudget
40		for _, id := range ids {
41			if err := ctx.Err(); err != nil {
42				return nil, err
43			}
44			if budget.Seen(id) {
45				continue
46			}
47			gid, err := git.ParseID(id.String())
48			if err != nil {
49				return nil, err
50			}
51			typ, size, err := r.ObjectHeader(gid)
52			if errors.Is(err, git.ErrNotFound) {
53				continue
54			}
55			if err != nil {
56				return nil, err
57			}
58			take, stop := budget.Admit(id, typ == git.TypeCommit, size)
59			if stop {
60				break
61			}
62			if !take {
63				continue
64			}
65			typ, data, err := r.ReadObject(gid, nil)
66			if errors.Is(err, git.ErrNotFound) {
67				continue // removed meanwhile
68			}
69			if err != nil {
70				return nil, err
71			}
72			if take, _ := budget.Admit(id, typ == git.TypeCommit, int64(len(data))); take {
73				out[id] = data
74				budget.Charge(id, int64(len(data)))
75			}
76		}
77		return out, nil
78	}, cli)
79}

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 4

Tags 45

↑↓ moveenter openesc close