mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-24 21:13:47 +00:00
cli: add "--limit N" option to log-like commands
Copied from Mercurial. This isn't a revset predicate since our revset is conceptually unordered.
This commit is contained in:
parent
abc7312dbc
commit
17b45d642f
6 changed files with 124 additions and 4 deletions
|
@ -50,6 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
external program. For configuration, see [the documentation](docs/config.md).
|
external program. For configuration, see [the documentation](docs/config.md).
|
||||||
[#1886](https://github.com/martinvonz/jj/issues/1886)
|
[#1886](https://github.com/martinvonz/jj/issues/1886)
|
||||||
|
|
||||||
|
* `jj log`/`obslog`/`op log` now supports `--limit N` option to show the first
|
||||||
|
`N` entries.
|
||||||
|
|
||||||
### Fixed bugs
|
### Fixed bugs
|
||||||
|
|
||||||
* SSH authentication could hang when ssh-agent couldn't be reached
|
* SSH authentication could hang when ssh-agent couldn't be reached
|
||||||
|
|
|
@ -368,6 +368,11 @@ struct LogArgs {
|
||||||
/// Show revisions in the opposite order (older revisions first)
|
/// Show revisions in the opposite order (older revisions first)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
reversed: bool,
|
reversed: bool,
|
||||||
|
/// Limit number of revisions to show
|
||||||
|
///
|
||||||
|
/// Applied after revisions are filtered and reordered.
|
||||||
|
#[arg(long, short)]
|
||||||
|
limit: Option<usize>,
|
||||||
/// Don't show the graph, show a flat list of revisions
|
/// Don't show the graph, show a flat list of revisions
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
no_graph: bool,
|
no_graph: bool,
|
||||||
|
@ -390,6 +395,9 @@ struct LogArgs {
|
||||||
struct ObslogArgs {
|
struct ObslogArgs {
|
||||||
#[arg(long, short, default_value = "@")]
|
#[arg(long, short, default_value = "@")]
|
||||||
revision: RevisionArg,
|
revision: RevisionArg,
|
||||||
|
/// Limit number of revisions to show
|
||||||
|
#[arg(long, short)]
|
||||||
|
limit: Option<usize>,
|
||||||
/// Don't show the graph, show a flat list of revisions
|
/// Don't show the graph, show a flat list of revisions
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
no_graph: bool,
|
no_graph: bool,
|
||||||
|
@ -1664,7 +1672,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
|
||||||
} else {
|
} else {
|
||||||
Box::new(forward_iter)
|
Box::new(forward_iter)
|
||||||
};
|
};
|
||||||
for (commit_id, edges) in iter {
|
for (commit_id, edges) in iter.take(args.limit.unwrap_or(usize::MAX)) {
|
||||||
let mut graphlog_edges = vec![];
|
let mut graphlog_edges = vec![];
|
||||||
// TODO: Should we update RevsetGraphIterator to yield this flag instead of all
|
// 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
|
// the missing edges since we don't care about where they point here
|
||||||
|
@ -1727,7 +1735,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
|
||||||
} else {
|
} else {
|
||||||
Box::new(revset.iter())
|
Box::new(revset.iter())
|
||||||
};
|
};
|
||||||
for commit_or_error in iter.commits(store) {
|
for commit_or_error in iter.commits(store).take(args.limit.unwrap_or(usize::MAX)) {
|
||||||
let commit = commit_or_error?;
|
let commit = commit_or_error?;
|
||||||
with_content_format
|
with_content_format
|
||||||
.write(formatter, |formatter| template.format(&commit, formatter))?;
|
.write(formatter, |formatter| template.format(&commit, formatter))?;
|
||||||
|
@ -1791,11 +1799,14 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result
|
||||||
let formatter = formatter.as_mut();
|
let formatter = formatter.as_mut();
|
||||||
formatter.push_label("log")?;
|
formatter.push_label("log")?;
|
||||||
|
|
||||||
let commits = topo_order_reverse(
|
let mut commits = topo_order_reverse(
|
||||||
vec![start_commit],
|
vec![start_commit],
|
||||||
|commit: &Commit| commit.id().clone(),
|
|commit: &Commit| commit.id().clone(),
|
||||||
|commit: &Commit| commit.predecessors(),
|
|commit: &Commit| commit.predecessors(),
|
||||||
);
|
);
|
||||||
|
if let Some(n) = args.limit {
|
||||||
|
commits.truncate(n);
|
||||||
|
}
|
||||||
if !args.no_graph {
|
if !args.no_graph {
|
||||||
let mut graph = get_graphlog(command.settings(), formatter.raw());
|
let mut graph = get_graphlog(command.settings(), formatter.raw());
|
||||||
let default_node_symbol = graph.default_node_symbol().to_owned();
|
let default_node_symbol = graph.default_node_symbol().to_owned();
|
||||||
|
|
|
@ -26,6 +26,9 @@ pub enum OperationCommands {
|
||||||
/// Show the operation log
|
/// Show the operation log
|
||||||
#[derive(clap::Args, Clone, Debug)]
|
#[derive(clap::Args, Clone, Debug)]
|
||||||
pub struct OperationLogArgs {
|
pub struct OperationLogArgs {
|
||||||
|
/// Limit number of operations to show
|
||||||
|
#[arg(long, short)]
|
||||||
|
limit: Option<usize>,
|
||||||
/// Render each operation using the given template
|
/// Render each operation using the given template
|
||||||
///
|
///
|
||||||
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
|
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
|
||||||
|
@ -119,7 +122,7 @@ fn cmd_op_log(
|
||||||
let formatter = formatter.as_mut();
|
let formatter = formatter.as_mut();
|
||||||
let mut graph = get_graphlog(command.settings(), formatter.raw());
|
let mut graph = get_graphlog(command.settings(), formatter.raw());
|
||||||
let default_node_symbol = graph.default_node_symbol().to_owned();
|
let default_node_symbol = graph.default_node_symbol().to_owned();
|
||||||
for op in operation::walk_ancestors(&head_op) {
|
for op in operation::walk_ancestors(&head_op).take(args.limit.unwrap_or(usize::MAX)) {
|
||||||
let mut edges = vec![];
|
let mut edges = vec![];
|
||||||
for parent in op.parents() {
|
for parent in op.parents() {
|
||||||
edges.push(Edge::direct(parent.id().clone()));
|
edges.push(Edge::direct(parent.id().clone()));
|
||||||
|
|
|
@ -796,6 +796,88 @@ fn test_log_filtered_by_path() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_log_limit() {
|
||||||
|
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");
|
||||||
|
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "a"]);
|
||||||
|
std::fs::write(repo_path.join("a"), "").unwrap();
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "b"]);
|
||||||
|
std::fs::write(repo_path.join("b"), "").unwrap();
|
||||||
|
test_env.jj_cmd_success(&repo_path, &["new", "-m", "c", "description(a)"]);
|
||||||
|
std::fs::write(repo_path.join("c"), "").unwrap();
|
||||||
|
test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&["new", "-m", "d", "description(c)", "description(b)"],
|
||||||
|
);
|
||||||
|
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--limit=3"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ d
|
||||||
|
├─╮
|
||||||
|
│ ◉ b
|
||||||
|
◉ │ c
|
||||||
|
├─╯
|
||||||
|
"###);
|
||||||
|
|
||||||
|
// Applied on sorted DAG
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "description", "--limit=2"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ d
|
||||||
|
├─╮
|
||||||
|
│ ◉ b
|
||||||
|
"###);
|
||||||
|
|
||||||
|
let stdout = test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&["log", "-T", "description", "--limit=2", "--no-graph"],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
d
|
||||||
|
c
|
||||||
|
"###);
|
||||||
|
|
||||||
|
// Applied on reversed DAG
|
||||||
|
let stdout = test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&["log", "-T", "description", "--limit=3", "--reversed"],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
◉
|
||||||
|
◉ a
|
||||||
|
├─╮
|
||||||
|
│ ◉ c
|
||||||
|
"###);
|
||||||
|
let stdout = test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&[
|
||||||
|
"log",
|
||||||
|
"-T",
|
||||||
|
"description",
|
||||||
|
"--limit=3",
|
||||||
|
"--reversed",
|
||||||
|
"--no-graph",
|
||||||
|
],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
a
|
||||||
|
b
|
||||||
|
"###);
|
||||||
|
|
||||||
|
// Applied on filtered commits
|
||||||
|
let stdout = test_env.jj_cmd_success(
|
||||||
|
&repo_path,
|
||||||
|
&["log", "-T", "description", "--limit=1", "b", "c"],
|
||||||
|
);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
◉ c
|
||||||
|
│
|
||||||
|
~
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_log_warn_path_might_be_revset() {
|
fn test_log_warn_path_might_be_revset() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
|
@ -80,6 +80,15 @@ fn test_obslog_with_or_without_diff() {
|
||||||
(empty) my description
|
(empty) my description
|
||||||
"###);
|
"###);
|
||||||
|
|
||||||
|
// Test `--limit`
|
||||||
|
let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--limit=2"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ rlvkpnrz test.user@example.com 2001-02-03 04:05:10.000 +07:00 66b42ad3
|
||||||
|
│ my description
|
||||||
|
◉ rlvkpnrz hidden test.user@example.com 2001-02-03 04:05:09.000 +07:00 af536e5a conflict
|
||||||
|
│ my description
|
||||||
|
"###);
|
||||||
|
|
||||||
// Test `--no-graph`
|
// Test `--no-graph`
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--no-graph"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["obslog", "--no-graph"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
|
|
@ -118,6 +118,18 @@ fn test_op_log() {
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_op_log_limit() {
|
||||||
|
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", "-Tdescription", "--limit=1"]);
|
||||||
|
insta::assert_snapshot!(stdout, @r###"
|
||||||
|
@ add workspace 'default'
|
||||||
|
"###);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_op_log_template() {
|
fn test_op_log_template() {
|
||||||
let test_env = TestEnvironment::default();
|
let test_env = TestEnvironment::default();
|
||||||
|
|
Loading…
Reference in a new issue