Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: add jj op log --no-graph #2243

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
66 changes: 40 additions & 26 deletions cli/src/commands/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
Expand Down
16 changes: 16 additions & 0 deletions cli/tests/test_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [38;5;[email protected] 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
add workspace 'default'
f1c462c494be [38;5;[email protected] 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();
Expand Down