Skip to content

Commit

Permalink
lib: remove support for legacy (non-tree) conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Seipp <[email protected]>
  • Loading branch information
thoughtpolice committed Oct 18, 2024
1 parent 0ec426d commit dc6de08
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 236 deletions.
16 changes: 8 additions & 8 deletions cli/tests/test_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ fn test_op_abandon_ancestors() {
Abandoned 2 operations and reparented 1 descendant operations.
"#);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r###"
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r#"
Current operation: OperationId("8545e013752445fd845c84eb961dbfbce47e1deb628e4ef20df10f6dc9aae2ef9e47200b0fcc70ca51f050aede05d0fa6dd1db40e20ae740876775738a07d02e")
Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904")))
"###);
Current tree: Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))
"#);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "log"]), @r###"
@ 8545e0137524 [email protected] 2001-02-03 04:05:09.000 +07:00 - 2001-02-03 04:05:09.000 +07:00
│ commit 81a4ef3dd421f3184289df1c58bd3a16ea1e3d8e
Expand Down Expand Up @@ -527,10 +527,10 @@ fn test_op_abandon_ancestors() {
Abandoned 1 operations and reparented 1 descendant operations.
"###);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r###"
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r#"
Current operation: OperationId("0699d720d0cecd80fb7d765c45955708c61b12feb1d7ed9ff2777ae719471f04ffed3c1dc24efdbf94bdb74426065d6fa9a4f0862a89db2c8c8e359eefc45462")
Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904")))
"###);
Current tree: Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))
"#);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "log"]), @r###"
@ 0699d720d0ce [email protected] 2001-02-03 04:05:21.000 +07:00 - 2001-02-03 04:05:21.000 +07:00
│ undo operation d92d0753399f732e438bdd88fa7e5214cba2a310d120ec1714028a514c7116bcf04b4a0b26c04dbecf0a917f1d4c8eb05571b8816dd98b0502aaf321e92500b3
Expand Down Expand Up @@ -574,7 +574,7 @@ fn test_op_abandon_without_updating_working_copy() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r#"
Current operation: OperationId("b0711a8ac91f5ac088cff9b57c9daf29dc61b1b4fedcbb9a07fe4c7f7da1e60e333c787eacf73d1e0544db048a4fe9c6c089991b4a67e25365c4f411fa8b489f")
Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904")))
Current tree: Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))
"#);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["op", "log", "-n1", "--ignore-working-copy"]), @r#"
Expand All @@ -594,7 +594,7 @@ fn test_op_abandon_without_updating_working_copy() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["debug", "local-working-copy", "--ignore-working-copy"]), @r#"
Current operation: OperationId("b0711a8ac91f5ac088cff9b57c9daf29dc61b1b4fedcbb9a07fe4c7f7da1e60e333c787eacf73d1e0544db048a4fe9c6c089991b4a67e25365c4f411fa8b489f")
Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904")))
Current tree: Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))
"#);
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["op", "log", "-n1", "--ignore-working-copy"]), @r#"
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_util_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn test_gc_operation_log() {
// Now this doesn't work.
let stderr = test_env.jj_cmd_failure(&repo_path, &["debug", "operation", &op_to_remove]);
insta::assert_snapshot!(stderr, @r#"
Error: No operation ID matching "8382f401329617b0c91a63354b86ca48fc28dee8d7a916fdad5310030f9a1260e969c43ed2b13d1d48eaf38f6f45541ecf593bcb6105495d514d21b3b6a98846"
Error: No operation ID matching "528205ec2c5cf94319e7c30e0b42f841812ff66c19e6d46f4099208a940e6758a9bd32b8f26bb5514a2e141b23fc02b24306fa58ba4f2ff7c14f753af0e69604"
"#);
}

Expand Down
58 changes: 29 additions & 29 deletions cli/tests/test_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,28 +658,28 @@ fn test_workspaces_current_op_discarded_by_other() {
],
);
insta::assert_snapshot!(stdout, @r#"
@ 757bc1140b abandon commit 20dd439c4bd12c6ad56c187ac490bd0141804618f638dc5c4dc92ff9aecba20f152b23160db9dcf61beb31a5cb14091d9def5a36d11c9599cc4d2e5689236af1
8d4abed655 create initial working-copy commit in workspace secondary
3de27432e5 add workspace 'secondary'
bcf69de808 new empty commit
a36b99a15c snapshot working copy
ddf023d319 new empty commit
829c93f6a3 snapshot working copy
2557266dd2 add workspace 'default'
@ 28cd5cdd88 abandon commit 5eaf6e87919b87ce8078cecd6a6216606601e7372eebc1c9a791595ce8fe7963a9bdd8c56640f2e14baac9e62efb4fccc0c5b3d8e21a95e877b20bc8c20e73d5
44fbe961e3 create initial working-copy commit in workspace secondary
114173706e add workspace 'secondary'
1ad55160ae new empty commit
c9efb83077 snapshot working copy
243778e06d new empty commit
0b530a766d snapshot working copy
ffbb23b00f add workspace 'default'
○ 0000000000
"#);

// Abandon ops, including the one the secondary workspace is currently on.
test_env.jj_cmd_ok(&main_path, &["operation", "abandon", "..@-"]);
test_env.jj_cmd_ok(&main_path, &["util", "gc", "--expire=now"]);

insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
○ 96b31dafdc41 secondary@
@ 6c051bd1ccd5 default@
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r#"
@ 214eef6a63cb default@
○ 1451cf1f1398 secondary@
├─╯
7c5b25a4fc8f
b431c7611a06
◆ 000000000000
"###);
"#);

let stderr = test_env.jj_cmd_failure(&secondary_path, &["st"]);
insta::assert_snapshot!(stderr, @r###"
Expand All @@ -690,19 +690,19 @@ fn test_workspaces_current_op_discarded_by_other() {

let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["workspace", "update-stale"]);
insta::assert_snapshot!(stderr, @r#"
Failed to read working copy's current operation; attempting recovery. Error message from read attempt: Object 8d4abed655badb70b1bab62aa87136619dbc3c8015a8ce8dfb7abfeca4e2f36c713d8f84e070a0613907a6cee7e1cc05323fe1205a319b93fe978f11a060c33c of type operation not found
Created and checked out recovery commit 62f70695e3b0
Failed to read working copy's current operation; attempting recovery. Error message from read attempt: Object 44fbe961e37a84af0908d31684571660b28fbe0db71d39abd16a8385200cd048b81a529a5e3988a64dad7fb5a8223545d330316e4f629cf6453b937ed2a17355 of type operation not found
Created and checked out recovery commit 44b50c0d749c
"#);
insta::assert_snapshot!(stdout, @"");

insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r###"
b0b400439a82 secondary@
96b31dafdc41
│ @ 6c051bd1ccd5 default@
insta::assert_snapshot!(get_log_output(&test_env, &main_path), @r#"
547a8f368e77 secondary@
1451cf1f1398
│ @ 214eef6a63cb default@
├─╯
7c5b25a4fc8f
b431c7611a06
◆ 000000000000
"###);
"#);

// The sparse patterns should remain
let stdout = test_env.jj_cmd_success(&secondary_path, &["sparse", "list"]);
Expand All @@ -713,14 +713,14 @@ fn test_workspaces_current_op_discarded_by_other() {
"###);
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["st"]);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
insta::assert_snapshot!(stdout, @r#"
Working copy changes:
A added
D deleted
M modified
Working copy : kmkuslsw b0b40043 (no description set)
Parent commit: rzvqmyuk 96b31daf (empty) (no description set)
"###);
Working copy : kmkuslsw 547a8f36 (no description set)
Parent commit: rzvqmyuk 1451cf1f (empty) (no description set)
"#);
// The modified file should have the same contents it had before (not reset to
// the base contents)
insta::assert_snapshot!(std::fs::read_to_string(secondary_path.join("modified")).unwrap(), @r###"
Expand All @@ -729,12 +729,12 @@ fn test_workspaces_current_op_discarded_by_other() {

let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["evolog"]);
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(stdout, @r###"
@ kmkuslsw [email protected] 2001-02-03 08:05:18 secondary@ b0b40043
insta::assert_snapshot!(stdout, @r#"
@ kmkuslsw [email protected] 2001-02-03 08:05:18 secondary@ 547a8f36
│ (no description set)
○ kmkuslsw hidden [email protected] 2001-02-03 08:05:18 62f70695
○ kmkuslsw hidden [email protected] 2001-02-03 08:05:18 44b50c0d
(empty) (no description set)
"###);
"#);
}

#[test]
Expand Down
36 changes: 1 addition & 35 deletions lib/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,41 +103,7 @@ pub type SigningFn<'a> = dyn FnMut(&[u8]) -> SignResult<Vec<u8>> + Send + 'a;

/// Identifies a single legacy tree, which may have path-level conflicts, or a
/// merge of multiple trees, where the individual trees do not have conflicts.
// TODO(#1624): Delete this type at some point in the future, when we decide to drop
// support for conflicts in older repos, or maybe after we have provided an upgrade
// mechanism.
#[derive(ContentHash, Debug, Clone)]
pub enum MergedTreeId {
/// The tree id of a legacy tree
Legacy(TreeId),
/// The tree id(s) of a merge tree
Merge(Merge<TreeId>),
}

impl PartialEq for MergedTreeId {
/// Overridden to make conflict-free trees be considered equal even if their
/// `MergedTreeId` variant is different.
fn eq(&self, other: &Self) -> bool {
self.to_merge() == other.to_merge()
}
}

impl Eq for MergedTreeId {}

impl MergedTreeId {
/// Create a resolved `MergedTreeId` from a single regular tree.
pub fn resolved(tree_id: TreeId) -> Self {
MergedTreeId::Merge(Merge::resolved(tree_id))
}

/// Return this id as `Merge<TreeId>`
pub fn to_merge(&self) -> Merge<TreeId> {
match self {
MergedTreeId::Legacy(tree_id) => Merge::resolved(tree_id.clone()),
MergedTreeId::Merge(tree_ids) => tree_ids.clone(),
}
}
}
pub type MergedTreeId = Merge<TreeId>;

#[derive(ContentHash, Debug, PartialEq, Eq, Clone)]
pub struct Commit {
Expand Down
6 changes: 1 addition & 5 deletions lib/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ impl Commit {
}

pub fn has_conflict(&self) -> BackendResult<bool> {
if let MergedTreeId::Merge(tree_ids) = self.tree_id() {
Ok(!tree_ids.is_resolved())
} else {
Ok(self.tree()?.has_conflict())
}
Ok(!self.tree_id().is_resolved())
}

pub fn change_id(&self) -> &ChangeId {
Expand Down
Loading

0 comments on commit dc6de08

Please sign in to comment.