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
30 changes: 26 additions & 4 deletions apps/origin-src/src/conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ impl Conflicts {
self.0.push(conflicted);
}

/// Those of these conflicts whose path `keep` keeps.
#[must_use]
pub fn only(mut self, keep: impl Fn(&RepoPath) -> bool) -> Self {
self.0.retain(|conflicted| keep(&conflicted.path));
self
}

/// Whether there are none.
#[must_use]
pub fn is_empty(&self) -> bool {
Expand Down Expand Up @@ -222,16 +229,31 @@ impl Conflicts {
store: &Store<P>,
claims: &[Claim],
revision: &Revision,
) -> Result<Self, StoreError> {
Self::latest(store, claims.iter().map(Claim::statement), revision)
}

/// The unresolved conflicts of `revision`, as [`Conflicts::of`] finds
/// them, from `statements` about it, in arrival order.
///
/// # Errors
///
/// Fails like [`Conflicts::of`].
pub fn latest<'s, P: Platform>(
store: &Store<P>,
statements: impl IntoIterator<Item = &'s Statement>,
revision: &Revision,
) -> Result<Self, StoreError> {
if matches!(revision.author, Principal::Node(_)) {
return Ok(Self::default());
}
let Some(claim) = claims.iter().rev().find(|claim| {
claim.statement().kind == Kind::CONFLICT && claim.statement().issuer == revision.author
}) else {
let latest = statements.into_iter().filter(|statement| {
statement.kind == Kind::CONFLICT && statement.issuer == revision.author
});
let Some(statement) = latest.last() else {
return Ok(Self::default());
};
Self::listed(store, claim.statement())?.remaining(store, revision.snapshot)
Self::listed(store, statement)?.remaining(store, revision.snapshot)
}

/// Those of these conflicts `snapshot` still has: where it has the
Expand Down
Loading