From 933d4fc50caf8e45887b4a07b53de4fe96f238d6 Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 20:33:04 +0100 Subject: [PATCH] fix(converge): fetch the merge bases' snapshots in a clone `converge` fetched the snapshots of the change's heads, but finding their merge base reads the snapshot of the revision they evolve from, and of each base a criss-cross history merges, which a clone may never have read: converging failed on an object not found. `Ancestry::merge_base` now calls back with each record before reading its snapshot, and the workspace fetches it there. The landing queue, which reads its own store, passes a callback that does nothing. --- apps/origin-src/src/ancestry.rs | 29 ++++++++++++++++------------ apps/origin-src/src/queue/mod.rs | 4 +++- apps/origin-src/src/workspace/mod.rs | 5 ++++- apps/origin-src/tests/sync.rs | 29 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/apps/origin-src/src/ancestry.rs b/apps/origin-src/src/ancestry.rs index fc644c3c..2531f7cc 100644 --- a/apps/origin-src/src/ancestry.rs +++ b/apps/origin-src/src/ancestry.rs @@ -48,35 +48,38 @@ impl Ancestry { /// recursive strategy does: each from their own merge base, with what /// [`Store::merge_bases`] leaves where they conflict, so a merge from /// the result conflicts there, and under it, unless both sides agree. Writes the trees - /// that makes, which merging reads. + /// that makes, which merging reads. Calls `need` with each record + /// before reading its snapshot, so a lazy clone can fetch it. /// /// # Errors /// - /// Fails if a tree cannot be read or written. - pub fn merge_base( + /// Fails as `need` does, or if a tree cannot be read or written. + pub fn merge_base>( &self, store: &Store

, tips: &[I], - ) -> Result, StoreError> { + mut need: impl FnMut(I) -> Result<(), E>, + ) -> Result, E> { let groups: Vec<_> = tips.iter().map(std::slice::from_ref).collect(); - self.merge_base_of(store, &groups) + self.merge_base_of(store, &groups, &mut need) } /// The snapshot to merge `groups` from, each standing for all it holds. - fn merge_base_of( + fn merge_base_of>( &self, store: &Store

, groups: &[&[I]], - ) -> Result, StoreError> { + need: &mut impl FnMut(I) -> Result<(), E>, + ) -> Result, E> { let bases = self.best_common(groups); let Some((&first, others)) = bases.split_first() else { return Ok(None); }; let mut merged = vec![first]; - let mut tree = self.snapshot(first); + let mut tree = self.snapshot(first, need)?; for &other in others { - let base = self.merge_base_of(store, &[&merged, &[other]])?; - let merge = store.merge_bases(base, tree, self.snapshot(other))?; + let base = self.merge_base_of(store, &[&merged, &[other]], need)?; + let merge = store.merge_bases(base, tree, self.snapshot(other, need)?)?; store.write_all(&merge.trees)?; tree = merge.tree; merged.push(other); @@ -127,8 +130,10 @@ impl Ancestry { self.records.get(&id).map_or(&[], |(parents, _)| parents) } - fn snapshot(&self, id: I) -> TreeId { - self.records[&id].1 + /// The snapshot of `id`, once `need` had it. + fn snapshot(&self, id: I, need: &mut impl FnMut(I) -> Result<(), E>) -> Result { + need(id)?; + Ok(self.records[&id].1) } } diff --git a/apps/origin-src/src/queue/mod.rs b/apps/origin-src/src/queue/mod.rs index 1c4e99fb..18568bf3 100644 --- a/apps/origin-src/src/queue/mod.rs +++ b/apps/origin-src/src/queue/mod.rs @@ -225,7 +225,9 @@ impl<'a, P: Platform> Queue<'a, P> { let state = self.store.get(tip.acceptance)?.body().state; let tips = [session.tip.acceptance, tip.acceptance]; let history = session.history(&tips)?; - let base = history.merge_base(self.store, &tips)?; + // Nothing to fetch: the queue reads the bases' states from its + // store, as it does the tips'. + let base = history.merge_base(self.store, &tips, |_| Ok::<_, StoreError>(()))?; let merge = self.store.merge(base, state, session.state)?; let proposal = Proposal::Target(source.clone()); if !merge.conflicts.is_empty() { diff --git a/apps/origin-src/src/workspace/mod.rs b/apps/origin-src/src/workspace/mod.rs index e7bdc929..2ff899dc 100644 --- a/apps/origin-src/src/workspace/mod.rs +++ b/apps/origin-src/src/workspace/mod.rs @@ -1338,12 +1338,15 @@ impl Workspace { /// The snapshot to merge `heads`, revisions of one change, from: that of /// the newest revision they all evolve from, or the /// [merge](Ancestry::merge_base) of several, if each lacks another. + /// Fetches the snapshots it reads that a clone lacks. fn merge_base(&self, heads: &[RevisionId]) -> Result, WorkspaceError> { let ancestry = Ancestry::walk(heads, |id| { let revision: Revision = self.store.get(id)?; Ok::<_, StoreError>((revision.predecessors, revision.snapshot)) })?; - Ok(ancestry.merge_base(&self.store, heads)?) + ancestry.merge_base(&self.store, heads, |id| { + self.need(&[RecordId::Revision(id)]) + }) } /// `origin log []`: prints the working copy's stack of changes diff --git a/apps/origin-src/tests/sync.rs b/apps/origin-src/tests/sync.rs index 106f63c3..d4d7ccf6 100644 --- a/apps/origin-src/tests/sync.rs +++ b/apps/origin-src/tests/sync.rs @@ -228,3 +228,32 @@ fn a_move_that_cannot_fetch_moves_nothing() { clone.ok(&["edit", &own]); assert_eq!(clone.read("notes"), "mine\n"); } + +#[test] +fn a_clone_converges_heads_whose_merge_base_it_never_read() { + let ada = User::new("ada"); + let origin = Repo::init(&ada); + origin.write("file", "base\n"); + origin.ok(&["describe", "Shared work"]); + let change = origin.full_change(); + // Two agents revise the same revision. + let pointer = origin.path(".origin/workspace"); + let started = fs::read_to_string(&pointer).unwrap(); + origin.write("file", "left\n"); + origin.ok(&["describe", "Shared work"]); + fs::write(&pointer, started).unwrap(); + origin.write("file", "right\n"); + origin.ok(&["describe", "Shared work"]); + + // The clone fetches the heads' snapshots, and their merge base's. + let clone = Repo::clone(&ada, origin.root().to_str().unwrap(), &[]); + clone.ok(&["fetch", "--change", &change]); + let converged = clone.ok(&["converge", &change]); + assert!(converged.starts_with("Converged change "), "{converged}"); + clone.ok(&["edit", &change]); + let file = clone.read("file"); + assert!( + file.contains("left\n") && file.contains("right\n"), + "{file}" + ); +}