Skip to content

Commit

Permalink
Add jj debug snapshot command and use it in trigger
Browse files Browse the repository at this point in the history
The command only takes a snapshot and avoids other overhead, so it can
be used as a target for the watchman trigger that gets installed.
  • Loading branch information
fowles committed Jun 19, 2024
1 parent 3ebad15 commit 3e7ad4d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cli/src/commands/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod index;
pub mod operation;
pub mod reindex;
pub mod revset;
pub mod snapshot;
pub mod template;
pub mod tree;
pub mod watchman;
Expand All @@ -33,6 +34,7 @@ use self::index::{cmd_debug_index, IndexArgs};
use self::operation::{cmd_debug_operation, OperationArgs};
use self::reindex::{cmd_debug_reindex, ReindexArgs};
use self::revset::{cmd_debug_revset, RevsetArgs};
use self::snapshot::{cmd_debug_snapshot, SnapshotArgs};
use self::template::{cmd_debug_template, TemplateArgs};
use self::tree::{cmd_debug_tree, TreeArgs};
use self::watchman::{cmd_debug_watchman, WatchmanCommand};
Expand All @@ -57,6 +59,7 @@ pub enum DebugCommand {
Tree(TreeArgs),
#[command(subcommand)]
Watchman(WatchmanCommand),
Snapshot(SnapshotArgs),
}

pub fn cmd_debug(
Expand All @@ -74,6 +77,7 @@ pub fn cmd_debug(
DebugCommand::Operation(args) => cmd_debug_operation(ui, command, args),
DebugCommand::Tree(args) => cmd_debug_tree(ui, command, args),
DebugCommand::Watchman(args) => cmd_debug_watchman(ui, command, args),
DebugCommand::Snapshot(args) => cmd_debug_snapshot(ui, command, args),
}
}

Expand Down
33 changes: 33 additions & 0 deletions cli/src/commands/debug/snapshot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt::Debug;

use crate::cli_util::CommandHelper;
use crate::command_error::CommandError;
use crate::ui::Ui;

/// Trigger a snapshot in the op log
#[derive(clap::Args, Clone, Debug)]
pub struct SnapshotArgs {}

pub fn cmd_debug_snapshot(
ui: &mut Ui,
command: &CommandHelper,
_args: &SnapshotArgs,
) -> Result<(), CommandError> {
// workspace helper will snapshot as needed
command.workspace_helper(ui)?;
Ok(())
}
36 changes: 36 additions & 0 deletions cli/tests/test_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,42 @@ fn test_workspaces_root() {
"###);
}

#[test]
fn test_debug_snapshot() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let repo_path = test_env.env_root().join("repo");

std::fs::write(repo_path.join("file"), "contents").unwrap();
test_env.jj_cmd_ok(&repo_path, &["debug", "snapshot"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
insta::assert_snapshot!(stdout, @r###"
@ 2d01fc903f0f [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
│ snapshot working copy
│ args: jj debug snapshot
◉ b51416386f26 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ add workspace 'default'
◉ 9a7d829846af [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ initialize repo
◉ 000000000000 root()
"###);
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
insta::assert_snapshot!(stdout, @r###"
@ 53a64275e379 [email protected] 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00
│ describe commit 123ed18e4c4c0d77428df41112bc02ffc83fb935
│ args: jj describe -m initial
◉ 2d01fc903f0f [email protected] 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
│ snapshot working copy
│ args: jj debug snapshot
◉ b51416386f26 [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ add workspace 'default'
◉ 9a7d829846af [email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
│ initialize repo
◉ 000000000000 root()
"###);
}

fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"
separate(" ",
Expand Down
5 changes: 2 additions & 3 deletions lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,8 @@ pub mod watchman {
name: "jj-background-monitor".to_string(),
command: vec![
"jj".to_string(),
"files".to_string(),
"-r".to_string(),
"root()".to_string(),
"debug".to_string(),
"snapshot".to_string(),
],
expression: Some(self.build_exclude_expr()),
..Default::default()
Expand Down

0 comments on commit 3e7ad4d

Please sign in to comment.