mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
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:
@@ -101,6 +101,27 @@ pub enum OperationName {
|
||||
Edit,
|
||||
}
|
||||
|
||||
pub struct Filter(fn(&patch::State) -> bool);
|
||||
|
||||
impl Filter {
|
||||
/// Match everything.
|
||||
fn all() -> Self {
|
||||
Self(|_| true)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Filter {
|
||||
fn default() -> Self {
|
||||
Self(|state| matches!(state, patch::State::Open { .. }))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Filter {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Filter(..)")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Operation {
|
||||
Open {
|
||||
@@ -131,7 +152,7 @@ pub enum Operation {
|
||||
patch_id: Rev,
|
||||
},
|
||||
List {
|
||||
filter: Option<patch::State>,
|
||||
filter: Filter,
|
||||
},
|
||||
Edit {
|
||||
patch_id: Rev,
|
||||
@@ -160,7 +181,7 @@ impl Args for Options {
|
||||
let mut patch_id = None;
|
||||
let mut message = Message::default();
|
||||
let mut push = true;
|
||||
let mut filter = Some(patch::State::Open);
|
||||
let mut filter = Filter::default();
|
||||
let mut diff = false;
|
||||
let mut draft = false;
|
||||
let mut undo = false;
|
||||
@@ -220,19 +241,19 @@ impl Args for Options {
|
||||
|
||||
// List options.
|
||||
Long("all") => {
|
||||
filter = None;
|
||||
filter = Filter::all();
|
||||
}
|
||||
Long("draft") => {
|
||||
filter = Some(patch::State::Draft);
|
||||
filter = Filter(|s| s == &patch::State::Draft);
|
||||
}
|
||||
Long("archived") => {
|
||||
filter = Some(patch::State::Archived);
|
||||
filter = Filter(|s| s == &patch::State::Archived);
|
||||
}
|
||||
Long("merged") => {
|
||||
filter = Some(patch::State::Merged);
|
||||
filter = Filter(|s| matches!(s, patch::State::Merged { .. }));
|
||||
}
|
||||
Long("open") => {
|
||||
filter = Some(patch::State::Open);
|
||||
filter = Filter(|s| matches!(s, patch::State::Open { .. }));
|
||||
}
|
||||
|
||||
// Common.
|
||||
@@ -352,8 +373,8 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||
options,
|
||||
)?;
|
||||
}
|
||||
Operation::List { filter } => {
|
||||
list::run(&repository, &profile, filter)?;
|
||||
Operation::List { filter: Filter(f) } => {
|
||||
list::run(&repository, &profile, f)?;
|
||||
}
|
||||
Operation::Show { patch_id, diff } => {
|
||||
let patch_id = patch_id.resolve(&repository.backend)?;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user