detached e7b3a25

snapshot.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package kv
4
5import (
6	"context"
7	"iter"
8)
9
10// Item is the value stored under a key.
11type Item struct {
12	Value   []byte // owned by the snapshot: must not be modified
13	Version uint64 // seq of the batch that last wrote the key
14}
15
16// Snapshot is an immutable, consistent view of the database at one seq. It is
17// safe for concurrent use and stays valid, unchanged, after later writes.
18// Keys yielded by iterators and Item.Value are owned by the snapshot and must
19// not be modified.
20type Snapshot struct {
21	t   tree
22	seq uint64
23}
24
25func newSnapshot(t tree, seq uint64) *Snapshot {
26	return &Snapshot{t: t, seq: seq}
27}
28
29// Seq returns the seq of the last batch applied in this snapshot.
30func (s *Snapshot) Seq() uint64 { return s.seq }
31
32// Len returns the number of keys.
33func (s *Snapshot) Len() int { return s.t.len() }
34
35// Get returns the item stored under key. Reads never block or log: ctx is
36// not checked.
37func (s *Snapshot) Get(_ context.Context, key []byte) (Item, bool) { return s.t.get(key) }
38
39// Range iterates over the keys in [start, end) in ascending order. A nil end
40// (or an empty start) is unbounded. Breaking out of the loop stops the walk.
41func (s *Snapshot) Range(_ context.Context, start, end []byte) iter.Seq2[[]byte, Item] {
42	return s.t.ascend(start, end)
43}
44
45// Prefix iterates over the keys that begin with p in ascending order. An
46// empty p matches every key.
47func (s *Snapshot) Prefix(_ context.Context, p []byte) iter.Seq2[[]byte, Item] {
48	return s.t.ascend(p, prefixEnd(p))
49}
50
51// prefixEnd returns the smallest key greater than every key that begins with
52// p, or nil if there is none (p is empty or all 0xFF).
53func prefixEnd(p []byte) []byte {
54	for i := len(p) - 1; i >= 0; i-- {
55		if p[i] < 0xFF {
56			end := make([]byte, i+1)
57			copy(end, p)
58			end[i]++
59			return end
60		}
61	}
62	return nil
63}

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 1

Tags 2

↑↓ moveenter openesc close