Debian Codegraph @

cli/src/commands/debug/mod.rs

raw
1 // Copyright 2023 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 mod copy_detection;
16 mod fileset;
17 mod index;
18 mod index_changed_paths;
19 mod init_simple;
20 mod local_working_copy;
21 mod object;
22 mod reindex;
23 mod revset;
24 mod snapshot;
25 mod stacked_table;
26 mod template;
27 mod tree;
28 mod watchman;
29 mod working_copy;
30
31 use clap::Subcommand;
32 use jj_lib::local_working_copy::LocalWorkingCopy;
33 use jj_lib::working_copy::WorkingCopy;
34
35 use self::copy_detection::CopyDetectionArgs;
36 use self::copy_detection::cmd_debug_copy_detection;
37 use self::fileset::DebugFilesetArgs;
38 use self::fileset::cmd_debug_fileset;
39 use self::index::DebugIndexArgs;
40 use self::index::cmd_debug_index;
41 use self::index_changed_paths::DebugIndexChangedPathsArgs;
42 use self::index_changed_paths::cmd_debug_index_changed_paths;
43 use self::init_simple::DebugInitSimpleArgs;
44 use self::init_simple::cmd_debug_init_simple;
45 use self::local_working_copy::DebugLocalWorkingCopyArgs;
46 use self::local_working_copy::cmd_debug_local_working_copy;
47 use self::object::DebugObjectArgs;
48 use self::object::cmd_debug_object;
49 use self::reindex::DebugReindexArgs;
50 use self::reindex::cmd_debug_reindex;
51 use self::revset::DebugRevsetArgs;
52 use self::revset::cmd_debug_revset;
53 use self::snapshot::DebugSnapshotArgs;
54 use self::snapshot::cmd_debug_snapshot;
55 use self::stacked_table::DebugStackedTableArgs;
56 use self::stacked_table::cmd_debug_stacked_table;
57 use self::template::DebugTemplateArgs;
58 use self::template::cmd_debug_template;
59 use self::tree::DebugTreeArgs;
60 use self::tree::cmd_debug_tree;
61 use self::watchman::DebugWatchmanCommand;
62 use self::watchman::cmd_debug_watchman;
63 use self::working_copy::DebugWorkingCopyArgs;
64 use self::working_copy::cmd_debug_working_copy;
65 use crate::cli_util::CommandHelper;
66 use crate::command_error::CommandError;
67 use crate::command_error::user_error;
68 use crate::ui::Ui;
69
70 /// Low-level commands not intended for users
71 #[derive(Subcommand, Clone, Debug)]
72 #[command(hide = true)]
73 pub enum DebugCommand {
74 CopyDetection(CopyDetectionArgs),
75 Fileset(DebugFilesetArgs),
76 Index(DebugIndexArgs),
77 IndexChangedPaths(DebugIndexChangedPathsArgs),
78 InitSimple(DebugInitSimpleArgs),
79 LocalWorkingCopy(DebugLocalWorkingCopyArgs),
80 #[command(subcommand)]
81 Object(DebugObjectArgs),
82 Reindex(DebugReindexArgs),
83 Revset(DebugRevsetArgs),
84 Snapshot(DebugSnapshotArgs),
85 StackedTable(DebugStackedTableArgs),
86 Template(DebugTemplateArgs),
87 Tree(DebugTreeArgs),
88 #[command(subcommand)]
89 Watchman(DebugWatchmanCommand),
90 WorkingCopy(DebugWorkingCopyArgs),
91 }
92
93 pub async fn cmd_debug(
94 ui: &mut Ui,
95 command: &CommandHelper,
96 subcommand: &DebugCommand,
97 ) -> Result<(), CommandError> {
98 match subcommand {
99 DebugCommand::CopyDetection(args) => cmd_debug_copy_detection(ui, command, args).await,
100 DebugCommand::Fileset(args) => cmd_debug_fileset(ui, command, args).await,
101 DebugCommand::Index(args) => cmd_debug_index(ui, command, args).await,
102 DebugCommand::IndexChangedPaths(args) => {
103 cmd_debug_index_changed_paths(ui, command, args).await
104 }
105 DebugCommand::InitSimple(args) => cmd_debug_init_simple(ui, command, args).await,
106 DebugCommand::LocalWorkingCopy(args) => {
107 cmd_debug_local_working_copy(ui, command, args).await
108 }
109 DebugCommand::Object(args) => cmd_debug_object(ui, command, args).await,
110 DebugCommand::Reindex(args) => cmd_debug_reindex(ui, command, args).await,
111 DebugCommand::Revset(args) => cmd_debug_revset(ui, command, args).await,
112 DebugCommand::Snapshot(args) => cmd_debug_snapshot(ui, command, args).await,
113 DebugCommand::StackedTable(args) => cmd_debug_stacked_table(ui, command, args).await,
114 DebugCommand::Template(args) => cmd_debug_template(ui, command, args).await,
115 DebugCommand::Tree(args) => cmd_debug_tree(ui, command, args).await,
116 DebugCommand::Watchman(args) => cmd_debug_watchman(ui, command, args).await,
117 DebugCommand::WorkingCopy(args) => cmd_debug_working_copy(ui, command, args).await,
118 }
119 }
120
121 fn check_local_disk_wc(x: &dyn WorkingCopy) -> Result<&LocalWorkingCopy, CommandError> {
122 x.downcast_ref()
123 .ok_or_else(|| user_error("This command requires a standard local-disk working copy"))
124 }