Skip to main content

memstead_base/ops/
transport.rs

1//! Wire types for the three transport ops `Engine::fetch`,
2//! `Engine::pull`, `Engine::push`.
3//!
4//! `branch_reset` lives next to these in the transport surface;
5//! this file pins the success-path payloads each transport op
6//! returns.
7
8use serde::{Deserialize, Serialize};
9
10/// Outcome of `Engine::fetch`. Updates remote-tracking refs without
11/// moving the local branch pointer.
12#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
13pub struct FetchOutcome {
14    /// Remote name the fetch targeted (verbatim from input).
15    pub remote: String,
16    /// Refspecs that were fetched. Empty in the response means "the
17    /// remote's configured defaults"; otherwise echoes the caller's
18    /// list.
19    pub refspecs: Vec<String>,
20    /// Per-ref tip the fetch landed on, keyed by remote-tracking ref
21    /// (e.g. `refs/remotes/origin/specs` → new SHA). Only refs that
22    /// actually moved appear here; unchanged refs are omitted.
23    pub updated_refs: Vec<UpdatedRef>,
24}
25
26/// One ref's transition recorded by a successful fetch / pull.
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
28pub struct UpdatedRef {
29    /// Ref name (e.g. `refs/remotes/origin/specs`).
30    pub ref_name: String,
31    /// SHA the ref pointed at before this op, when known. Empty
32    /// string when the ref did not exist locally before the op.
33    pub previous_sha: String,
34    /// SHA the ref points at after this op.
35    pub new_sha: String,
36}
37
38/// Outcome of `Engine::pull`. Fast-forwards the local branch when
39/// possible; refuses with `LOCAL_DIVERGENCE` on a diverged local
40/// branch.
41#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
42pub struct PullOutcome {
43    /// Mem whose branch was advanced.
44    pub mem: String,
45    /// Remote-tracking ref the fast-forward consumed (e.g.
46    /// `refs/remotes/origin/specs`).
47    pub source_ref: String,
48    /// Local branch ref that was moved (e.g. `refs/heads/specs`).
49    pub branch_ref: String,
50    /// SHA the local branch pointed at before the pull. Empty for a
51    /// fresh branch that did not yet exist locally.
52    pub previous_sha: String,
53    /// SHA the local branch points at after the pull.
54    pub new_sha: String,
55    /// Updated remote-tracking refs the underlying fetch produced.
56    pub updated_refs: Vec<UpdatedRef>,
57}
58
59/// Outcome of `Engine::push`. The remote's view of the mem's
60/// branch has moved to `new_sha` after the operation.
61#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
62pub struct PushOutcome {
63    /// Mem whose branch was pushed.
64    pub mem: String,
65    /// Remote name the push targeted.
66    pub remote: String,
67    /// Local branch ref that was pushed (e.g. `refs/heads/specs`).
68    pub branch_ref: String,
69    /// SHA the remote acknowledged after the push.
70    pub new_sha: String,
71    /// `true` when the push was a force update (the caller passed
72    /// `force: true` and the underlying ref move was not a
73    /// fast-forward). Consumers warn on this in their UI.
74    pub forced: bool,
75}
76
77/// Outcome of `Engine::remote_add`. Configures a named remote on the
78/// workspace's mem-repo so `fetch` / `pull` / `push` have somewhere to
79/// go — upsert semantics (re-pointing an existing remote is not an
80/// error; `updated` says which happened).
81#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
82pub struct RemoteAddOutcome {
83    /// Remote name (verbatim from input).
84    pub remote: String,
85    /// URL the remote now points at.
86    pub url: String,
87    /// `true` when the remote already existed and its URL was
88    /// re-pointed; `false` when it was newly added.
89    pub updated: bool,
90}