Skip to main content

kernel/event/record/
history.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The two steps of the unified history that write a tree: going back to
7//! a point, and taking one file back from a point.
8//!
9//! `crates/storage/spec/Worktree/Back.lean` requires that each step appends
10//! exactly one record and that an undo is one of them, never a removal;
11//! these are those records. The tree is named by its worktree name, as
12//! in `worktree_opened`, and never by its path on disk, because a
13//! history that carries a path is a fact about one machine.
14
15use serde::{Deserialize, Serialize};
16
17use crate::locator::GitOid;
18
19/// `went_back`: the tree `name` was opened with its branch at `point`.
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
21#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
22pub struct WentBack {
23    pub name: String,
24    #[cfg_attr(feature = "schema", schemars(with = "String"))]
25    pub point: GitOid,
26}
27
28/// `file_restored`: `path` in the tree `name` now holds what `point`
29/// holds there, or nothing when `point` holds no such file. An empty
30/// `name` is the city's own working tree, which a person takes a file
31/// back into from a page (`crates/wire/Spec.lean` ยง8-62).
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
33#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
34pub struct FileRestored {
35    pub name: String,
36    /// Relative and `/`-separated, as a git tree spells it, so the same
37    /// restore records the same bytes on every machine.
38    pub path: String,
39    #[cfg_attr(feature = "schema", schemars(with = "String"))]
40    pub point: GitOid,
41}