MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / ensure_baseline_mapping

Function ensure_baseline_mapping

atomic-cli/src/commands/git/ref_mapping.rs:88–132  ·  view source on GitHub ↗

Load the persisted mapping for `view`, creating the Synchronized baseline from the live observation when absent (journaled, CB-10A task 1).

(
    repo: &Repository,
    working_copy: WorkingCopyId,
    git: &GitRepository,
    view: &str,
)

Source from the content-addressed store, hash-verified

86/// Load the persisted mapping for `view`, creating the Synchronized baseline
87/// from the live observation when absent (journaled, CB-10A task 1).
88pub(crate) fn ensure_baseline_mapping(
89 repo: &Repository,
90 working_copy: WorkingCopyId,
91 git: &GitRepository,
92 view: &str,
93) -> CliResult<(RefMapping, bool)> {
94 if let Some(existing) = repo.get_ref_mapping(view).map_err(CliError::from)? {
95 return Ok((existing, false));
96 }
97 let info = repo.get_view_info(view).map_err(CliError::from)?;
98 let local_ref = if is_ephemeral_view_name(view) {
99 None
100 } else {
101 mapped_local_ref(info.scope, view)
102 };
103 let tip = observed_tip(git, local_ref.as_deref());
104 let mapping = RefMapping {
105 version: REF_MAPPING_VERSION,
106 view_id: durable_view_id(repo, view)?,
107 view_name: view.to_string(),
108 scope: info.scope as u8,
109 local_ref,
110 remote: None,
111 // A fresh baseline observes both sides as they stand: the first
112 // reconcile after enabling mapping bookkeeping is a no-op, never a
113 // spurious import/export of already-aligned history.
114 last_observed_local: tip.clone(),
115 last_observed_remote: None,
116 last_exported: tip,
117 // A baseline observation is not a verified export: the export stays
118 // unbound until a real projection writes it (CB-10A review R1).
119 last_exported_state: None,
120 last_observed_atomic: Some(info.state.to_base32()),
121 status: RefSyncStatus::Synchronized,
122 };
123 // CB-10A review R6: the baseline creation is an atomic expected-absence
124 // lease — a row another working copy wrote between the read above and
125 // this write refuses closed instead of storing a stale baseline over it.
126 repo.create_ref_mapping_expected_absent(working_copy, view, mapping.clone())
127 .map_err(CliError::from)?;
128 // CB-13C F3: the caller must know the run JOURNALED a mapping (a
129 // mutation) so no later `Refused` terminal outcome is emitted after a
130 // mutation — `Refused` promises before-any-mutation.
131 Ok((mapping, true))
132}
133
134/// Record a fresh Synchronized observation for `view` after a successful
135/// reconciliation side (import/export/no-op), preserving the remote pair.

Callers 3

push_to_remoteMethod · 0.85
run_publishFunction · 0.85

Calls 9

is_ephemeral_view_nameFunction · 0.85
mapped_local_refFunction · 0.85
observed_tipFunction · 0.85
durable_view_idFunction · 0.85
get_ref_mappingMethod · 0.80
get_view_infoMethod · 0.80
cloneMethod · 0.45
to_base32Method · 0.45

Tested by

no test coverage detected