v0.35.0 e86dbd6

mirror_refs.go RawHistoryFolder

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package domain
4
5import (
6	"sort"
7	"strings"
8	"time"
9	"unicode/utf8"
10)
11
12type MirrorRef struct {
13	Name string
14	ID   ObjectID
15} // ID = Ref.ID (tag object for annotated tags)
16// MirrorSnapshot is the last pushed set, persisted; Equal makes the sync a no-op.
17type MirrorSnapshot struct {
18	URL         string
19	Refs        []MirrorRef
20	AllBranches bool
21	At          time.Time
22}
23
24// MirrorRefspecs selects refs/heads/<default> (or every refs/heads/* with allBranches) and
25// refs/tags/*, from the refs of RepoReader.ListRefs (HEAD skipped, unborn default skipped).
26// Names are plain refs; the caller builds "<ref>:<ref>" (never "+", never a delete).
27// Refs whose name is not valid UTF-8 are skipped: they cannot be stored in the snapshot.
28// Returned sorted by ref name.
29func MirrorRefspecs(refs []Ref, defaultBranch string, allBranches bool) []MirrorRef {
30	var out []MirrorRef
31	for _, r := range refs {
32		if r.ID.IsZero() || r.ID.String() == ZeroOID || !utf8.ValidString(r.Name) {
33			continue
34		}
35		if strings.HasPrefix(r.Name, "refs/tags/") || strings.HasPrefix(r.Name, "refs/heads/") && (allBranches || r.Name == "refs/heads/"+defaultBranch) {
36			out = append(out, MirrorRef{Name: r.Name, ID: r.ID})
37		}
38	}
39	sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name })
40	return out
41}
42func (s MirrorSnapshot) Equal(url string, refs []MirrorRef, allBranches bool) bool {
43	if s.URL != url || s.AllBranches != allBranches || len(s.Refs) != len(refs) {
44		return false
45	}
46	counts := make(map[MirrorRef]int, len(refs))
47	for _, r := range s.Refs {
48		counts[r]++
49	}
50	for _, r := range refs {
51		if counts[r] == 0 {
52			return false
53		}
54		counts[r]--
55	}
56	return true
57}

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