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

Drop support for legacy graph drawing, add support for synthetic nodes for elided revisions #3027

Merged
merged 3 commits into from
Feb 13, 2024
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
reindexing failed, you'll need to clean up corrupted operation history by
`jj op abandon ..<bad operation ID>`.

* Dropped support for the "legacy" graph-drawing style. Use "ascii" for a very
similar result.

### New features

* Templates now support logical operators: `||`, `&&`, `!`
Expand All @@ -37,6 +40,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Built-in pager based on [minus](https://github.com/arijit79/minus/)

* Set config `ui.log-synthetic-elided-nodes = true` to make `jj log` include
synthetic nodes in the graph where some revisions were elided
([#1252](https://github.com/martinvonz/jj/issues/1252),
[#2971](https://github.com/martinvonz/jj/issues/2971)). This may become the
default depending on feedback.

### Fixed bugs

* On Windows, symlinks in the repo are now materialized as regular files in the
Expand Down
64 changes: 52 additions & 12 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ pub(crate) fn cmd_log(
Some(value) => value.to_string(),
None => command.settings().config().get_string("templates.log")?,
};
let use_elided_nodes = command
.settings()
.config()
.get_bool("ui.log-synthetic-elided-nodes")?;
let template = workspace_command.parse_commit_template(&template_string)?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;

Expand All @@ -115,42 +119,58 @@ pub(crate) fn cmd_log(
if !args.no_graph {
let mut graph = get_graphlog(command.settings(), formatter.raw());
let default_node_symbol = graph.default_node_symbol().to_owned();
let elided_node_symbol = graph.elided_node_symbol().to_owned();
let forward_iter = TopoGroupedRevsetGraphIterator::new(revset.iter_graph());
let iter: Box<dyn Iterator<Item = _>> = if args.reversed {
Box::new(ReverseRevsetGraphIterator::new(forward_iter))
} else {
Box::new(forward_iter)
};
for (commit_id, edges) in iter.take(args.limit.unwrap_or(usize::MAX)) {
// The graph is keyed by (CommitId, is_synthetic)
let mut graphlog_edges = vec![];
// TODO: Should we update RevsetGraphIterator to yield this flag instead of all
// the missing edges since we don't care about where they point here
// anyway?
let mut has_missing = false;
let mut elided_targets = vec![];
for edge in edges {
match edge.edge_type {
RevsetGraphEdgeType::Missing => {
has_missing = true;
}
RevsetGraphEdgeType::Direct => graphlog_edges.push(Edge::Present {
direct: true,
target: edge.target,
}),
RevsetGraphEdgeType::Indirect => graphlog_edges.push(Edge::Present {
direct: false,
target: edge.target,
}),
RevsetGraphEdgeType::Direct => {
graphlog_edges.push(Edge::Present {
direct: true,
target: (edge.target, false),
});
}
RevsetGraphEdgeType::Indirect => {
if use_elided_nodes {
elided_targets.push(edge.target.clone());
graphlog_edges.push(Edge::Present {
direct: true,
target: (edge.target, true),
});
} else {
graphlog_edges.push(Edge::Present {
direct: false,
target: (edge.target, false),
});
}
}
}
}
if has_missing {
graphlog_edges.push(Edge::Missing);
}
let mut buffer = vec![];
let commit = store.get_commit(&commit_id)?;
let key = (commit_id, false);
let commit = store.get_commit(&key.0)?;
with_content_format.write_graph_text(
ui.new_formatter(&mut buffer).as_mut(),
|formatter| template.format(&commit, formatter),
|| graph.width(&commit_id, &graphlog_edges),
|| graph.width(&key, &graphlog_edges),
)?;
if !buffer.ends_with(b"\n") {
buffer.push(b'\n');
Expand All @@ -166,18 +186,38 @@ pub(crate) fn cmd_log(
&diff_formats,
)?;
}
let node_symbol = if Some(&commit_id) == wc_commit_id {
let node_symbol = if Some(&key.0) == wc_commit_id {
"@"
} else {
&default_node_symbol
};

graph.add_node(
&commit_id,
&key,
&graphlog_edges,
node_symbol,
&String::from_utf8_lossy(&buffer),
)?;
for elided_target in elided_targets {
let elided_key = (elided_target, true);
let real_key = (elided_key.0.clone(), false);
let edges = [Edge::Present {
direct: true,
target: real_key,
}];
let mut buffer = vec![];
with_content_format.write_graph_text(
ui.new_formatter(&mut buffer).as_mut(),
|formatter| writeln!(formatter.labeled("elided"), "(elided revisions)"),
|| graph.width(&elided_key, &edges),
)?;
graph.add_node(
&elided_key,
&edges,
&elided_node_symbol,
&String::from_utf8_lossy(&buffer),
)?;
}
}
} else {
let iter: Box<dyn Iterator<Item = CommitId>> = if args.reversed {
Expand Down
10 changes: 7 additions & 3 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@
"style": {
"description": "Style of connectors/markings used to render the graph. See https://github.com/martinvonz/jj/blob/main/docs/config.md#graph-style",
"enum": [
"legacy",
"curved",
"square",
"ascii",
"ascii-large"
],
"default": "legacy"
"default": "curved"
}
}
},
Expand All @@ -120,6 +119,11 @@
"description": "Whether to wrap log template output",
"default": false
},
"log-synthetic-elided-nodes": {
"type": "boolean",
"description": "Whether to render elided parts of the graph as synthetic nodes.",
"default": false
},
"editor": {
"type": "string",
"description": "Editor to use for commands that involve editing text"
Expand Down Expand Up @@ -382,4 +386,4 @@
}
}
}
}
}
13 changes: 7 additions & 6 deletions cli/src/config/colors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"change_id" = "magenta"

# Unique prefixes and the rest for change & commit ids
"prefix" = { bold = true}
"prefix" = { bold = true }
"rest" = "bright black"
"divergent rest" = "red"
"divergent prefix" = {fg = "red", underline=true}
"divergent prefix" = { fg = "red", underline = true }
"hidden prefix" = "default"

"email" = "yellow"
Expand All @@ -28,13 +28,14 @@
"git_refs" = "green"
"git_head" = "green"
"divergent" = "red"
"divergent change_id"="red"
"divergent change_id" = "red"
"conflict" = "red"
"empty" = "green"
"placeholder" = "red"
"description placeholder" = "yellow"
"empty description placeholder" = "green"
"separator" = "bright black"
"elided" = "bright black"
"root" = "green"

"working_copy" = { bold = true }
Expand All @@ -45,13 +46,13 @@
"working_copy email" = "yellow"
"working_copy timestamp" = "bright cyan"
"working_copy working_copies" = "bright magenta"
"working_copy branch" = "bright magenta"
"working_copy branch" = "bright magenta"
"working_copy branches" = "bright magenta"
"working_copy local_branches" = "bright magenta"
"working_copy remote_branches" = "bright magenta"
"working_copy tags" = "bright magenta"
"working_copy git_refs" = "bright green"
"working_copy divergent" = "bright red"
"working_copy divergent" = "bright red"
"working_copy divergent change_id" = "bright red"
"working_copy conflict" = "bright red"
"working_copy empty" = "bright green"
Expand All @@ -71,5 +72,5 @@
"op_log time" = "cyan"
"op_log current_operation" = { bold = true }
"op_log current_operation id" = "bright blue"
"op_log current_operation user" = "yellow" # No bright yellow, see comment above
"op_log current_operation user" = "yellow" # No bright yellow, see comment above
"op_log current_operation time" = "bright cyan"
1 change: 1 addition & 0 deletions cli/src/config/misc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ tree-level-conflicts = true
paginate = "auto"
pager = { command = ["less", "-FRX"], env = { LESSCHARSET = "utf-8" } }
log-word-wrap = false
log-synthetic-elided-nodes = false

[snapshot]
max-new-file-size = "1MiB"
Loading