ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: migrate jj untrack to MergedTree API

This commit is contained in:
Martin von Zweigbergk 2023-08-27 09:24:02 -07:00 committed by Martin von Zweigbergk
parent 6d89f0c0a0
commit b19afb6d45

View file

@ -1323,27 +1323,26 @@ fn cmd_untrack(
let base_ignores = workspace_command.base_ignores(); let base_ignores = workspace_command.base_ignores();
let (mut locked_working_copy, wc_commit) = workspace_command.start_working_copy_mutation()?; let (mut locked_working_copy, wc_commit) = workspace_command.start_working_copy_mutation()?;
// Create a new tree without the unwanted files // Create a new tree without the unwanted files
let mut tree_builder = store.tree_builder(wc_commit.tree_id().clone()); let mut tree_builder =
for (path, _value) in wc_commit.tree().entries_matching(matcher.as_ref()) { MergedTreeBuilder::new(store.clone(), wc_commit.merged_tree_id().clone());
tree_builder.remove(path); let wc_tree = wc_commit.merged_tree()?;
for (path, _value) in wc_tree.entries_matching(matcher.as_ref()) {
tree_builder.set_or_remove(path, Merge::absent());
} }
let new_tree_id = tree_builder.write_tree(); let new_tree_id = tree_builder.write_tree()?;
let new_tree = store.get_tree(&RepoPath::root(), &new_tree_id)?; let new_tree = store.get_root_tree(&new_tree_id)?;
let new_tree = MergedTree::legacy(new_tree);
// Reset the working copy to the new tree // Reset the working copy to the new tree
locked_working_copy.reset(&new_tree)?; locked_working_copy.reset(&new_tree)?;
// Commit the working copy again so we can inform the user if paths couldn't be // Commit the working copy again so we can inform the user if paths couldn't be
// untracked because they're not ignored. // untracked because they're not ignored.
let wc_tree_id = locked_working_copy let wc_tree_id = locked_working_copy.snapshot(SnapshotOptions {
.snapshot(SnapshotOptions {
base_ignores, base_ignores,
fsmonitor_kind: command.settings().fsmonitor_kind()?, fsmonitor_kind: command.settings().fsmonitor_kind()?,
progress: None, progress: None,
max_new_file_size: command.settings().max_new_file_size()?, max_new_file_size: command.settings().max_new_file_size()?,
})? })?;
.to_legacy_tree_id();
if wc_tree_id != new_tree_id { if wc_tree_id != new_tree_id {
let wc_tree = store.get_tree(&RepoPath::root(), &wc_tree_id)?; let wc_tree = store.get_root_tree(&wc_tree_id)?;
let added_back = wc_tree.entries_matching(matcher.as_ref()).collect_vec(); let added_back = wc_tree.entries_matching(matcher.as_ref()).collect_vec();
if !added_back.is_empty() { if !added_back.is_empty() {
locked_working_copy.discard(); locked_working_copy.discard();
@ -1371,7 +1370,7 @@ Make sure they're ignored, then try again.",
} }
tx.mut_repo() tx.mut_repo()
.rewrite_commit(command.settings(), &wc_commit) .rewrite_commit(command.settings(), &wc_commit)
.set_tree(new_tree_id) .set_tree_id(new_tree_id)
.write()?; .write()?;
let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?; let num_rebased = tx.mut_repo().rebase_descendants(command.settings())?;
if num_rebased > 0 { if num_rebased > 0 {