Skip to content

Commit

Permalink
log: encode elided node as None
Browse files Browse the repository at this point in the history
Since elided graph entry has no associated commits, it makes some sense to
represent as None?
  • Loading branch information
yuja committed Mar 24, 2024
1 parent 2fc7feb commit c311131
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 40 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Graph node symbols are now configurable via templates
* `templates.log_node`
* `templates.op_log_node`
* `templates.log_node_elided`


* `jj log` now includes synthetic nodes in the graph where some revisions were
elided.
Expand Down
17 changes: 5 additions & 12 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::cli_util::{format_template, CommandHelper, LogContentFormat, Revision
use crate::command_error::CommandError;
use crate::commit_templater::CommitTemplateLanguage;
use crate::diff_util::{self, DiffFormatArgs};
use crate::generic_templater::GenericTemplateLanguage;
use crate::graphlog::{get_graphlog, Edge};
use crate::templater::Template as _;
use crate::ui::Ui;
Expand Down Expand Up @@ -111,7 +110,7 @@ pub(crate) fn cmd_log(
let with_content_format = LogContentFormat::new(ui, command.settings())?;

let template;
let commit_node_template;
let node_template;
{
let language = workspace_command.commit_template_language()?;
let template_string = match &args.template {
Expand All @@ -123,19 +122,13 @@ pub(crate) fn cmd_log(
&template_string,
CommitTemplateLanguage::wrap_commit,
)?;
commit_node_template = workspace_command.parse_template(
node_template = workspace_command.parse_template(
&language,
&command.settings().commit_node_template(),
CommitTemplateLanguage::wrap_commit,
CommitTemplateLanguage::wrap_commit_opt,
)?;
}

let elided_node_template = workspace_command.parse_template(
&GenericTemplateLanguage::new(),
&command.settings().elided_node_template(),
GenericTemplateLanguage::wrap_self,
)?;

{
ui.request_pager();
let mut formatter = ui.stdout_formatter();
Expand Down Expand Up @@ -201,7 +194,7 @@ pub(crate) fn cmd_log(
)?;
}

let node_symbol = format_template(ui, &commit, &commit_node_template);
let node_symbol = format_template(ui, &Some(commit), &node_template);
graph.add_node(
&key,
&graphlog_edges,
Expand All @@ -218,7 +211,7 @@ pub(crate) fn cmd_log(
|formatter| writeln!(formatter.labeled("elided"), "(elided revisions)"),
|| graph.width(&elided_key, &edges),
)?;
let node_symbol = format_template(ui, &(), &elided_node_template);
let node_symbol = format_template(ui, &None, &node_template);
graph.add_node(
&elided_key,
&edges,
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/obslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn cmd_obslog(
let with_content_format = LogContentFormat::new(ui, command.settings())?;

let template;
let commit_node_template;
let node_template;
{
let language = workspace_command.commit_template_language()?;
let template_string = match &args.template {
Expand All @@ -85,10 +85,10 @@ pub(crate) fn cmd_obslog(
&template_string,
CommitTemplateLanguage::wrap_commit,
)?;
commit_node_template = workspace_command.parse_template(
node_template = workspace_command.parse_template(
&language,
&command.settings().commit_node_template(),
CommitTemplateLanguage::wrap_commit,
CommitTemplateLanguage::wrap_commit_opt,
)?;
}

Expand Down Expand Up @@ -131,7 +131,7 @@ pub(crate) fn cmd_obslog(
&diff_formats,
)?;
}
let node_symbol = format_template(ui, &commit, &commit_node_template);
let node_symbol = format_template(ui, &Some(commit.clone()), &node_template);
graph.add_node(
commit.id(),
&edges,
Expand Down
24 changes: 13 additions & 11 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,11 +1433,12 @@ fn test_log_with_custom_symbols() {
};

// Simple test with showing default and elided nodes.
test_env.add_config(concat!(
"ui.log-synthetic-elided-nodes = true\n",
"templates.log_node = 'if(current_working_copy, \"$\", if(root, \"\", \"\"))'\n",
"templates.log_node_elided = '\"🮀\"'",
));
test_env.add_config(
r###"
ui.log-synthetic-elided-nodes = true
templates.log_node = 'if(self, if(current_working_copy, "$", if(root, "┴", "┝")), "🮀")'
"###,
);
insta::assert_snapshot!(get_log("@ | @- | description(initial) | root()"), @r###"
$ merge
├─╮
Expand All @@ -1454,12 +1455,13 @@ fn test_log_with_custom_symbols() {
"###);

// Simple test with showing default and elided nodes, ascii style.
test_env.add_config(concat!(
"ui.log-synthetic-elided-nodes = true\n",
"ui.graph.style = 'ascii'\n",
"templates.log_node = 'if(current_working_copy, \"$\", if(root, \"^\", \"*\"))'\n",
"templates.log_node_elided = '\":\"'",
));
test_env.add_config(
r###"
ui.log-synthetic-elided-nodes = true
ui.graph.style = 'ascii'
templates.log_node = 'if(self, if(current_working_copy, "$", if(root, "^", "*")), ":")'
"###,
);
insta::assert_snapshot!(get_log("@ | @- | description(initial) | root()"), @r###"
$ merge
|\
Expand Down
10 changes: 5 additions & 5 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,23 +234,23 @@ ui.graph.style = "square"
The symbols used to represent commits or operations can be customized via
templates.

* `templates.log_node` for commits (with `Commit` keywords)
* `templates.log_node` for commits (with `Option<Commit>` keywords)
* `templates.op_log_node` for operations (with `Operation` keywords)
* `templates.log_node_elided` for elided nodes

For example:
```toml
[templates]
log_node = '''
if(self,
if(current_working_copy, "@",
if(root, "┴",
if(immutable, "●", "○")
)
)
),
"🮀",
)
'''
op_log_node = 'if(current_operation, "@", "○")'
log_node_elided = '"🮀"'

```

### Wrap log content
Expand Down
8 changes: 2 additions & 6 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ impl UserSettings {
pub fn commit_node_template(&self) -> String {
self.node_template_for_key(
"templates.log_node",
r#"if(current_working_copy, "@", "◉")"#,
r#"if(current_working_copy, "@", "o")"#,
r#"if(self, if(current_working_copy, "@", "◉"), "◌")"#,
r#"if(self, if(current_working_copy, "@", "o"), ".")"#,
)
}

Expand All @@ -258,10 +258,6 @@ impl UserSettings {
)
}

pub fn elided_node_template(&self) -> String {
self.node_template_for_key("templates.log_node_elided", r#""◌""#, r#"".""#)
}

pub fn max_new_file_size(&self) -> Result<u64, config::ConfigError> {
let cfg = self
.config
Expand Down

0 comments on commit c311131

Please sign in to comment.