Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions apps/origin-src/src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ use std::sync::OnceLock;
use origin_platform::{LockMode, LockedFile, Native};
use origin_shared::api::{LogQuery, RevisionEntry, Revisions};
use origin_shared::{
AcceptanceId, AttachmentId, Base, ChangeId, EncodedObject, Kind, Principal, Record, RecordId,
RepoPath, Revision, RevisionId, Source, Statement, StatementId, TargetId, TargetName, Tree,
TreeId,
AcceptanceId, AttachmentId, Base, ChangeId, EncodedObject, Kind, ObjectKind, Principal, Record,
RecordId, RepoPath, Revision, RevisionId, Source, Statement, StatementId, TargetId, TargetName,
Tree, TreeId,
};

use crate::ancestry::Ancestry;
Expand Down Expand Up @@ -727,14 +727,56 @@ impl Workspace {
}

/// Writes `layers` of objects in order, each durable before the next,
/// so objects may refer to those of earlier layers.
/// so objects may refer to those of earlier layers. Revisions are
/// published holding the lock of every publication of revisions (see
/// [`Workspace::publishing`]).
fn write(&self, layers: &[Vec<EncodedObject>]) -> Result<(), WorkspaceError> {
let mut publishing = None;
for layer in layers.iter().filter(|layer| !layer.is_empty()) {
if publishing.is_none() {
publishing = self.publishing(layer)?;
}
self.store.write_all(layer)?;
}
Ok(())
}

/// Takes the lock every publication of revisions takes (see
/// [`Store::lock_pushes`]) if `objects` hold a revision, once no
/// revision they hold evolves from one the landing queue rebased since
/// the command looked: the queue checks a change's heads under it
/// before it publishes a rebase, so the change never diverges.
fn publishing(&self, objects: &[EncodedObject]) -> Result<Option<LockedFile>, WorkspaceError> {
let mut revisions = Vec::new();
for object in objects {
if object.kind().ok() == Some(ObjectKind::Revision) {
let revision: Revision =
object.decode_as().map_err(|source| StoreError::Decode {
id: object.id(),
source,
})?;
revisions.push(revision);
}
}
if revisions.is_empty() {
return Ok(None);
}
let lock = self.store.lock_pushes()?;
let index = Index::open(&self.store)?;
for revision in &revisions {
for &predecessor in &revision.predecessors {
let before = self.store.get(predecessor)?;
if let Some(behind @ Behind::Rebased(_)) =
self.behind(&index, predecessor, &before)?
{
let behind = self.describe_behind(revision.change, &behind)?;
return Err(WorkspaceError::Behind(behind));
}
}
}
Ok(Some(lock))
}

/// Durably records that the working copy, which has the files of
/// `revision`, is `revision`, and logs the move.
fn point_at(&mut self, revision: RevisionId, why: Why) -> Result<(), WorkspaceError> {
Expand Down
34 changes: 34 additions & 0 deletions apps/origin-src/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,3 +2005,37 @@ fn watch_prints_events_from_a_cursor_or_as_they_happen() {
"{issued}"
);
}

#[test]
fn revisions_never_follow_one_the_queue_rebased_meanwhile() {
let repo = Repo::new();
repo.write("file", "work\n");
repo.ok(&["describe", "Work"]);
let head: RevisionId = repo.revision().parse().unwrap();
let store = Store::new(repo.path(".origin"), Native::default());
// The queue checked the head is the change's only one, and is about to
// publish its rebase, while the user describes the change.
let publishing = store.lock_pushes().unwrap();
let describe = repo
.command(repo.root(), &["describe", "Edited"])
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
.unwrap();
thread::sleep(Duration::from_millis(500));
let rebased = Revision {
predecessors: vec![head],
author: "node:queue".parse().unwrap(),
..store.get(head).unwrap()
};
store.write_all(&[rebased.encode()]).unwrap();
drop(publishing);

// The description waited, then found the head rebased.
let described = describe.wait_with_output().unwrap();
let error = String::from_utf8_lossy(&described.stderr);
assert!(!described.status.success(), "{error}");
assert!(error.contains("rebased"), "{error}");
let status = repo.ok(&["status"]);
assert!(!status.contains("divergent"), "{status}");
}
Loading