cob: Redesign merge state

Move `merges` from `Revision` to `Patch`, and key them by actor.

This ensures that only one merge is possible per actor. We also make
sure that only one revision can be merged at a time, and signal a
conflict if more than one revision is considered merged.

Finally, we make sure that merges have the same target-branch commit
to be considered equal.
This commit is contained in:
Alexis Sellier
2023-05-19 18:40:46 +02:00
parent 8d8751655f
commit 2d55ffba81
11 changed files with 279 additions and 97 deletions
+1 -3
View File
@@ -178,9 +178,7 @@ pub fn find_unmerged_with_base(
let mut matches = Vec::new();
for (id, patch, clock) in proposed {
let (_, rev) = patch.latest().unwrap();
if !rev.merges().count() == 0 {
if patch.merges().count() != 0 {
continue;
}
if **patch.head() == patch_head {
+6 -8
View File
@@ -16,7 +16,7 @@ use super::common;
pub fn run(
repository: &Repository,
profile: &Profile,
filter: Option<patch::State>,
filter: fn(&patch::State) -> bool,
) -> anyhow::Result<()> {
let patches = Patches::open(repository)?;
@@ -24,10 +24,8 @@ pub fn run(
for patch in patches.all()? {
let (id, patch, _) = patch?;
if let Some(filter) = filter {
if patch.state() != filter {
continue;
}
if !filter(patch.state()) {
continue;
}
all.push((id, patch));
}
@@ -105,7 +103,7 @@ pub fn row(
Ok([
match state {
patch::State::Open => term::format::positive("●").into(),
patch::State::Open { .. } => term::format::positive("●").into(),
patch::State::Archived { .. } => term::format::yellow("●").into(),
patch::State::Draft => term::format::dim("●").into(),
patch::State::Merged { .. } => term::format::primary("✔").into(),
@@ -172,8 +170,8 @@ pub fn timeline(
));
}
for merge in revision.merges() {
let peer = repository.remote(&merge.node)?;
for (nid, merge) in patch.merges().filter(|(_, m)| m.revision == *revision_id) {
let peer = repository.remote(nid)?;
let mut badges = Vec::new();
if peer.id == *whoami {
+2 -2
View File
@@ -105,10 +105,10 @@ pub fn run(
attrs.push([
term::format::tertiary("Status".to_owned()).into(),
match state {
patch::State::Open => term::format::positive(state.to_string()),
patch::State::Open { .. } => term::format::positive(state.to_string()),
patch::State::Draft => term::format::dim(state.to_string()),
patch::State::Archived => term::format::yellow(state.to_string()),
patch::State::Merged => term::format::primary(state.to_string()),
patch::State::Merged { .. } => term::format::primary(state.to_string()),
}
.into(),
]);