utopia-ia/elffuss-braid public
Changesets · Branches · Tags · Compare
| Changeset | 3297f228f20ca79257c1fd5b81c8efca42719228523fbf53ca837f25d52b02e1 |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-21 17:30 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-21 17:30 +02:00 |
| Parents | 52e22f93c9da |
5 files changed
modified crates/wc/Cargo.toml +7 −0
| @@ -25,6 +25,13 @@ | ||
| 25 | 25 | thiserror = "2.0" |
| 26 | 26 | unicode-normalization = "0.1.25" |
| 27 | 27 | |
| 28 | +[features] | |
| 29 | +default = ["materialize"] | |
| 30 | +# `materialize`: write a changeset's files into a plain directory, as | |
| 31 | +# `braid verify` does. A build that never writes files outside a workspace, | |
| 32 | +# such as a server's, can leave it out. | |
| 33 | +materialize = [] | |
| 34 | + | |
| 28 | 35 | [target.'cfg(unix)'.dependencies] |
| 29 | 36 | rustix = { version = "1.1.5", features = ["fs"] } |
| 30 | 37 |
modified crates/wc/src/change.rs +16 −3
| @@ -159,6 +159,21 @@ | ||
| 159 | 159 | /// unless [`RevertRequest::mainline`] says so, are refused, as is |
| 160 | 160 | /// [`RevertRequest::mainline`] for a changeset that is not a merge. |
| 161 | 161 | pub fn create_revert(store: &Store, request: &RevertRequest) -> Result<ObjectId, Error> { |
| 162 | + let culprit = request.culprit; | |
| 163 | + let changeset = read_changeset(store, culprit)?; | |
| 164 | + let mut message = format!("Revert \"{}\"", subject(&changeset.message)).into_bytes(); | |
| 165 | + message.extend_from_slice(format!("\n\nThis reverts changeset {culprit}.\n").as_bytes()); | |
| 166 | + create_revert_with_message(store, request, &message) | |
| 167 | +} | |
| 168 | + | |
| 169 | +/// Makes the revert of `request.culprit` as [`create_revert`] does, with the | |
| 170 | +/// same parent, changes, extra fields and refusals, but with `message` for | |
| 171 | +/// its message. | |
| 172 | +pub fn create_revert_with_message( | |
| 173 | + store: &Store, | |
| 174 | + request: &RevertRequest, | |
| 175 | + message: &[u8], | |
| 176 | +) -> Result<ObjectId, Error> { | |
| 162 | 177 | let culprit = request.culprit; |
| 163 | 178 | let changeset = read_changeset(store, culprit)?; |
| 164 | 179 | let parent = match changeset.parents.as_slice() { |
| @@ -178,8 +193,6 @@ | ||
| 178 | 193 | if changes.is_empty() { |
| 179 | 194 | return Err(Error::NothingToRevert(culprit)); |
| 180 | 195 | } |
| 181 | - let mut message = format!("Revert \"{}\"", subject(&changeset.message)).into_bytes(); | |
| 182 | - message.extend_from_slice(format!("\n\nThis reverts changeset {culprit}.\n").as_bytes()); | |
| 183 | 196 | let mut extras = crate::rebase::agent_extras(&request.agent); |
| 184 | 197 | extras.push((REVERTS.to_vec(), culprit.to_hex().into_bytes())); |
| 185 | 198 | let signature = request.author.now(); |
| @@ -189,7 +202,7 @@ | ||
| 189 | 202 | changes, |
| 190 | 203 | signature.clone(), |
| 191 | 204 | signature, |
| 192 | - message, | |
| 205 | + message.to_vec(), | |
| 193 | 206 | extras, |
| 194 | 207 | )?; |
| 195 | 208 | store.sync()?; |
modified crates/wc/src/lib.rs +13 −5
| @@ -41,10 +41,13 @@ | ||
| 41 | 41 | //! rebasing its own changesets; conflicts are written with markers. |
| 42 | 42 | //! - [`create_change`] and [`land_change`] make and land a changeset |
| 43 | 43 | //! without any working copy; [`create_revert`] makes one that undoes |
| 44 | -//! another; [`land_stack`] lands a stack of them made elsewhere, as a hub | |
| 45 | -//! does. | |
| 46 | -//! - [`materialize`] writes a changeset's files into a plain directory, | |
| 47 | -//! with the same safe checkout, for a command that only needs the files. | |
| 44 | +//! another, and [`create_revert_with_message`] the same with a message of | |
| 45 | +//! the caller's; [`land_stack`] lands a stack of them made elsewhere, as a | |
| 46 | +//! hub does. | |
| 47 | +//! - `materialize` writes a changeset's files into a plain directory, with | |
| 48 | +//! the same safe checkout, for a command that only needs the files. It | |
| 49 | +//! comes with the `materialize` feature, on by default; a build that never | |
| 50 | +//! writes files outside a workspace, such as a server's, can leave it out. | |
| 48 | 51 | //! - [`Workspace::stack`] and [`Workspace::adopt`] split a landing in two, |
| 49 | 52 | //! for a repository whose branches live on a hub: what to land there, |
| 50 | 53 | //! and moving onto the head that holds it afterwards. |
| @@ -75,6 +78,7 @@ | ||
| 75 | 78 | mod identity; |
| 76 | 79 | mod ignores; |
| 77 | 80 | mod markers; |
| 81 | +#[cfg(feature = "materialize")] | |
| 78 | 82 | mod materialize; |
| 79 | 83 | mod paths; |
| 80 | 84 | mod rebase; |
| @@ -87,10 +91,14 @@ | ||
| 87 | 91 | mod workspace; |
| 88 | 92 | |
| 89 | 93 | pub use blocker::Blocker; |
| 90 | -pub use change::{ChangeRequest, Expect, RevertRequest, create_change, create_revert, land_change}; | |
| 94 | +pub use change::{ | |
| 95 | + ChangeRequest, Expect, RevertRequest, create_change, create_revert, create_revert_with_message, | |
| 96 | + land_change, | |
| 97 | +}; | |
| 91 | 98 | pub use error::Error; |
| 92 | 99 | pub use fsprobe::FileSystem; |
| 93 | 100 | pub use identity::Identity; |
| 101 | +#[cfg(feature = "materialize")] | |
| 94 | 102 | pub use materialize::materialize; |
| 95 | 103 | pub use paths::workspace_path; |
| 96 | 104 | pub use stack::{StackMode, land_stack}; |
modified crates/wc/tests/materialize.rs +2 −0
| @@ -4,6 +4,8 @@ | ||
| 4 | 4 | //! Writing a changeset into a plain directory: the files only, with the |
| 5 | 5 | //! checkout's modes and its refusal to follow symlinks. |
| 6 | 6 | |
| 7 | +#![cfg(feature = "materialize")] | |
| 8 | + | |
| 7 | 9 | mod common; |
| 8 | 10 | |
| 9 | 11 | use braid_format::{ChangeOp, GitId}; |
modified crates/wc/tests/revert.rs +59 −1
| @@ -9,7 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | use braid_engine::{AGENT, REBASED_FROM, REVERTS, read_changeset}; |
| 11 | 11 | use braid_format::{ChangeOp, GitId, ObjectId}; |
| 12 | -use braid_wc::{Error, Landed, RevertRequest, create_revert, land_change}; | |
| 12 | +use braid_wc::{ | |
| 13 | + Error, Landed, RevertRequest, create_revert, create_revert_with_message, land_change, | |
| 14 | +}; | |
| 13 | 15 | use common::{Fixture, ada}; |
| 14 | 16 | |
| 15 | 17 | fn revert(f: &Fixture, culprit: ObjectId, mainline: bool) -> Result<ObjectId, Error> { |
| @@ -191,3 +193,59 @@ | ||
| 191 | 193 | Err(Error::NotAMerge(id)) if id == side |
| 192 | 194 | )); |
| 193 | 195 | } |
| 196 | + | |
| 197 | +#[test] | |
| 198 | +fn a_revert_can_carry_a_message_of_its_own() { | |
| 199 | + let f = Fixture::new(); | |
| 200 | + let base = f.commit(&[], vec![("a", f.file("1\n")), ("b", f.file("b\n"))]); | |
| 201 | + let culprit = f.commit( | |
| 202 | + &[base], | |
| 203 | + vec![("a", f.file("2\n")), ("run", f.exec("echo\n"))], | |
| 204 | + ); | |
| 205 | + let request = |culprit, mainline| RevertRequest { | |
| 206 | + culprit, | |
| 207 | + mainline, | |
| 208 | + author: ada(), | |
| 209 | + agent: "reverter".to_owned(), | |
| 210 | + }; | |
| 211 | + let message = b"Undo the change to a\n\nIt broke the tests.\n"; | |
| 212 | + let own = | |
| 213 | + create_revert_with_message(f.repo.store(), &request(culprit, false), message).unwrap(); | |
| 214 | + let usual = revert(&f, culprit, false).unwrap(); | |
| 215 | + let (own, usual) = ( | |
| 216 | + read_changeset(f.repo.store(), own).unwrap(), | |
| 217 | + read_changeset(f.repo.store(), usual).unwrap(), | |
| 218 | + ); | |
| 219 | + assert_eq!(own.message, message); | |
| 220 | + assert_ne!(usual.message, own.message); | |
| 221 | + assert_eq!(own.root, usual.root); | |
| 222 | + assert_eq!(own.root, root(&f, base)); | |
| 223 | + assert_eq!(own.parents, usual.parents); | |
| 224 | + assert_eq!(own.parents, [culprit]); | |
| 225 | + assert_eq!(own.extras, usual.extras); | |
| 226 | + assert_eq!(own.changes, usual.changes); | |
| 227 | + | |
| 228 | + // And the same refusals. | |
| 229 | + let with_message = |culprit, mainline| { | |
| 230 | + create_revert_with_message(f.repo.store(), &request(culprit, mainline), message) | |
| 231 | + }; | |
| 232 | + assert!(matches!( | |
| 233 | + with_message(base, false), | |
| 234 | + Err(Error::RevertRoot(_)) | |
| 235 | + )); | |
| 236 | + assert!(matches!( | |
| 237 | + with_message(culprit, true), | |
| 238 | + Err(Error::NotAMerge(_)) | |
| 239 | + )); | |
| 240 | + let empty = f.commit(&[culprit], Vec::new()); | |
| 241 | + assert!(matches!( | |
| 242 | + with_message(empty, false), | |
| 243 | + Err(Error::NothingToRevert(_)) | |
| 244 | + )); | |
| 245 | + let side = f.commit(&[base], vec![("s", f.file("s\n"))]); | |
| 246 | + let merge = f.commit(&[culprit, side], vec![("s", f.file("s\n"))]); | |
| 247 | + assert!(matches!( | |
| 248 | + with_message(merge, false), | |
| 249 | + Err(Error::RevertMerge { parents: 2, .. }) | |
| 250 | + )); | |
| 251 | +} |