Skip to main content

memstead_base/ops/
branch_reset.rs

1//! Wire types for `Engine::branch_reset`.
2//!
3//! fetch / pull / push / branch_reset form one transport surface; this op is the lone history-rewrite
4//! primitive the others compose against.
5
6use serde::{Deserialize, Serialize};
7
8/// Successful outcome of `Engine::branch_reset`. Carries enough
9/// context for callers (CLI, replay skills, audit UIs) to surface
10/// what happened without a follow-up `memstead_changes_since` poll.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub struct BranchResetOutcome {
13    /// Mem name whose branch pointer moved.
14    pub mem: String,
15    /// Full ref name of the moved branch (`refs/heads/<mem>` for
16    /// flat layouts, `refs/heads/<path>/<mem>` for hierarchical
17    /// ones).
18    pub branch_ref: String,
19    /// SHA the branch pointed at before the reset.
20    pub previous_sha: String,
21    /// SHA the branch points at after the reset.
22    pub new_sha: String,
23    /// SHAs of the commits that the reset moved away from — every
24    /// commit reachable from `previous_sha` but not from `new_sha`.
25    /// Empty when the reset was a no-op (target == current head).
26    /// Implementer guarantees: every entry was unpushed at the
27    /// instant of the safety probe; nothing in the list was reachable
28    /// from any `refs/remotes/*` ref.
29    pub discarded_commits: Vec<String>,
30}
31
32/// One inbound cross-mem reference that a branch reset would strand: an
33/// edge from an entity in another mem pointing at an entity that exists
34/// at the current head but would not exist at the reset target (it was
35/// created — or renamed to its current id — after the target commit).
36/// Computed engine-side by `Engine::branch_reset_stranded_refs`; the
37/// human surface warns with these before confirming a reset.
38#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
39pub struct StrandedCrossMemRef {
40    /// Referencing entity (lives in a different mem than the reset).
41    pub from_id: String,
42    /// The referencing entity's mem.
43    pub from_mem: String,
44    /// The referenced entity that the reset would remove.
45    pub to_id: String,
46    pub rel_type: String,
47}