From 8bfb6c10fd8781b8a8729719fe0826637b22c86d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 10 Sep 2023 09:34:30 -0700 Subject: [PATCH] cli: add `jj op log --no-graph` Seems useful, and makes it consistent with the `jj log` and `jj obslog`. --- CHANGELOG.md | 2 ++ cli/src/commands/operation.rs | 66 +++++++++++++++++++++-------------- cli/tests/test_operations.rs | 16 +++++++++ 3 files changed, 58 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a2267596..7b5348c85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Support for the Watchman filesystem monitor is now bundled by default. Set `core.fsmonitor = "watchman"` in your repo to enable. +* `jj op log` now supports `--no-graph`. + ### Fixed bugs ## [0.9.0] - 2023-09-06 diff --git a/cli/src/commands/operation.rs b/cli/src/commands/operation.rs index daf3f78dd..991798372 100644 --- a/cli/src/commands/operation.rs +++ b/cli/src/commands/operation.rs @@ -29,6 +29,9 @@ pub struct OperationLogArgs { /// Limit number of operations to show #[arg(long, short)] limit: Option, + /// Don't show the graph, show a flat list of operations + #[arg(long)] + no_graph: bool, /// Render each operation using the given template /// /// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md @@ -120,34 +123,45 @@ fn cmd_op_log( ui.request_pager(); let mut formatter = ui.stdout_formatter(); let formatter = formatter.as_mut(); - let mut graph = get_graphlog(command.settings(), formatter.raw()); - let default_node_symbol = graph.default_node_symbol().to_owned(); - for op in operation::walk_ancestors(&head_op).take(args.limit.unwrap_or(usize::MAX)) { - let mut edges = vec![]; - for parent in op.parents() { - edges.push(Edge::direct(parent.id().clone())); + let iter = operation::walk_ancestors(&head_op).take(args.limit.unwrap_or(usize::MAX)); + if !args.no_graph { + let mut graph = get_graphlog(command.settings(), formatter.raw()); + let default_node_symbol = graph.default_node_symbol().to_owned(); + for op in iter { + let mut edges = vec![]; + for parent in op.parents() { + edges.push(Edge::direct(parent.id().clone())); + } + let is_head_op = op.id() == &head_op_id; + let mut buffer = vec![]; + with_content_format.write_graph_text( + ui.new_formatter(&mut buffer).as_mut(), + |formatter| { + formatter.with_label("op_log", |formatter| template.format(&op, formatter)) + }, + || graph.width(op.id(), &edges), + )?; + if !buffer.ends_with(b"\n") { + buffer.push(b'\n'); + } + let node_symbol = if is_head_op { + "@" + } else { + &default_node_symbol + }; + graph.add_node( + op.id(), + &edges, + node_symbol, + &String::from_utf8_lossy(&buffer), + )?; } - let is_head_op = op.id() == &head_op_id; - let mut buffer = vec![]; - with_content_format.write_graph_text( - ui.new_formatter(&mut buffer).as_mut(), - |formatter| formatter.with_label("op_log", |formatter| template.format(&op, formatter)), - || graph.width(op.id(), &edges), - )?; - if !buffer.ends_with(b"\n") { - buffer.push(b'\n'); + } else { + for op in iter { + with_content_format.write(formatter, |formatter| { + formatter.with_label("op_log", |formatter| template.format(&op, formatter)) + })?; } - let node_symbol = if is_head_op { - "@" - } else { - &default_node_symbol - }; - graph.add_node( - op.id(), - &edges, - node_symbol, - &String::from_utf8_lossy(&buffer), - )?; } Ok(()) diff --git a/cli/tests/test_operations.rs b/cli/tests/test_operations.rs index 856bd23c6..08340c208 100644 --- a/cli/tests/test_operations.rs +++ b/cli/tests/test_operations.rs @@ -130,6 +130,22 @@ fn test_op_log_limit() { "###); } +#[test] +fn test_op_log_no_graph() { + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + let stdout = + test_env.jj_cmd_success(&repo_path, &["op", "log", "--no-graph", "--color=always"]); + insta::assert_snapshot!(stdout, @r###" + 19b8089fc78b test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 + add workspace 'default' + f1c462c494be test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 + initialize repo + "###); +} + #[test] fn test_op_log_template() { let test_env = TestEnvironment::default();