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
|
||||
`core.fsmonitor = "watchman"` in your repo to enable.
|
||||
|
||||
* `jj op log` now supports `--no-graph`.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
## [0.9.0] - 2023-09-06
|
||||
|
|
|
@ -29,6 +29,9 @@ pub struct OperationLogArgs {
|
|||
/// Limit number of operations to show
|
||||
#[arg(long, short)]
|
||||
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
|
||||
///
|
||||
/// 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(())
|
||||
|
|
|
@ -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]
|
||||
fn test_op_log_template() {
|
||||
let test_env = TestEnvironment::default();
|
||||
|
|
Loading…
Reference in a new issue