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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! History — a versioned safety net for the workspace.
//!
//! prov workspaces are plaintext, so the obvious way to sync one across devices
//! is to point an existing transport (git, Dropbox, iCloud, Syncthing) at the
//! directory and let it reconcile files. That is free for ordinary content
//! edits. It is *not* free for **structural** mutations: a rename, move or
//! delete touches several files at once (the node, every inbound link, the
//! parent's child list, the id registry), and a transport reconciling the bytes
//! with no idea about prov's graph can produce a clean-looking merge that is
//! semantically broken.
//!
//! Nothing prov already has covers that. The crash journal ([`crate::journal`])
//! protects a single device against its own interrupted writes; the recycle bin
//! protects an explicit, single-device delete; `backup` protects against losing
//! the workspace's location entirely — but a backup is a whole opaque tree, and
//! cannot answer "which files did yesterday's merge break, and what did each
//! look like before."
//!
//! ## The shape
//!
//! A reachable `history/` directory off the root holds one **immutable event
//! document per capture** — a full manifest of every reachable file
//! (`path → (id?, hash)`) — plus a content-addressed **blob store** holding the
//! bytes, deduplicated by SHA-256. [`history_capture`] hashes the live graph
//! (minus `history/` itself and `recyclebin/items/`), parks any unseen bytes,
//! and writes one new file.
//!
//! Two properties do all the work:
//!
//! - **Every event is a full manifest, not a delta.** An event is
//! self-contained: nothing folds through its ancestry, so `parent` is display
//! metadata and a foreign event restores even if the events before it never
//! arrived. Removals need no bookkeeping — a path absent from the manifest was
//! not in the capture set.
//! - **The store is append-only at the filesystem level.** A capture only *adds*
//! files (a new event document, newly-seen blobs), and added-file/added-file is
//! the one merge case git, Dropbox, Syncthing and iCloud all handle without
//! conflict. The only mutable files are the per-shard index documents, and
//! those are a **rebuildable cache**: authority lives in the event documents,
//! and any index is recoverable by scanning the directory beneath it. A
//! conflicted index is a [`Finding::HistoryIndexStale`](crate::validate::Finding::HistoryIndexStale) with a mechanical
//! autofix, not data loss.
//!
//! The format is pinned in `docs/history-format.md` — event documents are
//! immutable, so it is a compatibility contract that cannot be retrofitted.
//!
//! ## Audience honesty
//!
//! When the transport is **git**, history should stay off: git already stores
//! every pre-image, dedupes by content, and reconciles concurrent histories. The
//! feature earns its keep where the transport keeps no history — Dropbox,
//! Syncthing, iCloud, a synced network share. That audience is real *and
//! narrow*, which is why [`History`](crate::config::History) defaults off.
//!
//! [`history_capture`]: crate::Workspace::history_capture
//!
//! ## Where the code lives
//!
//! **The feature itself is [`prov_history`]** — the model, the store's layout,
//! and every verb. It reaches this workspace through two host traits
//! (`HistoryReadHost`, `HistoryWriteHost`), which [`Workspace`]
//! implements; nothing in that crate names `prov`.
//!
//! What is left here is the integration:
//!
//! - the [`Workspace`] methods below, each a one-line forward
//! through [`history_store`](crate::Workspace::history_store) (or
//! `history_store_mut`), kept so existing call sites are unchanged;
//! - `HistoryIssue` → [`Finding`](crate::validate::Finding), and the remedies
//! in [`crate::remedy`];
//! - the composition with the recycle bin, the generated about page and the
//! configuration, which is what the host traits' `history_exclusions`,
//! `history_captures` and `registration_conflict` carry across the boundary.
//!
//! The tests follow that same line. Everything about the *store* — capture,
//! restore, prune, forget, the reads, and the [`HistoryIssue`]s it reports —
//! is tested in [`prov_history`], against a host built to its two traits and
//! nothing more, so those tests cannot come to depend on anything history is
//! defined not to know. What stays here is what only exists here: the
//! `HistoryIssue` → [`Finding`](crate::Finding) mapping and its
//! [`Fix`](crate::Fix)es, the claim that each verb leaves the whole *workspace*
//! `check`-clean, and the answers this crate gives to the host traits — the
//! recycle bin's items kept out of a capture set, the store's interior kept out
//! of the title index, the [`FixityCache`](crate::FixityCache) a capture reads
//! through. See `tests` for the entry condition stated as a rule.
use BTreeSet;
use ;
use crateWorkspace;
use Result;
use Storage;
use IndexStore;
pub use ;
/// The compatibility surface: one forward per verb, through
/// [`history_store`](Workspace::history_store) for the reads and plans and
/// [`history_store_mut`](Workspace::history_store_mut) for the four that write.
///
/// These carry no logic of their own — deliberately. Every one of them is a
/// method that predates the extraction and is called from `prov-cli`, from
/// [`crate::remedy`], or from a workspace-level pass like
/// [`check`](Workspace::check); keeping them means the boundary moved without a
/// single call site having to.