Commit e6b2112
committed
fix(zettel_id_log): emit single hyphence header instead of stacked docs
Closes #212.
`AppendEntry` previously wrapped every entry in a fresh
`hyphence.TypedBlob` and emitted `Coder.EncodeTo` for it, so every
append re-wrote the `---\n! zettel_id_log-v1\n---\n` preamble. The
file ended up as stacked hyphence docs: 2 yin/yang entries from init
-> 2 type headers; N more appends -> N more headers.
The on-disk shape now mirrors the sibling `inventory_lists_log`:
---
! zettel_id_log-v1
---
side = "yin"
tai = "..."
markl-id = "..."
word-count = 6
side = "yang"
tai = "..."
markl-id = "..."
word-count = 6
A single header at the top of the file, then bodies appended below
with blank-line separation.
## Writer
`AppendEntry` stats the file after the `O_CREATE|O_APPEND|O_WRONLY`
open. Size 0 means a fresh file: emit the header preamble then the
body. Size > 0 means an existing log: emit a `\n` separator then the
body only. Callers (`genesis.go`, `add_zettel_ids.go`,
`migrate_zettel_ids.go`) don't need to know about the header --- the
first append into a fresh file lays it down.
The type-header line is `! <type-without-prefix>`. The
`TypeZettelIdLogVCurrent` constant carries the leading `!`
(e.g. `!zettel_id_log-v1`), so we `strings.TrimPrefix` to avoid
emitting `! !zettel_id_log-v1`.
`encodeEntryBody` calls `charlie_zil.V1Document.Encode` directly to
get the TOML key/value bytes without any surrounding hyphence
framing. Replaces the old per-entry `Coder.EncodeTo(&hyphence.TypedBlob)`
that pulled in the full header.
## Reader
`ReadAllEntries` keeps back-compat with the v14 / v15 stacked-doc
fixtures via a new line-driven `segmentBodies` helper:
- A `---` line toggles an `inHeader` state.
- Lines while `inHeader` (e.g. `! zettel_id_log-v1`) are discarded.
- Non-empty non-header lines accumulate into the current body.
- A blank line flushes the current body and starts the next.
- Opening a new header also flushes (so stacked-doc entries split
at the inter-entry preamble).
Both shapes parse to the same body sequence with no per-shape branch.
## Verification
New BATS file `zz-tests_bats/current_version/zettel_id_log_format.bats`
asserts the on-disk contract:
zettel_id_log_has_single_header_after_init # 1 header after init
zettel_id_log_has_single_header_after_add_zettel_ids # 1 header after init + add
inventory_lists_log_has_single_header # pins the working sibling
All three pass.
The existing `add_zettel_ids.bats` (5 tests) and `migrate_zettel_ids.bats`
(2 tests) also pass --- the new dual-shape reader handles both fresh
single-header logs and v14/v15 stacked-doc fixtures.
:clown:1 parent 7740860 commit e6b2112
2 files changed
Lines changed: 278 additions & 37 deletions
File tree
- go/internal/delta/zettel_id_log
- zz-tests_bats/current_version
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | | - | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
| |||
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
20 | 32 | | |
21 | 33 | | |
22 | 34 | | |
| |||
31 | 43 | | |
32 | 44 | | |
33 | 45 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
37 | 79 | | |
38 | 80 | | |
39 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
40 | 89 | | |
41 | 90 | | |
42 | 91 | | |
43 | 92 | | |
44 | 93 | | |
45 | 94 | | |
46 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
47 | 122 | | |
48 | 123 | | |
49 | 124 | | |
| |||
59 | 134 | | |
60 | 135 | | |
61 | 136 | | |
62 | | - | |
63 | | - | |
| 137 | + | |
64 | 138 | | |
65 | | - | |
| 139 | + | |
66 | 140 | | |
67 | 141 | | |
68 | 142 | | |
69 | 143 | | |
70 | 144 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
83 | 149 | | |
84 | 150 | | |
85 | | - | |
| 151 | + | |
| 152 | + | |
86 | 153 | | |
87 | 154 | | |
88 | 155 | | |
89 | 156 | | |
90 | 157 | | |
91 | | - | |
92 | | - | |
93 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
94 | 172 | | |
95 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
96 | 185 | | |
97 | 186 | | |
98 | 187 | | |
99 | 188 | | |
100 | | - | |
| 189 | + | |
101 | 190 | | |
102 | 191 | | |
103 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
104 | 206 | | |
105 | | - | |
106 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
107 | 211 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
112 | 216 | | |
113 | 217 | | |
114 | 218 | | |
115 | 219 | | |
116 | 220 | | |
117 | | - | |
118 | | - | |
119 | | - | |
| 221 | + | |
120 | 222 | | |
121 | | - | |
| 223 | + | |
122 | 224 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
0 commit comments