v0.1.0 5228465

id.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package git
4
5import "fmt"
6
7// ObjectID is a SHA-1 object id.
8type ObjectID [20]byte
9
10const hexDigits = "0123456789abcdef"
11
12// oidHexVal maps a hex digit to its value, or 0xff.
13var oidHexVal = func() (t [256]byte) {
14	for i := range t {
15		t[i] = 0xff
16	}
17	for i := 0; i < 10; i++ {
18		t['0'+i] = byte(i)
19	}
20	for i := 0; i < 6; i++ {
21		t['a'+i] = byte(10 + i)
22		t['A'+i] = byte(10 + i)
23	}
24	return t
25}()
26
27// ParseID parses 40 hexadecimal digits.
28func ParseID(s string) (ObjectID, error) {
29	var id ObjectID
30	if len(s) != 40 {
31		return id, fmt.Errorf("%w: %q has %d characters, want 40", ErrInvalidID, truncate(s), len(s))
32	}
33	for i := 0; i < 20; i++ {
34		hi, lo := oidHexVal[s[2*i]], oidHexVal[s[2*i+1]]
35		if hi|lo > 0x0f {
36			return ObjectID{}, fmt.Errorf("%w: %q is not hexadecimal", ErrInvalidID, truncate(s))
37		}
38		id[i] = hi<<4 | lo
39	}
40	return id, nil
41}
42
43// parseIDBytes parses 40 hexadecimal digits.
44func parseIDBytes(b []byte) (id ObjectID, ok bool) {
45	if len(b) != 40 {
46		return id, false
47	}
48	for i := 0; i < 20; i++ {
49		hi, lo := oidHexVal[b[2*i]], oidHexVal[b[2*i+1]]
50		if hi|lo > 0x0f {
51			return ObjectID{}, false
52		}
53		id[i] = hi<<4 | lo
54	}
55	return id, true
56}
57
58// String returns the 40 lowercase hexadecimal digits of the id.
59func (id ObjectID) String() string {
60	var b [40]byte
61	return string(id.AppendHex(b[:0]))
62}
63
64// AppendHex appends the 40 lowercase hexadecimal digits of the id to dst.
65// It does not allocate when dst has room.
66func (id ObjectID) AppendHex(dst []byte) []byte {
67	for _, c := range id {
68		dst = append(dst, hexDigits[c>>4], hexDigits[c&0x0f])
69	}
70	return dst
71}
72
73// IsZero reports whether the id is all zeros (the null id).
74func (id ObjectID) IsZero() bool { return id == ObjectID{} }
75
76func truncate(s string) string {
77	if len(s) > 64 {
78		return s[:64] + "..."
79	}
80	return s
81}

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