working copy: return Box<dyn WorkingCopy> from finish()

This commit is contained in:
Martin von Zweigbergk 2023-10-13 22:46:28 -07:00 committed by Martin von Zweigbergk
parent 6a13fa8264
commit 580586d008
9 changed files with 61 additions and 37 deletions

View file

@ -41,7 +41,7 @@ use jj_lib::git_backend::GitBackend;
use jj_lib::gitignore::GitIgnoreFile;
use jj_lib::hex_util::to_reverse_hex;
use jj_lib::id_prefix::IdPrefixContext;
use jj_lib::local_working_copy::{LocalWorkingCopy, LockedLocalWorkingCopy};
use jj_lib::local_working_copy::LockedLocalWorkingCopy;
use jj_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher, Visit};
use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder};
use jj_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
@ -853,7 +853,7 @@ impl WorkspaceCommandHelper {
&self.user_repo.repo
}
pub fn working_copy(&self) -> &LocalWorkingCopy {
pub fn working_copy(&self) -> &dyn WorkingCopy {
self.workspace.working_copy()
}

View file

@ -12,14 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::any::Any;
use std::fmt::Debug;
use std::io::Write as _;
use clap::Subcommand;
use jj_lib::backend::ObjectId;
use jj_lib::default_index_store::{DefaultIndexStore, ReadonlyIndexWrapper};
use jj_lib::local_working_copy::{LocalWorkingCopy, LockedLocalWorkingCopy};
use jj_lib::revset;
use jj_lib::working_copy::WorkingCopy;
use jj_lib::working_copy::{LockedWorkingCopy, WorkingCopy};
use crate::cli_util::{resolve_op_for_load, user_error, CommandError, CommandHelper};
use crate::template_parser;
@ -103,7 +105,7 @@ pub fn cmd_debug(
DebugCommands::Revset(args) => cmd_debug_revset(ui, command, args)?,
DebugCommands::WorkingCopy(_wc_matches) => {
let workspace_command = command.workspace_helper(ui)?;
let wc = workspace_command.working_copy();
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
writeln!(ui.stdout(), "Current operation: {:?}", wc.operation_id())?;
writeln!(ui.stdout(), "Current tree: {:?}", wc.tree_id()?)?;
for (file, state) in wc.file_states()? {
@ -250,16 +252,25 @@ fn cmd_debug_watchman(
let repo = workspace_command.repo().clone();
match subcommand {
DebugWatchmanSubcommand::QueryClock => {
let (clock, _changed_files) = workspace_command.working_copy().query_watchman()?;
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let (clock, _changed_files) = wc.query_watchman()?;
writeln!(ui.stdout(), "Clock: {clock:?}")?;
}
DebugWatchmanSubcommand::QueryChangedFiles => {
let (_clock, changed_files) = workspace_command.working_copy().query_watchman()?;
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let (_clock, changed_files) = wc.query_watchman()?;
writeln!(ui.stdout(), "Changed files: {changed_files:?}")?;
}
DebugWatchmanSubcommand::ResetClock => {
let (mut locked_ws, _commit) = workspace_command.start_working_copy_mutation()?;
locked_ws.locked_wc().reset_watchman()?;
let Some(locked_local_wc): Option<&mut LockedLocalWorkingCopy> =
locked_ws.locked_wc().as_any_mut().downcast_mut()
else {
return Err(user_error(
"This command requires a standard local-disk working copy",
));
};
locked_local_wc.reset_watchman()?;
locked_ws.finish(repo.op_id().clone())?;
writeln!(ui.stderr(), "Reset Watchman clock")?;
}
@ -277,3 +288,8 @@ fn cmd_debug_watchman(
"Cannot query Watchman because jj was not compiled with the `watchman` feature",
))
}
fn check_local_disk_wc(x: &dyn Any) -> Result<&LocalWorkingCopy, CommandError> {
x.downcast_ref()
.ok_or_else(|| user_error("This command requires a standard local-disk working copy"))
}

View file

@ -47,7 +47,7 @@ use jj_lib::revset_graph::{
};
use jj_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit, DescendantRebaser};
use jj_lib::settings::UserSettings;
use jj_lib::working_copy::{LockedWorkingCopy, SnapshotOptions, WorkingCopy};
use jj_lib::working_copy::{LockedWorkingCopy, SnapshotOptions};
use jj_lib::workspace::Workspace;
use jj_lib::{conflicts, file_util, revset};
use maplit::{hashmap, hashset};