Skip to content

Commit

Permalink
Summarize experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
algmyr committed Jul 14, 2024
1 parent 4b0cd02 commit 45a61e4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
23 changes: 20 additions & 3 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ pub(crate) struct LogArgs {
/// Show patch
#[arg(long, short = 'p')]
patch: bool,
/// Restrict diffs to the given revsets.
///
/// Defaults to all().
#[arg(long)]
diff_revisions: Vec<RevisionArg>,
#[command(flatten)]
diff_format: DiffFormatArgs,
}
Expand Down Expand Up @@ -102,6 +107,14 @@ pub(crate) fn cmd_log(
}
expression
};
let diff_revset_contains = {
let diff_revset_expression = if args.diff_revisions.is_empty() {
workspace_command.attach_revset_evaluator(RevsetExpression::all())?
} else {
workspace_command.parse_union_revsets(&args.diff_revisions)?
};
diff_revset_expression.evaluate()?.containing_fn()
};

let repo = workspace_command.repo();
let matcher = fileset_expression.to_matcher();
Expand Down Expand Up @@ -202,8 +215,10 @@ pub(crate) fn cmd_log(
buffer.push(b'\n');
}
if let Some(renderer) = &diff_renderer {
let mut formatter = ui.new_formatter(&mut buffer);
renderer.show_patch(ui, formatter.as_mut(), &commit, matcher.as_ref())?;
if diff_revset_contains(commit.id()) {
let mut formatter = ui.new_formatter(&mut buffer);
renderer.show_patch(ui, formatter.as_mut(), &commit, matcher.as_ref())?;
}
}

let node_symbol = format_template(ui, &Some(commit), &node_template);
Expand Down Expand Up @@ -243,7 +258,9 @@ pub(crate) fn cmd_log(
with_content_format
.write(formatter, |formatter| template.format(&commit, formatter))?;
if let Some(renderer) = &diff_renderer {
renderer.show_patch(ui, formatter, &commit, matcher.as_ref())?;
if diff_revset_contains(commit.id()) {
renderer.show_patch(ui, formatter, &commit, matcher.as_ref())?;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,9 @@ Spans of revisions that are not included in the graph per `--revisions` are rend
For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
* `-p`, `--patch` — Show patch
* `--diff-revisions <DIFF_REVISIONS>` — Restrict diffs to the given revsets.
Defaults to all().
* `-s`, `--summary` — For each path, show only whether it was modified, added, or deleted
* `--stat` — Show a histogram of the changes
* `--types` — For each path, show only its type before and after
Expand Down
63 changes: 63 additions & 0 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,69 @@ fn test_log_with_or_without_diff() {
"###);
}

#[test]
fn test_diff_revisions_restriction() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let repo_path = test_env.env_root().join("repo");

std::fs::write(repo_path.join("file1"), "foo\n").unwrap();
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "add a file"]);
test_env.jj_cmd_ok(&repo_path, &["new", "-m", "a new commit"]);
std::fs::write(repo_path.join("file1"), "foo\nbar\n").unwrap();

// diff-revisions doesn't affect output when summary or patch is not requested.
let stdout = test_env.jj_cmd_success(
&repo_path,
&["log", "-T", "description", "--diff-revisions=@"],
);
insta::assert_snapshot!(stdout, @r###"
@ a new commit
◉ add a file
"###);

// `-p` for default diff output, restrict to @
let stdout = test_env.jj_cmd_success(
&repo_path,
&["log", "-T", "description", "-p", "--diff-revisions=@"],
);
insta::assert_snapshot!(stdout, @r###"
@ a new commit
│ Modified regular file file1:
│ 1 1: foo, "--diff-revisions=@"
│ 2: bar
◉ add a file
"###);

// `-p` for default diff output, `-s` for summary, restrict to @
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p", "-s", "--diff-revisions=@"]);
insta::assert_snapshot!(stdout, @r###"
@ a new commit
│ M file1
│ Modified regular file file1:
│ 1 1: foo
│ 2: bar
◉ add a file
"###);

// `-s` for summary, restrict to @-
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "-p", "-s", "--diff-revisions=@-"]);
insta::assert_snapshot!(stdout, @r###"
@ a new commit
◉ add a file
│ A file1
│ Added regular file file1:
│ 1: foo
"###);
}

#[test]
fn test_log_null_terminate_multiline_descriptions() {
let test_env = TestEnvironment::default();
Expand Down

0 comments on commit 45a61e4

Please sign in to comment.