utopia-ia/elffuss-braid public
Changesets · Branches · Tags · Compare
| Changeset | 3533fe68b31414acd8671b386589692a7880908fe2723b5aba2ee44cccf29271 |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-15 23:41 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-15 23:41 +02:00 |
| Parents | c03d76685fb3 |
13 files changed
modified crates/cli/src/main.rs +18 −2
| @@ -34,7 +34,9 @@ | ||
| 34 | 34 | #[arg(long, global = true, value_name = "DIR")] |
| 35 | 35 | repo: Option<PathBuf>, |
| 36 | 36 | |
| 37 | - /// Label recorded in the op log for operations made by this command. | |
| 37 | + /// Who is acting: a label recorded in the op log with every ref this | |
| 38 | + /// command moves, and as the `agent` field of every changeset it | |
| 39 | + /// creates. | |
| 38 | 40 | #[arg(long, global = true, env = "BRAID_AGENT", default_value = "cli")] |
| 39 | 41 | agent: String, |
| 40 | 42 | |
| @@ -614,6 +616,15 @@ | ||
| 614 | 616 | }) |
| 615 | 617 | } |
| 616 | 618 | |
| 619 | +/// The agent a changeset names in its `agent` field, if it names one. | |
| 620 | +fn agent_of(changeset: &Changeset) -> Option<String> { | |
| 621 | + changeset | |
| 622 | + .extras | |
| 623 | + .iter() | |
| 624 | + .find(|(key, _)| key.as_slice() == braid_engine::AGENT) | |
| 625 | + .map(|(_, value)| String::from_utf8_lossy(value).into_owned()) | |
| 626 | +} | |
| 627 | + | |
| 617 | 628 | fn changeset_json(id: &ObjectId, changeset: &Changeset) -> Value { |
| 618 | 629 | json!({ |
| 619 | 630 | "id": id.to_hex(), |
| @@ -621,6 +632,7 @@ | ||
| 621 | 632 | "root": changeset.root.to_hex(), |
| 622 | 633 | "author": signature_json(&changeset.author), |
| 623 | 634 | "committer": signature_json(&changeset.committer), |
| 635 | + "agent": agent_of(changeset), | |
| 624 | 636 | "message": String::from_utf8_lossy(&changeset.message), |
| 625 | 637 | "extras": changeset.extras.iter().map(|(k, v)| json!([ |
| 626 | 638 | String::from_utf8_lossy(k), String::from_utf8_lossy(v) |
| @@ -660,9 +672,10 @@ | ||
| 660 | 672 | } else { |
| 661 | 673 | let mut out = io::stdout().lock(); |
| 662 | 674 | for (id, changeset) in &entries { |
| 675 | + let agent = agent_of(changeset).map_or_else(String::new, |agent| format!(" ({agent})")); | |
| 663 | 676 | writeln!( |
| 664 | 677 | out, |
| 665 | - "{} {} {} {}", | |
| 678 | + "{} {} {}{agent} {}", | |
| 666 | 679 | id.short(), |
| 667 | 680 | format_signature_time(&changeset.author), |
| 668 | 681 | String::from_utf8_lossy(&changeset.author.name), |
| @@ -723,6 +736,9 @@ | ||
| 723 | 736 | format_signature_time(signature) |
| 724 | 737 | )?; |
| 725 | 738 | } |
| 739 | + if let Some(agent) = agent_of(&changeset) { | |
| 740 | + writeln!(out, "agent {agent}")?; | |
| 741 | + } | |
| 726 | 742 | writeln!(out)?; |
| 727 | 743 | for line in String::from_utf8_lossy(&changeset.message).lines() { |
| 728 | 744 | writeln!(out, " {line}")?; |
modified crates/cli/src/work.rs +2 −0
| @@ -426,6 +426,7 @@ | ||
| 426 | 426 | paths: workspace_paths(&workspace, &args.paths)?, |
| 427 | 427 | author: None, |
| 428 | 428 | committer: identity(&args.identity, &target.repo)?, |
| 429 | + agent: cli.agent.clone(), | |
| 429 | 430 | force: args.force, |
| 430 | 431 | }; |
| 431 | 432 | let outcome = workspace.commit(&request)?; |
| @@ -704,6 +705,7 @@ | ||
| 704 | 705 | expects, |
| 705 | 706 | message: args.message.as_bytes().to_vec(), |
| 706 | 707 | author: author.clone(), |
| 708 | + agent: cli.agent.clone(), | |
| 707 | 709 | }; |
| 708 | 710 | let change = braid_wc::create_change(repo.store(), &request)?; |
| 709 | 711 | let landing = match &args.land { |
modified crates/cli/tests/workspaces.rs +60 −8
| @@ -53,24 +53,26 @@ | ||
| 53 | 53 | |
| 54 | 54 | /// Runs braid in `dir` with a fixed author and agent. |
| 55 | 55 | fn braid(dir: &Path, args: &[&str]) -> Output { |
| 56 | + braid_as("tester", dir, args) | |
| 57 | +} | |
| 58 | + | |
| 59 | +/// Runs braid in `dir` with a fixed author, as the agent `agent`. | |
| 60 | +fn braid_as(agent: &str, dir: &Path, args: &[&str]) -> Output { | |
| 56 | 61 | Command::new(env!("CARGO_BIN_EXE_braid")) |
| 57 | 62 | .current_dir(dir) |
| 58 | 63 | .args(args) |
| 59 | 64 | .env("BRAID_AUTHOR", AUTHOR) |
| 60 | - .env("BRAID_AGENT", "tester") | |
| 65 | + .env("BRAID_AGENT", agent) | |
| 61 | 66 | .output() |
| 62 | 67 | .unwrap() |
| 63 | 68 | } |
| 64 | 69 | |
| 65 | -fn stderr(out: &Output) -> String { | |
| 66 | - String::from_utf8_lossy(&out.stderr).into_owned() | |
| 67 | -} | |
| 68 | - | |
| 69 | -/// Runs braid with `--json`, expecting exit status `code`. | |
| 70 | -fn json_status(dir: &Path, args: &[&str], code: i32) -> Value { | |
| 70 | +/// Runs braid with `--json` as the agent `agent`, expecting exit status | |
| 71 | +/// `code`. | |
| 72 | +fn json_as(agent: &str, dir: &Path, args: &[&str], code: i32) -> Value { | |
| 71 | 73 | let mut all = args.to_vec(); |
| 72 | 74 | all.push("--json"); |
| 73 | - let out = braid(dir, &all); | |
| 75 | + let out = braid_as(agent, dir, &all); | |
| 74 | 76 | assert_eq!( |
| 75 | 77 | out.status.code(), |
| 76 | 78 | Some(code), |
| @@ -81,6 +83,15 @@ | ||
| 81 | 83 | serde_json::from_slice(&out.stdout).unwrap() |
| 82 | 84 | } |
| 83 | 85 | |
| 86 | +fn stderr(out: &Output) -> String { | |
| 87 | + String::from_utf8_lossy(&out.stderr).into_owned() | |
| 88 | +} | |
| 89 | + | |
| 90 | +/// Runs braid with `--json`, expecting exit status `code`. | |
| 91 | +fn json_status(dir: &Path, args: &[&str], code: i32) -> Value { | |
| 92 | + json_as("tester", dir, args, code) | |
| 93 | +} | |
| 94 | + | |
| 84 | 95 | fn json(dir: &Path, args: &[&str]) -> Value { |
| 85 | 96 | json_status(dir, args, 0) |
| 86 | 97 | } |
| @@ -541,6 +552,47 @@ | ||
| 541 | 552 | assert_eq!(committed["changeset"].as_str().unwrap().len(), 64); |
| 542 | 553 | } |
| 543 | 554 | |
| 555 | +#[test] | |
| 556 | +fn changesets_name_the_agent_that_made_them() { | |
| 557 | + let repo = Repo::new(); | |
| 558 | + seed(&repo, &[("shared.txt", "one\ntwo\nthree\n")]); | |
| 559 | + let a = repo.workspace("a"); | |
| 560 | + let b = repo.workspace("b"); | |
| 561 | + write(&a, "shared.txt", "one\nTWO from a\nthree\n"); | |
| 562 | + json_as("agent-a", &a, &["commit", "-m", "a's two"], 0); | |
| 563 | + json_as("agent-a", &a, &["land"], 0); | |
| 564 | + write(&b, "b.txt", "b\n"); | |
| 565 | + json_as("agent-b", &b, &["commit", "-m", "add b"], 0); | |
| 566 | + write(&b, "shared.txt", "one\nTWO from b\nthree\n"); | |
| 567 | + json_as("agent-b", &b, &["commit", "-m", "b's two"], 0); | |
| 568 | + | |
| 569 | + // Rebased by an update and resolved under another label, b's changes | |
| 570 | + // still name agent-b; landing records the lander in the op log only. | |
| 571 | + json_as("fixer", &b, &["update"], 2); | |
| 572 | + write(&b, "shared.txt", "one\nTWO from a and b\nthree\n"); | |
| 573 | + json_as("fixer", &b, &["commit"], 0); | |
| 574 | + let landed = json_as("lander", &b, &["land"], 0); | |
| 575 | + let log = history(&repo); | |
| 576 | + let agents: Vec<&str> = log.iter().map(|c| c["agent"].as_str().unwrap()).collect(); | |
| 577 | + assert_eq!(agents, ["agent-b", "agent-b", "agent-a", "tester"]); | |
| 578 | + for changeset in &log[..2] { | |
| 579 | + assert!(rebased_from(changeset).is_some()); | |
| 580 | + let extras = changeset["extras"].as_array().unwrap(); | |
| 581 | + assert_eq!(extras[0], serde_json::json!(["agent", "agent-b"])); | |
| 582 | + } | |
| 583 | + let ops = json(&repo.root, &["op", "log", "-n", "1"]); | |
| 584 | + assert_eq!(ops[0]["agent"], "lander"); | |
| 585 | + assert_eq!(ops[0]["seq"], landed["operation"]); | |
| 586 | + | |
| 587 | + // The text forms show it too. | |
| 588 | + let out = braid(&repo.root, &["show", "main"]); | |
| 589 | + let text = String::from_utf8(out.stdout).unwrap(); | |
| 590 | + assert!(text.contains("\nagent agent-b\n"), "{text}"); | |
| 591 | + let out = braid(&repo.root, &["log", "-n", "1"]); | |
| 592 | + let text = String::from_utf8(out.stdout).unwrap(); | |
| 593 | + assert!(text.contains(" Ada (agent-b) b's two"), "{text}"); | |
| 594 | +} | |
| 595 | + | |
| 544 | 596 | #[test] |
| 545 | 597 | fn removing_a_workspace() { |
| 546 | 598 | let repo = Repo::new(); |
modified crates/engine/src/land.rs +6 −0
| @@ -45,6 +45,12 @@ | ||
| 45 | 45 | /// changeset it was rebased from. |
| 46 | 46 | pub const REBASED_FROM: &[u8] = b"rebased-from"; |
| 47 | 47 | |
| 48 | +/// The extra field naming the agent that made a changeset: its label, as | |
| 49 | +/// the command line's `--agent` gives it. A rebased changeset keeps the | |
| 50 | +/// original's, as it keeps every extra field but [`REBASED_FROM`], so the | |
| 51 | +/// field names the agent that made the change, wherever it landed. | |
| 52 | +pub const AGENT: &[u8] = b"agent"; | |
| 53 | + | |
| 48 | 54 | /// What landing a change does to the branch. |
| 49 | 55 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 50 | 56 | pub enum LandOutcome { |
modified crates/engine/src/lib.rs +1 −1
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | pub use commit::{admit, commit}; |
| 71 | 71 | pub use diff::diff; |
| 72 | 72 | pub use error::{ApplyProblem, Error, StoreError}; |
| 73 | -pub use land::{Conflict, ConflictKind, LandOutcome, REBASED_FROM, land}; | |
| 73 | +pub use land::{AGENT, Conflict, ConflictKind, LandOutcome, REBASED_FROM, land}; | |
| 74 | 74 | pub use merge::{BINARY_SNIFF_BYTES, ConflictHunk, HunkSide, MergeResult, is_binary, merge3}; |
| 75 | 75 | pub use path::MAX_PATH_DEPTH; |
| 76 | 76 | pub use tree_merge::{MergeOutcome, merge}; |
modified crates/engine/src/tree_merge.rs +54 −11
| @@ -46,7 +46,8 @@ | ||
| 46 | 46 | /// [`merge_bases`](crate::merge_bases)). The merge changeset has the parents |
| 47 | 47 | /// `[ours, theirs]`; as root, the three-way merge of the three trees; the |
| 48 | 48 | /// change list against `ours`; `committer` as author and committer; |
| 49 | -/// `message`; and no extra fields. It is made even when `ours` already has | |
| 49 | +/// `message`; and `extras` as its extra fields, such as [`AGENT`](crate::AGENT) | |
| 50 | +/// naming who merged. It is made even when `ours` already has | |
| 50 | 51 | /// every change of `theirs`, with an empty change list, so that its history |
| 51 | 52 | /// records the merge. Blobs, directories and the changeset are stored only |
| 52 | 53 | /// when the outcome is [`Merged`](MergeOutcome::Merged). |
| @@ -66,6 +67,7 @@ | ||
| 66 | 67 | theirs: ObjectId, |
| 67 | 68 | committer: Signature, |
| 68 | 69 | message: Vec<u8>, |
| 70 | + extras: Vec<(Vec<u8>, Vec<u8>)>, | |
| 69 | 71 | ) -> Result<MergeOutcome, Error> { |
| 70 | 72 | let bases = merge_bases(objects, ours, theirs)?; |
| 71 | 73 | let base_root = match bases.as_slice() { |
| @@ -105,7 +107,7 @@ | ||
| 105 | 107 | author: committer.clone(), |
| 106 | 108 | committer, |
| 107 | 109 | message, |
| 108 | - extras: Vec::new(), | |
| 110 | + extras, | |
| 109 | 111 | git_origin: None, |
| 110 | 112 | } |
| 111 | 113 | .assemble() |
| @@ -144,7 +146,7 @@ | ||
| 144 | 146 | use super::*; |
| 145 | 147 | use crate::access::read_changes; |
| 146 | 148 | use crate::commit::{admit, commit}; |
| 147 | - use crate::land::{ConflictKind, LandOutcome, land}; | |
| 149 | + use crate::land::{AGENT, ConflictKind, LandOutcome, land}; | |
| 148 | 150 | use crate::testing::{Repo, delete, signature, text_map}; |
| 149 | 151 | use braid_format::{Change, Changes}; |
| 150 | 152 | |
| @@ -185,6 +187,7 @@ | ||
| 185 | 187 | fork.theirs, |
| 186 | 188 | signature("merger"), |
| 187 | 189 | b"Merge\n".to_vec(), |
| 190 | + vec![(AGENT.to_vec(), b"merger".to_vec())], | |
| 188 | 191 | ) |
| 189 | 192 | .unwrap() |
| 190 | 193 | } |
| @@ -223,7 +226,17 @@ | ||
| 223 | 226 | let later = repo.commit(&[next], vec![repo.set("b", "1")]); |
| 224 | 227 | let objects = &repo.objects; |
| 225 | 228 | let stored = objects.len(); |
| 226 | - let run = |ours, theirs| merge(objects, ours, theirs, signature("m"), Vec::new()).unwrap(); | |
| 229 | + let run = |ours, theirs| { | |
| 230 | + merge( | |
| 231 | + objects, | |
| 232 | + ours, | |
| 233 | + theirs, | |
| 234 | + signature("m"), | |
| 235 | + Vec::new(), | |
| 236 | + Vec::new(), | |
| 237 | + ) | |
| 238 | + .unwrap() | |
| 239 | + }; | |
| 227 | 240 | assert_eq!(run(base, later), MergeOutcome::FastForward(later)); |
| 228 | 241 | assert_eq!(run(later, base), MergeOutcome::UpToDate); |
| 229 | 242 | assert_eq!(run(later, next), MergeOutcome::UpToDate); |
| @@ -253,7 +266,7 @@ | ||
| 253 | 266 | assert_eq!(new.author, signature("merger")); |
| 254 | 267 | assert_eq!(new.committer, signature("merger")); |
| 255 | 268 | assert_eq!(new.message, b"Merge\n"); |
| 256 | - assert!(new.extras.is_empty()); | |
| 269 | + assert_eq!(new.extras, [(AGENT.to_vec(), b"merger".to_vec())]); | |
| 257 | 270 | assert_eq!(new.git_origin, None); |
| 258 | 271 | |
| 259 | 272 | // Merging the other way gives the same tree. |
| @@ -263,6 +276,7 @@ | ||
| 263 | 276 | f.ours, |
| 264 | 277 | signature("merger"), |
| 265 | 278 | Vec::new(), |
| 279 | + Vec::new(), | |
| 266 | 280 | ) |
| 267 | 281 | .unwrap(); |
| 268 | 282 | let MergeOutcome::Merged { changeset, .. } = back else { |
| @@ -390,7 +404,16 @@ | ||
| 390 | 404 | ); |
| 391 | 405 | let (first, _) = merged(&f); |
| 392 | 406 | let repo = &f.repo; |
| 393 | - let run = |ours, theirs| merge(&repo.objects, ours, theirs, signature("m"), Vec::new()); | |
| 407 | + let run = |ours, theirs| { | |
| 408 | + merge( | |
| 409 | + &repo.objects, | |
| 410 | + ours, | |
| 411 | + theirs, | |
| 412 | + signature("m"), | |
| 413 | + Vec::new(), | |
| 414 | + Vec::new(), | |
| 415 | + ) | |
| 416 | + }; | |
| 394 | 417 | assert_eq!(run(first, f.theirs).unwrap(), MergeOutcome::UpToDate); |
| 395 | 418 | assert_eq!( |
| 396 | 419 | run(f.theirs, first).unwrap(), |
| @@ -413,7 +436,14 @@ | ||
| 413 | 436 | let repo = Repo::new(); |
| 414 | 437 | let one = repo.commit(&[], vec![repo.set("a", "1")]); |
| 415 | 438 | let two = repo.commit(&[], vec![repo.set("b", "1")]); |
| 416 | - let result = merge(&repo.objects, one, two, signature("m"), Vec::new()); | |
| 439 | + let result = merge( | |
| 440 | + &repo.objects, | |
| 441 | + one, | |
| 442 | + two, | |
| 443 | + signature("m"), | |
| 444 | + Vec::new(), | |
| 445 | + Vec::new(), | |
| 446 | + ); | |
| 417 | 447 | assert!( |
| 418 | 448 | matches!(result, Err(Error::UnrelatedHistories { ours, theirs }) if ours == one && theirs == two), |
| 419 | 449 | "{result:?}" |
| @@ -446,7 +476,14 @@ | ||
| 446 | 476 | let m2 = node(&repo, &[y, x], vec![repo.set("a", "x")], "m2"); |
| 447 | 477 | let ours = node(&repo, &[m1], vec![repo.set("c", "1")], "ours"); |
| 448 | 478 | let theirs = node(&repo, &[m2], vec![repo.set("d", "1")], "theirs"); |
| 449 | - let result = merge(&repo.objects, ours, theirs, signature("m"), Vec::new()); | |
| 479 | + let result = merge( | |
| 480 | + &repo.objects, | |
| 481 | + ours, | |
| 482 | + theirs, | |
| 483 | + signature("m"), | |
| 484 | + Vec::new(), | |
| 485 | + Vec::new(), | |
| 486 | + ); | |
| 450 | 487 | assert!( |
| 451 | 488 | matches!(&result, Err(Error::SeveralMergeBases { bases, .. }) if bases.len() == 2), |
| 452 | 489 | "{result:?}" |
| @@ -460,9 +497,15 @@ | ||
| 460 | 497 | let m2 = node(&repo, &[y, x], Vec::new(), "m2 again"); |
| 461 | 498 | let ours = node(&repo, &[m1], vec![repo.set("c", "1")], "ours again"); |
| 462 | 499 | let theirs = node(&repo, &[m2], vec![repo.set("d", "1")], "theirs again"); |
| 463 | - let MergeOutcome::Merged { changeset, .. } = | |
| 464 | - merge(&repo.objects, ours, theirs, signature("m"), Vec::new()).unwrap() | |
| 465 | - else { | |
| 500 | + let MergeOutcome::Merged { changeset, .. } = merge( | |
| 501 | + &repo.objects, | |
| 502 | + ours, | |
| 503 | + theirs, | |
| 504 | + signature("m"), | |
| 505 | + Vec::new(), | |
| 506 | + Vec::new(), | |
| 507 | + ) | |
| 508 | + .unwrap() else { | |
| 466 | 509 | panic!("expected a merge"); |
| 467 | 510 | }; |
| 468 | 511 | assert_eq!( |
modified crates/engine/tests/properties.rs +1 −1
| @@ -433,7 +433,7 @@ | ||
| 433 | 433 | Vec::new(), |
| 434 | 434 | )?; |
| 435 | 435 | let landed = land(&objects, Some(x), y, signature())?; |
| 436 | - let merged = merge(&objects, x, y, signature(), b"merge\n".to_vec())?; | |
| 436 | + let merged = merge(&objects, x, y, signature(), b"merge\n".to_vec(), Vec::new())?; | |
| 437 | 437 | match (landed, merged) { |
| 438 | 438 | (LandOutcome::Conflicts(by_land), MergeOutcome::Conflicts(by_merge)) => { |
| 439 | 439 | prop_assert_eq!(by_land, by_merge); |
modified crates/repo/src/sync.rs +5 −2
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | use std::fs::{self, File, OpenOptions}; |
| 10 | 10 | use std::path::{Path, PathBuf}; |
| 11 | 11 | |
| 12 | -use braid_engine::{Conflict, MergeOutcome, is_ancestor, merge}; | |
| 12 | +use braid_engine::{AGENT, Conflict, MergeOutcome, is_ancestor, merge}; | |
| 13 | 13 | use braid_format::{Kind, MemoryObjects, ObjectId, Objects, Signature}; |
| 14 | 14 | use braid_git::{Exporter, GitKind, GitOid, ImportOptions, RefTarget}; |
| 15 | 15 | use braid_store::{Operation, Store}; |
| @@ -179,7 +179,8 @@ | ||
| 179 | 179 | /// moved) as a fast-forward with a lease. Braid never force-pushes. |
| 180 | 180 | /// Operations are recorded by `agent`, who is also the committer of a |
| 181 | 181 | /// merge, with the `email` of the repository's [`Config`](crate::Config) |
| 182 | - /// or `<agent>@example.org`. | |
| 182 | + /// or `<agent>@example.org`, and whom the merge's | |
| 183 | + /// [`AGENT`](braid_engine::AGENT) field names. | |
| 183 | 184 | /// |
| 184 | 185 | /// # The mirror |
| 185 | 186 | /// |
| @@ -494,12 +495,14 @@ | ||
| 494 | 495 | } |
| 495 | 496 | (Some(head), Some(remote)) => { |
| 496 | 497 | let message = format!("Merge {} into {}\n", self.remote_ref, self.branch); |
| 498 | + let agent = vec![(AGENT.to_vec(), self.agent.as_bytes().to_vec())]; | |
| 497 | 499 | match merge( |
| 498 | 500 | objects, |
| 499 | 501 | head, |
| 500 | 502 | remote, |
| 501 | 503 | self.committer.clone(), |
| 502 | 504 | message.into_bytes(), |
| 505 | + agent, | |
| 503 | 506 | )? { |
| 504 | 507 | MergeOutcome::UpToDate => Decision::Push(head), |
| 505 | 508 | MergeOutcome::FastForward(to) => Decision::FastForward(to), |
modified crates/repo/src/sync/tests.rs +6 −0
| @@ -469,6 +469,11 @@ | ||
| 469 | 469 | let theirs_changeset = world.map().changeset(&oid(&theirs)).unwrap(); |
| 470 | 470 | let merged = read_changeset(world.braid.store(), merge).unwrap(); |
| 471 | 471 | assert_eq!(merged.parents, [ours, theirs_changeset]); |
| 472 | + // The merge names the agent that made it. | |
| 473 | + assert_eq!( | |
| 474 | + merged.extras, | |
| 475 | + [(braid_engine::AGENT.to_vec(), b"tester".to_vec())] | |
| 476 | + ); | |
| 472 | 477 | assert_eq!(report.operations.len(), 2, "the merge, then the push"); |
| 473 | 478 | |
| 474 | 479 | // The remote has both lines and the merge commit, a fast-forward from |
| @@ -485,6 +490,7 @@ | ||
| 485 | 490 | text.contains("\ncommitter tester <tester@example.org> "), |
| 486 | 491 | "{text}" |
| 487 | 492 | ); |
| 493 | + assert!(text.contains("\nagent tester\n"), "{text}"); | |
| 488 | 494 | assert!( |
| 489 | 495 | text.ends_with(&format!("Merge {} into main", report.remote_ref)), |
| 490 | 496 | "{text}" |
modified crates/wc/src/change.rs +4 −1
| @@ -41,6 +41,9 @@ | ||
| 41 | 41 | pub message: Vec<u8>, |
| 42 | 42 | /// The author, who also commits it. |
| 43 | 43 | pub author: Identity, |
| 44 | + /// The label of the agent making it, recorded as its | |
| 45 | + /// [`AGENT`](braid_engine::AGENT) field. | |
| 46 | + pub agent: String, | |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | /// Checks the expectations against the base, stores the contents and the |
| @@ -118,7 +121,7 @@ | ||
| 118 | 121 | signature.clone(), |
| 119 | 122 | signature, |
| 120 | 123 | request.message.clone(), |
| 121 | - Vec::new(), | |
| 124 | + crate::rebase::agent_extras(&request.agent), | |
| 122 | 125 | )?; |
| 123 | 126 | store.sync()?; |
| 124 | 127 | Ok(id) |
modified crates/wc/src/rebase.rs +29 −7
| @@ -15,8 +15,8 @@ | ||
| 15 | 15 | //! the store, unreferenced. |
| 16 | 16 | |
| 17 | 17 | use braid_engine::{ |
| 18 | - Conflict, LandOutcome, REBASED_FROM, commit, diff, entry_at, land, read_blob, read_changes, | |
| 19 | - read_changeset, | |
| 18 | + AGENT, Conflict, LandOutcome, REBASED_FROM, commit, diff, entry_at, land, read_blob, | |
| 19 | + read_changes, read_changeset, | |
| 20 | 20 | }; |
| 21 | 21 | use braid_format::{ |
| 22 | 22 | Change, ChangeOp, ChangesetParts, EntryKind, Kind, ObjectId, Objects, Signature, |
| @@ -178,7 +178,8 @@ | ||
| 178 | 178 | return Ok(outcome); |
| 179 | 179 | }; |
| 180 | 180 | // The same tree and change list, with `onto` as the first parent (the |
| 181 | - // temporary base has `onto`'s tree), naming the original change. | |
| 181 | + // temporary base has `onto`'s tree), naming the original change. The | |
| 182 | + // other extra fields are the original's, its agent among them. | |
| 182 | 183 | let landed = read_changeset(objects, changeset)?; |
| 183 | 184 | let changes = read_changes(objects, changeset, &landed)?.into_owned(); |
| 184 | 185 | let parents = std::iter::once(onto) |
| @@ -189,7 +190,7 @@ | ||
| 189 | 190 | .into_iter() |
| 190 | 191 | .filter(|(key, _)| key.as_slice() != REBASED_FROM) |
| 191 | 192 | .collect(); |
| 192 | - extras.extend(rebased_extras(change)); | |
| 193 | + extras.push((REBASED_FROM.to_vec(), change.to_hex().into_bytes())); | |
| 193 | 194 | let rebased = store_parts( |
| 194 | 195 | objects, |
| 195 | 196 | ChangesetParts { |
| @@ -373,7 +374,28 @@ | ||
| 373 | 374 | }) |
| 374 | 375 | } |
| 375 | 376 | |
| 376 | -/// The extras of a changeset made by finishing a rebase of `change`. | |
| 377 | -pub(crate) fn rebased_extras(change: ObjectId) -> Vec<(Vec<u8>, Vec<u8>)> { | |
| 378 | - vec![(REBASED_FROM.to_vec(), change.to_hex().into_bytes())] | |
| 377 | +/// The extra fields of a changeset: the agent that makes it. | |
| 378 | +pub(crate) fn agent_extras(agent: &str) -> Vec<(Vec<u8>, Vec<u8>)> { | |
| 379 | + vec![(AGENT.to_vec(), agent.as_bytes().to_vec())] | |
| 380 | +} | |
| 381 | + | |
| 382 | +/// The extra fields of the changeset that finishes a rebase of `change`, | |
| 383 | +/// whose own are `original`: the same, as landing keeps them, with | |
| 384 | +/// [`REBASED_FROM`] naming `change`. The original's [`AGENT`] stays; a change | |
| 385 | +/// without one gets `agent`, who resolved it. | |
| 386 | +pub(crate) fn rebased_extras( | |
| 387 | + original: &[(Vec<u8>, Vec<u8>)], | |
| 388 | + change: ObjectId, | |
| 389 | + agent: &str, | |
| 390 | +) -> Vec<(Vec<u8>, Vec<u8>)> { | |
| 391 | + let mut extras: Vec<(Vec<u8>, Vec<u8>)> = original | |
| 392 | + .iter() | |
| 393 | + .filter(|(key, _)| key.as_slice() != REBASED_FROM) | |
| 394 | + .cloned() | |
| 395 | + .collect(); | |
| 396 | + if !extras.iter().any(|(key, _)| key.as_slice() == AGENT) { | |
| 397 | + extras.splice(0..0, agent_extras(agent)); | |
| 398 | + } | |
| 399 | + extras.push((REBASED_FROM.to_vec(), change.to_hex().into_bytes())); | |
| 400 | + extras | |
| 379 | 401 | } |
modified crates/wc/src/workspace.rs +11 −6
| @@ -27,7 +27,7 @@ | ||
| 27 | 27 | use crate::identity::Identity; |
| 28 | 28 | use crate::markers::has_markers; |
| 29 | 29 | use crate::paths::{is_within, os_name, split_last}; |
| 30 | -use crate::rebase::{First, Replayed, conflict_tree, rebased_extras, replay}; | |
| 30 | +use crate::rebase::{First, Replayed, agent_extras, conflict_tree, rebased_extras, replay}; | |
| 31 | 31 | use crate::safe::{Found, Root, Stat, StatKind, open_file, read_link}; |
| 32 | 32 | use crate::scan; |
| 33 | 33 | use crate::state::{Checkout, Lock, Rebase, RecordedConflict, State}; |
| @@ -73,6 +73,10 @@ | ||
| 73 | 73 | pub author: Option<Identity>, |
| 74 | 74 | /// Who records the changeset. |
| 75 | 75 | pub committer: Identity, |
| 76 | + /// The label of the agent making it, recorded as its | |
| 77 | + /// [`AGENT`](braid_engine::AGENT) field. While a rebase is in progress, | |
| 78 | + /// the rebased changeset's own agent stays, if it names one. | |
| 79 | + pub agent: String, | |
| 76 | 80 | /// Commit even if conflict markers remain or conflicts are not marked |
| 77 | 81 | /// resolved. |
| 78 | 82 | pub force: bool, |
| @@ -623,11 +627,12 @@ | ||
| 623 | 627 | (None, Some(original)) => original.author.clone(), |
| 624 | 628 | (None, None) => committer.clone(), |
| 625 | 629 | }; |
| 626 | - let extras = state | |
| 627 | - .rebase | |
| 628 | - .as_ref() | |
| 629 | - .map(|rebase| rebased_extras(rebase.change)) | |
| 630 | - .unwrap_or_default(); | |
| 630 | + let extras = match (&state.rebase, &original) { | |
| 631 | + (Some(rebase), Some(original)) => { | |
| 632 | + rebased_extras(&original.extras, rebase.change, &request.agent) | |
| 633 | + } | |
| 634 | + _ => agent_extras(&request.agent), | |
| 635 | + }; | |
| 631 | 636 | let parents: Vec<ObjectId> = state.base.into_iter().collect(); |
| 632 | 637 | let count = changes.len(); |
| 633 | 638 | let id = braid_engine::commit( |
modified crates/wc/tests/workspaces.rs +5 −0
| @@ -19,6 +19,7 @@ | ||
| 19 | 19 | paths: Vec::new(), |
| 20 | 20 | author: None, |
| 21 | 21 | committer: ada(), |
| 22 | + agent: "tester".to_owned(), | |
| 22 | 23 | force: false, |
| 23 | 24 | }) |
| 24 | 25 | .unwrap() |
| @@ -153,6 +154,7 @@ | ||
| 153 | 154 | paths: vec![b"x".to_vec()], |
| 154 | 155 | author: None, |
| 155 | 156 | committer: ada(), |
| 157 | + agent: "tester".to_owned(), | |
| 156 | 158 | force: false, |
| 157 | 159 | }); |
| 158 | 160 | assert!( |
| @@ -167,6 +169,7 @@ | ||
| 167 | 169 | paths: Vec::new(), |
| 168 | 170 | author: None, |
| 169 | 171 | committer: ada(), |
| 172 | + agent: "tester".to_owned(), | |
| 170 | 173 | force: false, |
| 171 | 174 | }) |
| 172 | 175 | .unwrap(); |
| @@ -263,6 +266,7 @@ | ||
| 263 | 266 | paths: Vec::new(), |
| 264 | 267 | author: None, |
| 265 | 268 | committer: ada(), |
| 269 | + agent: "tester".to_owned(), | |
| 266 | 270 | force: false, |
| 267 | 271 | }), |
| 268 | 272 | Err(Error::NothingToCommit) |
| @@ -274,6 +278,7 @@ | ||
| 274 | 278 | paths: Vec::new(), |
| 275 | 279 | author: None, |
| 276 | 280 | committer: ada(), |
| 281 | + agent: "tester".to_owned(), | |
| 277 | 282 | force: false, |
| 278 | 283 | }), |
| 279 | 284 | Err(Error::NoMessage) |