Skip to content

Commit

Permalink
cli: only use default log revset when neither path nor revset is prov…
Browse files Browse the repository at this point in the history
…ided
  • Loading branch information
noahmayr committed Apr 2, 2024
1 parent 320f50e commit 5da3827
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The `jj sparse` subcommands now parse and print patterns as workspace-relative
paths.

* The `jj log` command no longer uses the default revset when a path is specified.

### New features

* Config now supports rgb hex colors (in the form `#rrggbb`) wherever existing color names are supported.
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl WorkspaceCommandHelper {
self.attach_revset_evaluator(expression)
}

fn attach_revset_evaluator(
pub fn attach_revset_evaluator(
&self,
expression: Rc<RevsetExpression>,
) -> Result<RevsetExpressionEvaluator<'_>, CommandError> {
Expand Down
14 changes: 10 additions & 4 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ use crate::ui::Ui;
/// rendered as a synthetic node labeled "(elided revisions)".
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct LogArgs {
/// Which revisions to show. Defaults to the `revsets.log` setting, or
/// `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set.
/// Which revisions to show. If no paths nor revisions are specified, this
/// defaults to the `revsets.log` setting, or `@ |
/// ancestors(immutable_heads().., 2) | trunk()` if it is not set.
#[arg(long, short)]
revisions: Vec<RevisionArg>,
/// Show revisions modifying the given paths
Expand Down Expand Up @@ -77,10 +78,14 @@ pub(crate) fn cmd_log(
let workspace_command = command.workspace_helper(ui)?;

let revset_expression = {
let mut expression = if args.revisions.is_empty() {
// only use default revset if neither revset nor path are specified
let mut expression = if args.revisions.is_empty() && args.paths.is_empty() {
workspace_command.parse_revset(&command.settings().default_revset())?
} else {
} else if !args.revisions.is_empty() {
workspace_command.parse_union_revsets(&args.revisions)?
} else {
// a path was specified so we use all() and add path filter later
workspace_command.attach_revset_evaluator(RevsetExpression::all())?
};
if !args.paths.is_empty() {
let repo_paths: Vec<_> = args
Expand All @@ -94,6 +99,7 @@ pub(crate) fn cmd_log(
}
expression
};

let repo = workspace_command.repo();
let matcher = workspace_command.matcher_from_values(&args.paths)?;
let revset = revset_expression.evaluate()?;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ Spans of revisions that are not included in the graph per `--revisions` are rend
###### **Options:**
* `-r`, `--revisions <REVISIONS>` — Which revisions to show. Defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set
* `-r`, `--revisions <REVISIONS>` — Which revisions to show. If no paths nor revisions are specified, this defaults to the `revsets.log` setting, or `@ | ancestors(immutable_heads().., 2) | trunk()` if it is not set
* `--reversed` — Show revisions in the opposite order (older revisions first)
Possible values: `true`, `false`
Expand Down
9 changes: 9 additions & 0 deletions cli/tests/test_log_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,15 @@ fn test_default_revset() {
.lines()
.count()
);

// The default revset is not used if a path is specified
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "file1", "-T", "description"]),
@r###"
@ add a file
~
"###);
}

#[test]
Expand Down
41 changes: 20 additions & 21 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

These are the config settings available to jj/Jujutsu.


## Config files and TOML

`jj` loads several types of config settings:
Expand All @@ -11,11 +10,11 @@ These are the config settings available to jj/Jujutsu.
`cli/src/config/` directory in `jj`'s source repo.

- The user settings. These can be edited with `jj config edit --user`. User
settings are located in [the user config file], which can be found with `jj
settings are located in [the user config file], which can be found with `jj
config path --user`.

- The repo settings. These can be edited with `jj config edit --repo` and are
located in `.jj/repo/config.toml`.
located in `.jj/repo/config.toml`.

- Settings [specified in the command-line](#specifying-config-on-the-command-line).

Expand All @@ -35,6 +34,7 @@ The first thing to remember is that the value of a setting (the part to the
right of the `=` sign) should be surrounded in quotes if it's a string.

### Dotted style and headings

In TOML, anything under a heading can be dotted instead. For example,
`user.name = "YOUR NAME"` is equivalent to:

Expand Down Expand Up @@ -66,7 +66,6 @@ then use whichever suits you in your config. If you mix dotted keys and headings
That's probably enough TOML to keep you out of trouble but the [syntax guide] is
very short if you ever need to check.


## User settings

```toml
Expand Down Expand Up @@ -99,15 +98,15 @@ colors.commit_id = "green"

The following colors are available:

* black
* red
* green
* yellow
* blue
* magenta
* cyan
* white
* default
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- default

All of them but "default" come in a bright version too, e.g. "bright red". The
"default" color can be used to override a color defined by a parent style
Expand Down Expand Up @@ -215,7 +214,7 @@ immutable even if the set is empty.

### Default revisions to log

You can configure the revisions `jj log` without `-r` should show.
You can configure the revisions `jj log` would show when neither `-r` nor any paths are specified.

```toml
# Show commits that are not in `main@origin`
Expand All @@ -234,10 +233,11 @@ ui.graph.style = "square"
The symbols used to represent commits or operations can be customized via
templates.

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

For example:

```toml
[templates]
log_node = '''
Expand Down Expand Up @@ -416,7 +416,7 @@ Obviously, you would only set one line, don't copy them all in!

## Editing diffs

The `ui.diff-editor` setting affects the tool used for editing diffs (e.g. `jj
The `ui.diff-editor` setting affects the tool used for editing diffs (e.g. `jj
split`, `jj squash -i`). The default is the special value `:builtin`, which
launches a built-in TUI tool (known as [scm-diff-editor]) to edit the diff in
your terminal.
Expand Down Expand Up @@ -476,7 +476,6 @@ experience, you can follow [instructions from the Wiki] to configure the
[DirDiff Vim plugin] and/or the [vimtabdiff Python script].

[instructions from the Wiki]: https://github.com/martinvonz/jj/wiki/Vim#using-vim-as-a-diff-tool

[DirDiff Vim plugin]: https://github.com/will133/vim-dirdiff
[vimtabdiff Python script]: https://github.com/balki/vimtabdiff

Expand Down Expand Up @@ -552,7 +551,7 @@ conflict is considered fully resolved when there are no conflict markers left.

## Commit Signing

`jj` can be configured to sign and verify the commits it creates using either
`jj` can be configured to sign and verify the commits it creates using either
GnuPG or SSH signing keys.

To do this you need to configure a signing backend.
Expand Down Expand Up @@ -603,8 +602,8 @@ signing.backends.ssh.program = "/path/to/ssh-keygen"
When verifying commit signatures the ssh backend needs to be provided with an allowed-signers
file containing the public keys of authors whose signatures you want to be able to verify.

You can find the format for this file in the
[ssh-keygen man page](https://man.openbsd.org/ssh-keygen#ALLOWED_SIGNERS). This can be provided
You can find the format for this file in the
[ssh-keygen man page](https://man.openbsd.org/ssh-keygen#ALLOWED_SIGNERS). This can be provided
as follows:

```toml
Expand Down

0 comments on commit 5da3827

Please sign in to comment.