From 72438fc9d2e7daddba243bf1337bc32893db5077 Mon Sep 17 00:00:00 2001 From: Manuel Caldeira <5896952+KiitoX@users.noreply.github.com> Date: Sat, 15 Jun 2024 01:24:09 +0200 Subject: [PATCH] cli: deprecate `-l` short alias for `--limit` in favour of `-n` This better matches `git log` and affects `jj log`, `jj op log` and `jj obslog` --- CHANGELOG.md | 2 ++ cli/src/commands/log.rs | 22 +++++++++++++++++++--- cli/src/commands/obslog.rs | 18 ++++++++++++++++-- cli/src/commands/operation.rs | 19 +++++++++++++++++-- cli/tests/cli-reference@.md.snap | 9 ++++++--- cli/tests/test_operations.rs | 6 +++--- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 740194aad..7e0c5574d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecations +* Replacing `-l` shorthand for `--limit` with `-n` in `jj log`, `jj op log` and `jj obslog`. + ### New features * Show paths to config files when configuration errors occur diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index d1afd286d..46fbcb164 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -49,8 +49,16 @@ pub(crate) struct LogArgs { /// Limit number of revisions to show /// /// Applied after revisions are filtered and reordered. - #[arg(long, short)] + #[arg(long, short = 'n')] limit: Option, + // TODO: Delete `-l` alias in jj 0.25+ + #[arg( + short = 'l', + hide = true, + conflicts_with = "limit", + value_name = "LIMIT" + )] + deprecated_limit: Option, /// Don't show the graph, show a flat list of revisions #[arg(long)] no_graph: bool, @@ -137,6 +145,14 @@ pub(crate) fn cmd_log( let mut formatter = ui.stdout_formatter(); let formatter = formatter.as_mut(); + if args.deprecated_limit.is_some() { + writeln!( + ui.warning_default(), + "The -l shorthand is deprecated, use -n instead." + )?; + } + let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX); + if !args.no_graph { let mut graph = get_graphlog(command.settings(), formatter.raw()); let forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph()); @@ -145,7 +161,7 @@ pub(crate) fn cmd_log( } else { Box::new(forward_iter) }; - for (commit_id, edges) in iter.take(args.limit.unwrap_or(usize::MAX)) { + for (commit_id, edges) in iter.take(limit) { // The graph is keyed by (CommitId, is_synthetic) let mut graphlog_edges = vec![]; // TODO: Should we update revset.iter_graph() to yield this flag instead of all @@ -222,7 +238,7 @@ pub(crate) fn cmd_log( } else { Box::new(revset.iter()) }; - for commit_or_error in iter.commits(store).take(args.limit.unwrap_or(usize::MAX)) { + for commit_or_error in iter.commits(store).take(limit) { let commit = commit_or_error?; with_content_format .write(formatter, |formatter| template.format(&commit, formatter))?; diff --git a/cli/src/commands/obslog.rs b/cli/src/commands/obslog.rs index d3ce56cd8..7a34c735f 100644 --- a/cli/src/commands/obslog.rs +++ b/cli/src/commands/obslog.rs @@ -39,8 +39,16 @@ pub(crate) struct ObslogArgs { #[arg(long, short, default_value = "@")] revision: RevisionArg, /// Limit number of revisions to show - #[arg(long, short)] + #[arg(long, short = 'n')] limit: Option, + // TODO: Delete `-l` alias in jj 0.25+ + #[arg( + short = 'l', + hide = true, + conflicts_with = "limit", + value_name = "LIMIT" + )] + deprecated_limit: Option, /// Don't show the graph, show a flat list of revisions #[arg(long)] no_graph: bool, @@ -107,7 +115,13 @@ pub(crate) fn cmd_obslog( |commit: &Commit| commit.id().clone(), |commit: &Commit| commit.predecessors().collect_vec(), )?; - if let Some(n) = args.limit { + if args.deprecated_limit.is_some() { + writeln!( + ui.warning_default(), + "The -l shorthand is deprecated, use -n instead." + )?; + } + if let Some(n) = args.limit.or(args.deprecated_limit) { commits.truncate(n); } if !args.no_graph { diff --git a/cli/src/commands/operation.rs b/cli/src/commands/operation.rs index 782cb8533..86cd44dc9 100644 --- a/cli/src/commands/operation.rs +++ b/cli/src/commands/operation.rs @@ -45,8 +45,16 @@ pub enum OperationCommand { #[derive(clap::Args, Clone, Debug)] pub struct OperationLogArgs { /// Limit number of operations to show - #[arg(long, short)] + #[arg(long, short = 'n')] limit: Option, + // TODO: Delete `-l` alias in jj 0.25+ + #[arg( + short = 'l', + hide = true, + conflicts_with = "limit", + value_name = "LIMIT" + )] + deprecated_limit: Option, /// Don't show the graph, show a flat list of operations #[arg(long)] no_graph: bool, @@ -191,7 +199,14 @@ fn cmd_op_log( ui.request_pager(); let mut formatter = ui.stdout_formatter(); let formatter = formatter.as_mut(); - let iter = op_walk::walk_ancestors(&head_ops).take(args.limit.unwrap_or(usize::MAX)); + if args.deprecated_limit.is_some() { + writeln!( + ui.warning_default(), + "The -l shorthand is deprecated, use -n instead." + )?; + } + let limit = args.limit.or(args.deprecated_limit).unwrap_or(usize::MAX); + let iter = op_walk::walk_ancestors(&head_ops).take(limit); if !args.no_graph { let mut graph = get_graphlog(command.settings(), formatter.raw()); for op in iter { diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 49ab95d81..2ea06e945 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1097,7 +1097,8 @@ Spans of revisions that are not included in the graph per `--revisions` are rend Possible values: `true`, `false` -* `-l`, `--limit ` — Limit number of revisions to show +* `-n`, `--limit ` — Limit number of revisions to show +* `-l ` * `--no-graph` — Don't show the graph, show a flat list of revisions Possible values: `true`, `false` @@ -1236,7 +1237,8 @@ Name is derived from Merciual's obsolescence markers. * `-r`, `--revision ` Default value: `@` -* `-l`, `--limit ` — Limit number of revisions to show +* `-n`, `--limit ` — Limit number of revisions to show +* `-l ` * `--no-graph` — Don't show the graph, show a flat list of revisions Possible values: `true`, `false` @@ -1314,7 +1316,8 @@ Show the operation log ###### **Options:** -* `-l`, `--limit ` — Limit number of operations to show +* `-n`, `--limit ` — Limit number of operations to show +* `-l ` * `--no-graph` — Don't show the graph, show a flat list of operations Possible values: `true`, `false` diff --git a/cli/tests/test_operations.rs b/cli/tests/test_operations.rs index 44b22d071..2d1de0e74 100644 --- a/cli/tests/test_operations.rs +++ b/cli/tests/test_operations.rs @@ -449,7 +449,7 @@ fn test_op_abandon_ancestors() { insta::assert_snapshot!(stderr, @r###" Nothing changed. "###); - insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "log", "-l1"]), @r###" + insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["op", "log", "-n1"]), @r###" @ 445e93662d71 test-username@host.example.com 2001-02-03 04:05:21.000 +07:00 - 2001-02-03 04:05:21.000 +07:00 │ undo operation 70112b4447b65fa811038b2b119fe22e959e3b3194b461a32475f6528c2b684ac6baebc86cce7ad7e0bb92c033852850e561506508ca43e823626f107e81ed76 │ args: jj undo @@ -480,7 +480,7 @@ fn test_op_abandon_without_updating_working_copy() { Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["op", "log", "-l1", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["op", "log", "-n1", "--ignore-working-copy"]), @r###" @ ae6364994418 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00 │ commit 268f5f16139313ff25bef31280b2ec2e675200f3 │ args: jj commit -m 'commit 3' @@ -500,7 +500,7 @@ fn test_op_abandon_without_updating_working_copy() { Current tree: Merge(Resolved(TreeId("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))) "###); insta::assert_snapshot!( - test_env.jj_cmd_success(&repo_path, &["op", "log", "-l1", "--ignore-working-copy"]), @r###" + test_env.jj_cmd_success(&repo_path, &["op", "log", "-n1", "--ignore-working-copy"]), @r###" @ 51192a90e899 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00 │ commit 268f5f16139313ff25bef31280b2ec2e675200f3 │ args: jj commit -m 'commit 3'