v0.36.0 1fb2421

releases_index.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2package kvstore
3
4import (
5	"context"
6	"fmt"
7	"strconv"
8
9	kv "bnema.dev/ermite-kv"
10	"bnema.dev/ermite/internal/domain"
11)
12
13const releaseLatestIndexMarker = "meta/release-latest-index"
14
15// buildReleaseLatestIndex runs before the store is exposed to writers. A crash
16// before the marker is written safely repeats the pass on the next open.
17// Selection remains owned by domain.LatestRelease.
18func (s *Store) buildReleaseLatestIndex(ctx context.Context) error {
19	if _, ok := s.db.Get(ctx, []byte(releaseLatestIndexMarker)); ok {
20		return nil
21	}
22	var repo domain.RepoName
23	var best domain.Release
24	var eligible bool
25	flush := func() error {
26		var b kv.Batch
27		if eligible {
28			b.Put(relLatestKey(repo), []byte(strconv.FormatInt(best.ID, 10)))
29		} else {
30			b.Delete(relLatestKey(repo))
31		}
32		if _, err := s.db.Apply(ctx, &b); err != nil {
33			return fmt.Errorf("build latest release index: %w", err)
34		}
35		return nil
36	}
37	haveRepo := false
38	for _, item := range s.db.Snapshot(ctx).Prefix(ctx, []byte("rel/")) {
39		rel, err := decodeRelease(item)
40		if err != nil {
41			return fmt.Errorf("build latest release index: %w", err)
42		}
43		if haveRepo && rel.Repo != repo {
44			if err := flush(); err != nil {
45				return err
46			}
47			best, eligible = domain.Release{}, false
48		}
49		repo, haveRepo = rel.Repo, true
50		if eligible {
51			best, eligible = domain.LatestRelease([]domain.Release{best, rel})
52		} else {
53			best, eligible = domain.LatestRelease([]domain.Release{rel})
54		}
55	}
56	if haveRepo {
57		if err := flush(); err != nil {
58			return err
59		}
60	}
61	var b kv.Batch
62	b.Put([]byte(releaseLatestIndexMarker), []byte{1})
63	if _, err := s.db.Apply(ctx, &b); err != nil {
64		return fmt.Errorf("mark latest release index: %w", err)
65	}
66	return nil
67}

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