mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 22:30:41 +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:
@@ -153,10 +153,10 @@ pub enum PatchState {
|
||||
impl PatchState {
|
||||
pub fn matches(&self, patch: &patch::State) -> bool {
|
||||
match self {
|
||||
Self::Open => matches!(patch, patch::State::Open),
|
||||
Self::Open => matches!(patch, patch::State::Open { .. }),
|
||||
Self::Draft => matches!(patch, patch::State::Draft),
|
||||
Self::Archived => matches!(patch, patch::State::Archived),
|
||||
Self::Merged => matches!(patch, patch::State::Merged),
|
||||
Self::Merged => matches!(patch, patch::State::Merged { .. }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,14 @@ pub(crate) fn patch(
|
||||
"state": patch.state(),
|
||||
"target": patch.target(),
|
||||
"tags": patch.tags().collect::<Vec<_>>(),
|
||||
"merges": patch.merges().map(|(a, m)| {
|
||||
json!({
|
||||
"author": a,
|
||||
"revision": m.revision,
|
||||
"commit": m.commit,
|
||||
"timestamp": m.timestamp
|
||||
})
|
||||
}).collect::<Vec<_>>(),
|
||||
"revisions": patch.revisions().map(|(id, rev)| {
|
||||
json!({
|
||||
"id": id,
|
||||
@@ -130,7 +138,6 @@ pub(crate) fn patch(
|
||||
"base": rev.base(),
|
||||
"oid": rev.head(),
|
||||
"refs": get_refs(repo, patch.author().id(), &rev.head()).unwrap_or(vec![]),
|
||||
"merges": rev.merges().collect::<Vec<_>>(),
|
||||
"discussions": rev.discussion().comments()
|
||||
.map(|(id, comment)| Comment::new(id, comment, rev.discussion(), aliases))
|
||||
.collect::<Vec<_>>(),
|
||||
|
||||
@@ -1745,6 +1745,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -1754,7 +1755,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -1784,6 +1784,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -1793,7 +1794,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -1862,6 +1862,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CREATED_PATCH_ID,
|
||||
@@ -1871,7 +1872,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -1925,6 +1925,7 @@ mod routes {
|
||||
"bug",
|
||||
"design"
|
||||
],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -1934,7 +1935,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -1985,6 +1985,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -1994,7 +1995,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -2007,7 +2007,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -2058,6 +2057,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -2067,7 +2067,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
@@ -2140,6 +2139,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -2149,7 +2149,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_COMMENT_1,
|
||||
@@ -2236,6 +2235,7 @@ mod routes {
|
||||
"state": { "status": "open" },
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -2245,7 +2245,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [
|
||||
@@ -2316,9 +2315,19 @@ mod routes {
|
||||
},
|
||||
"title": "A new `hello world`",
|
||||
"description": "change `hello world` in README to something else",
|
||||
"state": { "status": "merged" },
|
||||
"state": {
|
||||
"status": "merged",
|
||||
"revision": CONTRIBUTOR_PATCH_ID,
|
||||
"commit": PARENT,
|
||||
},
|
||||
"target": "delegates",
|
||||
"tags": [],
|
||||
"merges": [{
|
||||
"author": CONTRIBUTOR_NID,
|
||||
"revision": CONTRIBUTOR_PATCH_ID,
|
||||
"commit": PARENT,
|
||||
"timestamp": TIMESTAMP,
|
||||
}],
|
||||
"revisions": [
|
||||
{
|
||||
"id": CONTRIBUTOR_PATCH_ID,
|
||||
@@ -2328,13 +2337,6 @@ mod routes {
|
||||
"refs": [
|
||||
"refs/heads/master",
|
||||
],
|
||||
"merges": [
|
||||
{
|
||||
"node": CONTRIBUTOR_NID,
|
||||
"commit": PARENT,
|
||||
"timestamp": TIMESTAMP,
|
||||
},
|
||||
],
|
||||
"discussions": [],
|
||||
"timestamp": TIMESTAMP,
|
||||
"reviews": [],
|
||||
|
||||
Reference in New Issue
Block a user