oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire
2
3import "strings"
4
5// Placement binds visible labels to repository choices. NewRepo is proposed,
6// never created by asking the question.
7type Placement struct {
8 NewFirst bool `json:"new_first,omitempty"`
9 Repos []string `json:"repos"`
10 NewRepo string `json:"new_repo,omitempty"`
11}
12
13// MoveTask is an owner's revision-checked project correction.
14type MoveTask struct {
15 Abandon bool `json:"abandon,omitempty"`
16 NewProject bool `json:"new_project,omitempty"`
17 Repo string `json:"repo"`
18 Revision int64 `json:"revision"`
19}
20
21const MaxPlacementNotes = 16
22
23// PersonalNotes excludes the separate, system-owned correction slot.
24func PersonalNotes(entries []NotebookEntry) []NotebookEntry {
25 out := []NotebookEntry{}
26 for _, e := range entries {
27 if e.Source != NoteSystem && !(e.Source == NoteOwn && strings.HasPrefix(e.ID, "mv")) {
28 out = append(out, e)
29 }
30 }
31 return out
32}
33
34func BoundedPlacementNotes(entries []NotebookEntry) []NotebookEntry {
35 out := []NotebookEntry{}
36 for _, e := range entries {
37 if e.Source != NoteSystem || !strings.HasPrefix(e.ID, "mv") || len(e.Text) > MaxEntryBytes {
38 continue
39 }
40 found := false
41 for i, old := range out {
42 if old.ID == e.ID {
43 out[i] = e
44 found = true
45 break
46 }
47 }
48 if !found {
49 out = append(out, e)
50 }
51 }
52 if len(out) > MaxPlacementNotes {
53 out = out[len(out)-MaxPlacementNotes:]
54 }
55 return out
56}
57
58// MergePlacementNotes replaces the correction slot with the server snapshot.
59// Personal entries keep their independent count and byte bounds.
60func MergePlacementNotes(entries, corrections []NotebookEntry) []NotebookEntry {
61 return append(PersonalNotes(entries), BoundedPlacementNotes(corrections)...)
62}
63