forked from mirrors/jj
cli: add jj op log --no-graph
Seems useful, and makes it consistent with the `jj log` and `jj obslog`.
This commit is contained in:
parent
fc86d91b15
commit
8bfb6c10fd
3 changed files with 58 additions and 26 deletions
|
@ -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
|
* Support for the Watchman filesystem monitor is now bundled by default. Set
|
||||||
`core.fsmonitor = "watchman"` in your repo to enable.
|
`core.fsmonitor = "watchman"` in your repo to enable.
|
||||||
|
|
||||||
|
* `jj op log` now supports `--no-graph`.
|
||||||
|
|
||||||
### Fixed bugs
|
### Fixed bugs
|
||||||
|
|
||||||
## [0.9.0] - 2023-09-06
|
## [0.9.0] - 2023-09-06
|
||||||
|
|
|
@ -29,6 +29,9 @@ pub struct OperationLogArgs {
|
||||||
/// Limit number of operations to show
|
/// Limit number of operations to show
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
|
/// Don't show the graph, show a flat list of operations
|
||||||
|
#[arg(long)]
|
||||||
|
no_graph: bool,
|
||||||
/// Render each operation using the given template
|
/// Render each operation using the given template
|
||||||
///
|
///
|
||||||
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
|
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
|
||||||
|
@ -120,9 +123,11 @@ fn cmd_op_log(
|
||||||
ui.request_pager();
|
ui.request_pager();
|
||||||
let mut formatter = ui.stdout_formatter();
|
let mut formatter = ui.stdout_formatter();
|
||||||
let formatter = formatter.as_mut();
|
let formatter = formatter.as_mut();
|
||||||
|
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 mut graph = get_graphlog(command.settings(), formatter.raw());
|
||||||
let default_node_symbol = graph.default_node_symbol().to_owned();
|
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)) {
|
for op in iter {
|
||||||
let mut edges = vec![];
|
let mut edges = vec![];
|
||||||
for parent in op.parents() {
|
for parent in op.parents() {
|
||||||
edges.push(Edge::direct(parent.id().clone()));
|
edges.push(Edge::direct(parent.id().clone()));
|
||||||
|
@ -131,7 +136,9 @@ fn cmd_op_log(
|
||||||
let mut buffer = vec![];
|
let mut buffer = vec![];
|
||||||
with_content_format.write_graph_text(
|
with_content_format.write_graph_text(
|
||||||
ui.new_formatter(&mut buffer).as_mut(),
|
ui.new_formatter(&mut buffer).as_mut(),
|
||||||
|formatter| formatter.with_label("op_log", |formatter| template.format(&op, formatter)),
|
|formatter| {
|
||||||
|
formatter.with_label("op_log", |formatter| template.format(&op, formatter))
|
||||||
|
},
|
||||||
|| graph.width(op.id(), &edges),
|
|| graph.width(op.id(), &edges),
|
||||||
)?;
|
)?;
|
||||||
if !buffer.ends_with(b"\n") {
|
if !buffer.ends_with(b"\n") {
|
||||||
|
@ -149,6 +156,13 @@ fn cmd_op_log(
|
||||||
&String::from_utf8_lossy(&buffer),
|
&String::from_utf8_lossy(&buffer),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for op in iter {
|
||||||
|
with_content_format.write(formatter, |formatter| {
|
||||||
|
formatter.with_label("op_log", |formatter| template.format(&op, formatter))
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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###"
|
||||||
|
[1m[38;5;12m19b8089fc78b[39m [38;5;3mtest-username@host.example.com[39m [38;5;14m2001-02-03 04:05:07.000 +07:00[39m - [38;5;14m2001-02-03 04:05:07.000 +07:00[39m[0m
|
||||||
|
[1madd workspace 'default'[0m
|
||||||
|
[38;5;4mf1c462c494be[39m [38;5;3mtest-username@host.example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m - [38;5;6m2001-02-03 04:05:07.000 +07:00[39m
|
||||||
|
initialize repo
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_op_log_template() {
|
fn test_op_log_template() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue