diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d71a42b34..6df8a0b2f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -708,7 +708,7 @@ Thanks to the people who made this release happen! * `jj backout --revision` has been renamed to `jj backout --revisions`. The short alias `-r` is still supported. -* [The default `immutable_heads()` set](docs/config.md#set-of-immutable-commits) +* [The default `immutable_heads()` set](docs/revset-config.md#immutable_heads) now includes `untracked_remote_branches()` with the assumption that untracked branches aren't managed by you. Therefore, untracked branches are no longer displayed in `jj log` by default. diff --git a/cli/src/commands/log.rs b/cli/src/commands/log.rs index eea384519d..2f9f8c2f25 100644 --- a/cli/src/commands/log.rs +++ b/cli/src/commands/log.rs @@ -54,9 +54,9 @@ use crate::ui::Ui; /// rendered as a synthetic node labeled "(elided revisions)". /// /// The working-copy commit is indicated by a `@` symbol in the graph. Immutable -/// revisions (https://jj-vcs.github.io/jj/latest/config/#set-of-immutable-commits) +/// revisions (https://jj-vcs.github.io/jj/latest/revset-aliases/#immutable_heads) /// have a `◆` symbol. Other commits have a `○` symbol. To customize these -/// symbols, see https://jj-vcs.github.io/jj/latest/config/#node-style. +/// symbols, see https://jj-vcs.github.io/jj/latest/template-config/#log-nodes. #[derive(clap::Args, Clone, Debug)] pub(crate) struct LogArgs { /// Which revisions to show diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 106cfe78ea..2d3c20b293 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1361,7 +1361,7 @@ Renders a graphical view of the project's history, ordered with children before Spans of revisions that are not included in the graph per `--revisions` are rendered as a synthetic node labeled "(elided revisions)". -The working-copy commit is indicated by a `@` symbol in the graph. Immutable revisions (https://jj-vcs.github.io/jj/latest/config/#set-of-immutable-commits) have a `◆` symbol. Other commits have a `○` symbol. To customize these symbols, see https://jj-vcs.github.io/jj/latest/config/#node-style. +The working-copy commit is indicated by a `@` symbol in the graph. Immutable revisions (https://jj-vcs.github.io/jj/latest/revset-config/#immutable_heads) have a `◆` symbol. Other commits have a `○` symbol. To customize these symbols, see https://jj-vcs.github.io/jj/latest/config/#node-style. **Usage:** `jj log [OPTIONS] [FILESETS]...` diff --git a/docs/config.md b/docs/config.md index c139bd25f0..257bfe5a25 100644 --- a/docs/config.md +++ b/docs/config.md @@ -169,32 +169,18 @@ default-command = ["log", "--reversed"] ### Default description -The editor content of a commit description can be populated by the -`draft_commit_description` template. - -```toml -[templates] -draft_commit_description = ''' -concat( - description, - surround( - "\nJJ: This commit contains the following changes:\n", "", - indent("JJ: ", diff.stat(72)), - ), - "\nJJ: ignore-rest\n", - diff.git(), -) -''' -``` - -The value of the `ui.default-description` setting can also be used in order to -fill in things like BUG=, TESTED= etc. +The value of the `ui.default-description` setting can be used in order to fill +in things like BUG=, TESTED= etc. ```toml [ui] default-description = "\n\nTESTED=TODO" ``` +The contents of the editor when editing descriptions (including comments) can be +changed with the setting +[`template-aliases.draft_commit_description`](template-config.md#description-editor-contents). + ### Diff colors and styles In color-words and git diffs, word-level hunks are rendered with underline. You @@ -320,69 +306,23 @@ page](conflicts.md#conflict-markers). ### Set of immutable commits -You can configure the set of immutable commits via -`revset-aliases."immutable_heads()"`. The default set of immutable heads is -`builtin_immutable_heads()`, which in turn is defined as -`present(trunk()) | tags() | untracked_remote_bookmarks()`. For example, to -also consider the `release@origin` bookmark immutable: - -```toml -[revset-aliases] -"immutable_heads()" = "builtin_immutable_heads() | release@origin" -``` - -To prevent rewriting commits authored by other users: - -```toml -# The `trunk().. &` bit is an optimization to scan for non-`mine()` commits -# only among commits that are not in `trunk()`. -[revset-aliases] -"immutable_heads()" = "builtin_immutable_heads() | (trunk().. & ~mine())" -``` - -Ancestors of the configured set are also immutable. The root commit is always -immutable even if the set is empty. +You can change which revisions are immutable by setting the +[`immutable_heads()` revset alias](revset-config.md#immutable_heads). ## Log ### Default revisions -You can configure the revisions `jj log` would show when neither `-r` nor any paths are specified. - -```toml -[revsets] -# Show commits that are not in `main@origin` -log = "main@origin.." -``` - -The default value for `revsets.log` is -`'present(@) | ancestors(immutable_heads().., 2) | present(trunk())'`. +You can change which revisions are logged by default with the [`revsets.log` +setting](revset-config.md#revsets-log). ### Default Template -You can configure the template used when no `-T` is specified. - -- `templates.log` for `jj log` -- `templates.op_log` for `jj op log` -- `templates.show` for `jj show` +See the following documentation to change the default templates: -```toml -[templates] -# Use builtin log template -log = "builtin_log_compact" -# Use builtin op log template -op_log = "builtin_op_log_compact" -# Use builtin show template -show = "builtin_log_detailed" -``` - -If you want to see the full description when you do `jj log` you can add this to -your config: - -```toml -[templates] -log = "builtin_log_compact_full_description" -``` +* [`templates.log`](template-config.md#log) +* [`templates.op_log`](template-config.md#operation-log) +* [`templates.show`](template-config.md#show) ### Graph style @@ -394,25 +334,8 @@ graph.style = "square" #### Node style -The symbols used to represent commits or operations can be customized via -templates. - -- `templates.log_node` for commits (with `Option` keywords) -- `templates.op_log_node` for operations (with `Operation` keywords) - -For example: -```toml -[templates] -log_node = ''' -coalesce( - if(!self, "🮀"), - if(current_working_copy, "@"), - if(root, "┴"), - if(immutable, "●", "○"), -) -''' -op_log_node = 'if(current_operation, "@", "○")' -``` +See [`templates.log_node`](template-config.md#log-nodes) and +[`templates.op_log_node`](template-config.md#operation-log-nodes). ### Wrap log content @@ -426,84 +349,28 @@ log-word-wrap = true ### Display of commit and change ids -Can be customized by the `format_short_id()` template alias. +To change the presentation of commit and change ids, adjust the +[`format_short_id()` template alias](template-config.md#format_short_id). The +linked doc also explains how to change them separately. -```toml -[template-aliases] -# Highlight unique prefix and show at least 12 characters (default) -'format_short_id(id)' = 'id.shortest(12)' -# Just the shortest possible unique prefix -'format_short_id(id)' = 'id.shortest()' -# Show unique prefix and the rest surrounded by brackets -'format_short_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"' -# Always show 12 characters -'format_short_id(id)' = 'id.short(12)' -``` - -To customize these separately, use the `format_short_commit_id()` and -`format_short_change_id()` aliases: - -```toml -[template-aliases] -# Uppercase change ids. `jj` treats change and commit ids as case-insensitive. -'format_short_change_id(id)' = 'format_short_id(id).upper()' -``` - -To get shorter prefixes for certain revisions, set `revsets.short-prefixes`: - -```toml -[revsets] -# Prioritize the current bookmark -short-prefixes = "(main..@)::" -``` +To change which revisions get the shortest prefixes, see [commit and change Id +short prefixes](revset-config.md#revsets-short-prefixes). ### Relative timestamps -Can be customized by the `format_timestamp()` template alias. - -```toml -[template-aliases] -# Full timestamp in ISO 8601 format -'format_timestamp(timestamp)' = 'timestamp' -# Relative timestamp rendered as "x days/hours/seconds ago" -'format_timestamp(timestamp)' = 'timestamp.ago()' -``` - -`jj op log` defaults to relative timestamps. To use absolute timestamps, you -will need to modify the `format_time_range()` template alias. - -```toml -[template-aliases] -'format_time_range(time_range)' = 'time_range.start() ++ " - " ++ time_range.end()' -``` +You can use relative timestamps by adjusting the [`format_timestamp()` template +alias](template-config.md#format_timestamp). ### Author format -Can be customized by the `format_short_signature()` template alias. - -```toml -[template-aliases] -# Full email address (default) -'format_short_signature(signature)' = 'signature.email()' -# Both name and email address -'format_short_signature(signature)' = 'signature' -# Username part of the email address -'format_short_signature(signature)' = 'signature.username()' -``` +The [`format_short_signature()` template +alias](template-config.md#format_short_signature) controls how commit authors +are displayed. ### Commit timestamp -Commits have both an "author timestamp" and "committer timestamp". By default, -jj displays the committer timestamp, but can be changed to show the author -timestamp instead. - -The function must return a timestamp because the return value will likely be -formatted with `format_timestamp()`. - -```toml -[template-aliases] -'commit_timestamp(commit)' = 'commit.author().timestamp()' -``` +The [`commit_timestamp()` template alias](template-config.md#commit_timestamp) +controls whether the author or committer timestamp is displayed in the log. ### Signature format diff --git a/docs/revset-config.md b/docs/revset-config.md new file mode 100644 index 0000000000..93ea559624 --- /dev/null +++ b/docs/revset-config.md @@ -0,0 +1,85 @@ +# Revset configuration + +## Configurable revsets + +Settings in the `revsets` section configure Jujutsu itself. These revsets may +use any [revset aliases](#revset-aliases) that you have defined. + +### `log`: Default log revisions {#revsets-log} + +You can configure the revisions `jj log` would show when neither `-r` nor any +paths are specified. + +```toml +[revsets] +# Show commits that are not in `main@origin` +log = "main@origin.." +``` + +The default value for `revsets.log` is +`'present(@) | ancestors(immutable_heads().., 2) | present(trunk())'`. + +### `short-prefixes`: Commit and change ID short prefixes {#revsets-short-prefixes} + +To control which revisions get priority for shorter prefixes, set +`revsets.short-prefixes`: + +```toml +[revsets] +# Prioritize the current bookmark +short-prefixes = "(main..@)::" +``` + +## Revset aliases + +Some revset aliases are built-in to Jujutsu and used to control its behavior. + +See the [revset language reference](revsets.md) for more information about the +revset language and defining your own revset aliases. + +### `trunk()`: Head of the main line of development {#trunk} + +Most teams have a main line of development, usually named `main`, `master`, or +`trunk`. The `trunk()` alias resolves to the bookmark for this branch. + +This alias is used in the default values for the [log +revset](#revsets-log) and for +[`immutable_heads()`](#immutable_heads). + +When Jujutsu clones a Git repository, it uses the remote's HEAD to set this +revset aliases in the repo's config. + +```toml +[revset-aliases] +"trunk()" = "dev@origin" +``` + +### `immutable_heads()`: Change the set of immutable commits {#immutable_heads} + +Controls which commits are immutable. Jujutsu will refuse to modify these +commits unless `--ignore-immutable` is specified. + +Many teams have a main line of development, usually named `main`, `master`, or +`trunk`. + +Ancestors of the configured set are also immutable. The root commit is always +immutable even if the set is empty. + +Default value: `builtin_immutable_heads()`, which in turn is defined as +`present(trunk()) | tags() | untracked_remote_bookmarks()`. + +For example, to also consider the `release@origin` bookmark immutable: + +```toml +[revset-aliases] +"immutable_heads()" = "builtin_immutable_heads() | release@origin" +``` + +To prevent rewriting commits authored by other users: + +```toml +# The `trunk().. &` bit is an optimization to scan for non-`mine()` commits +# only among commits that are not in `trunk()`. +[revset-aliases] +"immutable_heads()" = "builtin_immutable_heads() | (trunk().. & ~mine())" +``` diff --git a/docs/revsets.md b/docs/revsets.md index 810fefd5d5..34cac97299 100644 --- a/docs/revsets.md +++ b/docs/revsets.md @@ -1,4 +1,4 @@ -# Revsets +# Revset language Jujutsu supports a functional language for selecting a set of revisions. Expressions in this language are called "revsets" (the idea comes from @@ -489,7 +489,7 @@ for a comprehensive list. * `immutable_heads()`: Resolves to `present(trunk()) | tags() | untracked_remote_bookmarks()` by default. It is actually defined as `builtin_immutable_heads()`, and can be overridden as - required. See [here](config.md#set-of-immutable-commits) for details. + required. See [here](revset-config.md#immutable_heads) for details. * `immutable()`: The set of commits that `jj` treats as immutable. This is equivalent to `::(immutable_heads() | root())`. It is not recommended to redefine diff --git a/docs/template-config.md b/docs/template-config.md new file mode 100644 index 0000000000..fd23e5ff48 --- /dev/null +++ b/docs/template-config.md @@ -0,0 +1,202 @@ +# Template configuration + +## Templates + +This configuration section configures the default. These values can use [template +aliases](#template-aliases). + +### Log + +Configures the output of `jj log` when no `-T` is specified. + +```toml +[templates] +log = "builtin_log_compact" +``` + +If you want to see the full description when you do `jj log` you can add this to +your config: + +```toml +[templates] +log = "builtin_log_compact_full_description" +``` + +### Log nodes + +Configures the symbol used to represent commits in the log. In this template, +`self` is an `Option`, so the expression should first check for `!self`. + +```toml +[templates] +log_node = ''' +coalesce( + if(!self, "🮀"), + if(current_working_copy, "@"), + if(root, "┴"), + if(immutable, "●", "○"), +) +''' +``` + +### Operation log + +Configures the output of `jj operation log` when no `-T` is specified. In this +template, `self` is an `Operation`. + +```toml +[templates] +op_log = "builtin_op_log_compact" +``` + +### Operation log nodes + +Configures the symbol used to represent operations in the operation log. In this +template, `self` is an `Operation`. + +```toml +[templates] +op_log_node = 'if(current_operation, "@", "○")' +``` + +### Show + +Configures the output of `jj show` when no `-T` is specified. + +```toml +[templates] +show = "builtin_log_detailed" +``` + +### Description editor contents + +The editor content of a commit description can be populated by the +`draft_commit_description` template. + +```toml +[templates] +draft_commit_description = ''' +concat( + description, + surround( + "\nJJ: This commit contains the following changes:\n", "", + indent("JJ: ", diff.stat(72)), + ), + "\nJJ: ignore-rest\n", + diff.git(), +) +''' +``` + +To configure the value of the description itself, use the setting +[`ui.default-description`](config.md#default-description). + +## Template aliases + +Template aliases + +Some template aliases are built-in to Jujutsu and can be used to customize its output. + +See the [templating language reference](templates.md) for more information about +the templating language and defining your own template aliases. + +### Display of change and commit IDs + +#### `format_short_change_id()` + +Customizes how short change IDs are formatted. Default value: `format_short_id(id)` + +```toml +[template-aliases] +# Uppercase change ids. `jj` treats change and commit ids as case-insensitive. +'format_short_change_id(id)' = 'format_short_id(id).upper()' +``` + +#### `format_short_commit_id()` + +Customizes how short commit IDs are formatted. Default value: `format_short_id(id)` + +```toml +[template-aliases] +# Uppercase change ids. `jj` treats change and commit ids as case-insensitive. +'format_short_commit_id(id)' = 'format_short_id(id).upper()' +``` + +#### `format_short_id()` + +By default, both `format_short_change_id(id)` and `format_short_commit_id(id)` +both simply call `format_short_id(id)`, so this can be used to update both of +them together. + +```toml +[template-aliases] +# Highlight unique prefix and show at least 12 characters (default) +'format_short_id(id)' = 'id.shortest(12)' +# Just the shortest possible unique prefix +'format_short_id(id)' = 'id.shortest()' +# Show unique prefix and the rest surrounded by brackets +'format_short_id(id)' = 'id.shortest(12).prefix() ++ "[" ++ id.shortest(12).rest() ++ "]"' +# Always show 12 characters +'format_short_id(id)' = 'id.short(12)' +``` + +### Display of timestamps + +#### `format_timestamp()` + +Controls how timestamps are displayed. Default value: `timestamp` + +```toml +[template-aliases] +# Full timestamp in ISO 8601 format +'format_timestamp(timestamp)' = 'timestamp' +# Relative timestamp rendered as "x days/hours/seconds ago" +'format_timestamp(timestamp)' = 'timestamp.ago()' +``` + +`jj op log` defaults to relative timestamps. To use absolute timestamps, you +will need to modify the `format_time_range()` template alias. + +#### `format_time_range()` + +Controls how time ranges are displayed. + +```toml +[template-aliases] +'format_time_range(time_range)' = 'time_range.start() ++ " - " ++ time_range.end()' +``` + +#### `commit_timestamp()` + +Determines which timestamp is displayed for commits. + +Commits have both an "author timestamp" and "committer timestamp". By default, +jj displays the committer timestamp, but can be changed to show the author +timestamp instead. + +The function must return a timestamp because the return value will likely be +formatted with `format_timestamp()`. + +Default value: `commit.committer().timestamp()` + +```toml +[template-aliases] +'commit_timestamp(commit)' = 'commit.author().timestamp()' +``` + +### Display of commit authors + +#### `format_short_signature()` + +Controls how author and committer information are displayed in logs. Default +value: `signature.email()` + +```toml +[template-aliases] +# Full email address (default) +'format_short_signature(signature)' = 'signature.email()' +# Both name and email address +'format_short_signature(signature)' = 'signature' +# Username part of the email address +'format_short_signature(signature)' = 'signature.username()' +``` diff --git a/docs/templates.md b/docs/templates.md index bcc69a5e21..0a24e2b375 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -1,4 +1,4 @@ -# Templates +# Templating language Jujutsu supports a functional language to customize output of commands. The language consists of literals, keywords, operators, functions, and @@ -113,7 +113,7 @@ This type cannot be printed. The following methods are defined. visible commits. * `hidden() -> Boolean`: True if the commit is not visible (a.k.a. abandoned). * `immutable() -> Boolean`: True if the commit is included in [the set of - immutable commits](config.md#set-of-immutable-commits). + immutable commits](revset-config.md#immutable_heads). * `contained_in(revset: String) -> Boolean`: True if the commit is included in [the provided revset](revsets.md). * `conflict() -> Boolean`: True if the commit contains merge conflicts. * `empty() -> Boolean`: True if the commit modifies no files. diff --git a/mkdocs.yml b/mkdocs.yml index d62d7f88c3..3659dd3321 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -111,9 +111,8 @@ nav: - 'Configuration': - 'Settings': 'config.md' - - 'Fileset language': 'filesets.md' - - 'Revset language': 'revsets.md' - - 'Templating language': 'templates.md' + - 'Revset configuration': 'revset-config.md' + - 'Template configuration': 'template-config.md' - 'Comparisons': - 'Git comparison': 'git-comparison.md' @@ -121,6 +120,11 @@ nav: - 'Sapling': 'sapling-comparison.md' - 'Other related work': 'related-work.md' +- 'Reference': + - 'Fileset language': 'filesets.md' + - 'Revset language': 'revsets.md' + - 'Templating language': 'templates.md' + - 'Technical details': - 'Architecture': 'technical/architecture.md' - 'Concurrency': 'technical/concurrency.md'