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
4 changes: 3 additions & 1 deletion apps/origin-src/src/conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
//! Every revision made from one with unresolved paths, by a snapshot,
//! `describe`, a new change on top, or a merge, carries those it still has
//! the entries of over, in a `core.conflict` of its own, published before
//! the revision itself, so it's never found without it.
//! the revision itself, so it's never found without it. The landing queue
//! refuses a revision whose author's latest `core.conflict` lists a path it
//! still has the entry of.
//!
//! The landing queue also issues `core.conflict`, as a node, when a revision
//! doesn't rebase onto its target, even one the queue rebased itself. That
Expand Down
24 changes: 21 additions & 3 deletions apps/origin-src/src/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
//!
//! Landing a change lands its stack: the head of each change below it that
//! isn't on the target yet, from the bottom, with an acceptance each. A
//! change that diverged is refused. A stack stops at the first change that
//! waits. For each revision:
//! change that diverged, that its creator abandoned, or whose head has
//! unresolved conflicts (see [`conflict`](crate::conflict)) is refused. A
//! stack stops at the first change that waits. For each revision:
//!
//! 1. **Rebase.** The changes it made to its base are merged onto the
//! target's tip, file by file ([`Store::merge`]). A revision made on the
Expand Down Expand Up @@ -159,7 +160,8 @@ impl<'a, P: Platform> Queue<'a, P> {
/// # Errors
///
/// Fails if this node isn't the target's authority, a change in the
/// stack diverged, or the records cannot be read or written.
/// stack diverged, was abandoned or has unresolved conflicts, or the
/// records cannot be read or written.
pub fn land_change(
&self,
change: ChangeId,
Expand Down Expand Up @@ -313,6 +315,22 @@ pub enum LandError {
/// Its heads.
heads: Vec<RevisionId>,
},
/// The change was given up.
#[error("change {} was abandoned, so it cannot land", .0.short())]
Abandoned(ChangeId),
/// The change's head has unresolved conflicts.
#[error(
"change {} has unresolved conflicts, so it cannot land: edit {}, or accept them as they \
are with `origin resolve`",
change.short(),
paths.iter().map(ToString::to_string).collect::<Vec<_>>().join(", ")
)]
Unresolved {
/// The change.
change: ChangeId,
/// The unresolved paths.
paths: Vec<RepoPath>,
},
/// Landing on `policy` would leave it without a valid policy.
#[error("landing would leave `policy` without a valid policy.toml")]
InvalidPolicy(#[source] PolicyError),
Expand Down
14 changes: 14 additions & 0 deletions apps/origin-src/src/queue/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ impl<P: Platform> Session<'_, '_, P> {
if self.has_landed(head, &revision)? {
break;
}
let claims = self.annotations.claims(RecordId::Revision(head))?;
for claim in &claims {
let statement = claim.statement();
if statement.kind == Kind::ABANDON && self.store().authorizes(statement)? {
return Err(LandError::Abandoned(change));
}
}
let conflicts = Conflicts::of(self.store(), &claims, &revision)?;
if !conflicts.is_empty() {
return Err(LandError::Unresolved {
change,
paths: conflicts.paths(),
});
}
if let Base::Revision(below) = revision.base {
next = Some(self.store().get(below)?.change);
}
Expand Down
42 changes: 41 additions & 1 deletion apps/origin-src/src/queue/tests/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use std::sync::Mutex;
use std::thread;

use origin_shared::Statement;

use super::*;

#[test]
Expand Down Expand Up @@ -67,7 +69,7 @@ fn stacks_land_from_the_bottom() {
}

#[test]
fn refuses_divergent_changes() {
fn refuses_divergent_and_abandoned_changes() {
let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n");
let first = repo.change_on_main(1, &[("a", "a")]);
let base = Base::Acceptance(repo.tip(&TargetName::MAIN).acceptance);
Expand All @@ -79,6 +81,24 @@ fn refuses_divergent_changes() {
.land_change(ChangeId::from_bytes([1; 16]), &main)
.unwrap_err();
assert!(matches!(error, LandError::Divergent { .. }), "{error}");

let given_up = repo.change_on_main(2, &[("b", "b")]);
let abandon = Statement {
subject: RecordId::Revision(given_up),
kind: Kind::ABANDON,
verdict: None,
issuer: "user:ada".parse().unwrap(),
inputs: None,
payload: None,
supersedes: None,
promoted_from: None,
};
repo.store.write_all(&[abandon.encode()]).unwrap();
let error = repo
.queue()
.land_change(ChangeId::from_bytes([2; 16]), &main)
.unwrap_err();
assert!(matches!(error, LandError::Abandoned(_)), "{error}");
}

#[test]
Expand Down Expand Up @@ -125,3 +145,23 @@ fn concurrent_landings_serialize() {
}
assert_eq!(repo.main_files().len(), changes.len(), "every file landed");
}

#[test]
fn only_the_creator_of_a_change_abandons_it() {
let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n");
let revision = repo.change_on_main(1, &[("file", "work")]);
let abandon = |issuer: &str| Statement {
subject: RecordId::Revision(revision),
kind: Kind::ABANDON,
verdict: None,
issuer: issuer.parse().unwrap(),
inputs: None,
payload: None,
supersedes: None,
promoted_from: None,
};
repo.store
.write_all(&[abandon("user:eve").encode()])
.unwrap();
assert!(matches!(repo.land(1)[..], [Landing::Landed { .. }]));
}
66 changes: 66 additions & 0 deletions apps/origin-src/src/queue/tests/conflicts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Landings that conflict, and what lets them through.

use super::*;
use crate::conflict::Conflicted;

#[test]
fn conflicts_block_until_a_revision_merges() {
Expand All @@ -26,3 +27,68 @@ fn conflicts_block_until_a_revision_merges() {
repo.revision(2, &[two], tip, &[("shared", "one"), ("more", "m")]);
assert!(matches!(repo.land(2)[..], [Landing::Landed { .. }]));
}

#[test]
fn unresolved_conflicts_never_land() {
let repo = Repo::new("[targets.main]\nauthority = \"node:queue\"\n");
let marked = "<<<<<<< a\n=======\n>>>>>>> b\n";
let revision = repo.change_on_main(1, &[("file", marked)]);
let path = RepoPath::new("file").unwrap();
let conflicts = |content: &str| {
Conflicts::new(vec![Conflicted {
path: path.clone(),
written: Some(EncodedObject::blob(content.as_bytes()).id()),
}])
};
// From someone else, it says nothing about the revision's files.
let foreign = conflicts(marked).statement(
RecordId::Revision(revision),
"user:eve".parse().unwrap(),
None,
);
// From its author, it does.
let (payload, statement) = conflicts(marked).statement(
RecordId::Revision(revision),
"user:ada".parse().unwrap(),
None,
);
repo.store
.write_all(&[foreign.0, foreign.1.encode()])
.unwrap();
let mut annotations = Annotations::open(&repo.store).unwrap();
assert_eq!(
annotations
.claims(RecordId::Revision(revision))
.unwrap()
.len(),
1
);
annotations.issue(&statement, Some(payload)).unwrap();
annotations = Annotations::open(&repo.store).unwrap();
assert_eq!(
annotations
.claims(RecordId::Revision(revision))
.unwrap()
.len(),
2
);
let error = repo
.queue()
.land_change(ChangeId::from_bytes([1; 16]), &TargetName::MAIN)
.unwrap_err();
assert!(
matches!(&error, LandError::Unresolved { paths, .. } if *paths == [path.clone()]),
"{error}"
);

// A revision whose file is no longer what the conflict wrote there
// is resolved, whatever the file holds.
let edited = repo.change_on_main(2, &[("file", "Heading\n=======\n")]);
let (payload, statement) = conflicts(marked).statement(
RecordId::Revision(edited),
"user:ada".parse().unwrap(),
None,
);
annotations.issue(&statement, Some(payload)).unwrap();
assert!(matches!(repo.land(2)[..], [Landing::Landed { .. }]));
}
2 changes: 2 additions & 0 deletions apps/origin-src/src/queue/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use origin_shared::{
};

use super::*;
use crate::annotations::Annotations;
use crate::conflict::Conflicts;
use crate::store::Store;
use crate::targets::Head;
use crate::tree::tests::build;
Expand Down
Loading