v0.2.0 80c61e3

move_lifecycle.go RawHistoryFolder

1package daemon
2
3import (
4	"cmp"
5	"errors"
6	"slices"
7	"sync"
8)
9
10var errMoveLifecycleUnavailable = errors.New("move lifecycle is no longer available")
11
12// moveLifecycleReservation pins a unique, canonically ordered set of sessions
13// plus the daemon move gate. Release is idempotent so every abort path can use
14// defer without coordinating ownership with its caller.
15type moveLifecycleReservation struct {
16	daemon   *Daemon
17	sessions []*session
18	once     sync.Once
19}
20
21// reserveMoveLifecycles admits a move at the daemon gate before touching any
22// per-session lifecycle state. All session counts publish atomically while the
23// complete ordered teardown lock set is held.
24func (d *Daemon) reserveMoveLifecycles(source, destination *session) (*moveLifecycleReservation, error) {
25	if d == nil || source == nil || destination == nil {
26		return nil, errMoveLifecycleUnavailable
27	}
28
29	d.moveLifecycleMu.Lock()
30	if d.moveLifecycleClosing {
31		d.moveLifecycleMu.Unlock()
32		return nil, errMoveLifecycleUnavailable
33	}
34	d.mu.Lock()
35	closing := d.closing
36	d.mu.Unlock()
37	if closing {
38		d.moveLifecycleMu.Unlock()
39		return nil, errMoveLifecycleUnavailable
40	}
41	d.moveLifecycleActive++
42	d.signalMoveLifecycleChangedLocked()
43	d.moveLifecycleMu.Unlock()
44	if d.afterMoveLifecycleGateBeforeTeardownLocks != nil {
45		d.afterMoveLifecycleGateBeforeTeardownLocks()
46	}
47
48	sessions := uniqueMoveSessions(source, destination)
49	for _, sess := range sessions {
50		sess.teardownMu.Lock()
51	}
52	for _, sess := range sessions {
53		if sess.teardownActive {
54			unlockMoveSessions(sessions)
55			d.moveLifecycleMu.Lock()
56			d.moveLifecycleActive--
57			d.signalMoveLifecycleChangedLocked()
58			d.moveLifecycleMu.Unlock()
59			return nil, errMoveLifecycleUnavailable
60		}
61	}
62	for _, sess := range sessions {
63		sess.moveReservations++
64		sess.signalTeardownChangedLocked()
65	}
66	unlockMoveSessions(sessions)
67
68	return &moveLifecycleReservation{daemon: d, sessions: sessions}, nil
69}
70
71func uniqueMoveSessions(source, destination *session) []*session {
72	sessions := []*session{source}
73	if destination != source {
74		sessions = append(sessions, destination)
75	}
76	slices.SortFunc(sessions, func(left, right *session) int {
77		return cmp.Compare(left.id, right.id)
78	})
79	return sessions
80}
81
82func unlockMoveSessions(sessions []*session) {
83	for i := len(sessions) - 1; i >= 0; i-- {
84		sessions[i].teardownMu.Unlock()
85	}
86}
87
88func (r *moveLifecycleReservation) Release() {
89	if r == nil {
90		return
91	}
92	r.once.Do(func() {
93		r.daemon.moveLifecycleMu.Lock()
94		for _, sess := range r.sessions {
95			sess.teardownMu.Lock()
96		}
97		for _, sess := range r.sessions {
98			sess.moveReservations--
99			sess.signalTeardownChangedLocked()
100		}
101		unlockMoveSessions(r.sessions)
102		r.daemon.moveLifecycleActive--
103		r.daemon.signalMoveLifecycleChangedLocked()
104		r.daemon.moveLifecycleMu.Unlock()
105	})
106}
107
108// closeMoveLifecycles rejects new moves, publishes daemon shutdown to ordinary
109// routing, then drains reservations without holding either daemon mutex. Pane
110// process lifetime is cancelled only after the final reservation releases.
111func (d *Daemon) closeMoveLifecycles() {
112	if d == nil {
113		return
114	}
115	d.moveLifecycleMu.Lock()
116	if !d.moveLifecycleClosing {
117		d.moveLifecycleClosing = true
118		d.signalMoveLifecycleChangedLocked()
119	}
120	d.moveLifecycleMu.Unlock()
121
122	// Publish ordinary shutdown admission separately: no move gate mutex is held
123	// while taking the architecture registry lock.
124	d.mu.Lock()
125	d.closing = true
126	d.mu.Unlock()
127
128	d.moveLifecycleMu.Lock()
129	for d.moveLifecycleActive != 0 {
130		changed := d.moveLifecycleChangeLocked()
131		d.moveLifecycleMu.Unlock()
132		<-changed
133		d.moveLifecycleMu.Lock()
134	}
135	cancel := d.paneProcessCancel
136	d.moveLifecycleMu.Unlock()
137	if cancel != nil {
138		cancel()
139	}
140}
141
142func (d *Daemon) moveLifecycleChangeLocked() chan struct{} {
143	if d.moveLifecycleChanged == nil {
144		d.moveLifecycleChanged = make(chan struct{})
145	}
146	return d.moveLifecycleChanged
147}
148
149func (d *Daemon) signalMoveLifecycleChangedLocked() {
150	close(d.moveLifecycleChangeLocked())
151	d.moveLifecycleChanged = make(chan struct{})
152}

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 12

Tags 11

↑↓ moveenter openesc close