diff --git a/CHANGELOG.md b/CHANGELOG.md index 63b0d70203..406d6c62a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Description tempfiles created via `jj describe` now have the file extension `.jjdescription` to help external tooling detect a unique filetype. +* The shortest unique change ID prefixes and commit ID prefixes in `jj log` are + now shorter within the default log revset. You can override the default by + setting the `revsets.short-prefixes` config to a different revset. + ### Fixed bugs * Modify/delete conflicts now include context lines diff --git a/docs/config.md b/docs/config.md index e4cfdd7f01..2fcf457b3f 100644 --- a/docs/config.md +++ b/docs/config.md @@ -192,6 +192,13 @@ To customize these separately, use the `format_short_commit_id()` and 'format_short_change_id(id)' = 'format_short_id(id).upper()' ``` +To get shorter prefixes for certain revisions, set `revsets.short-prefixes`: + +```toml +# Prioritize the current branch +revsets.short-prefixes = "(main..@):" +``` + ### Relative timestamps Can be customized by the `format_timestamp()` template alias. diff --git a/src/cli_util.rs b/src/cli_util.rs index eeb4fea30c..59bc533835 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -940,7 +940,17 @@ impl WorkspaceCommandHelper { pub fn id_prefix_context(&self) -> &IdPrefixContext<'_> { self.user_repo.id_prefix_context.get_or_init(|| { - let context: IdPrefixContext<'_> = IdPrefixContext::new(self.user_repo.repo.as_ref()); + let mut context: IdPrefixContext<'_> = IdPrefixContext::new(self.repo().as_ref()); + let revset_string: String = self + .settings + .config() + .get_string("revsets.short-prefixes") + .unwrap_or_else(|_| self.settings.default_revset()); + if !revset_string.is_empty() { + let disambiguation_revset = self.parse_revset(&revset_string).unwrap(); + context = + context.disambiguate_within(disambiguation_revset, Some(self.workspace_id())); + } let context: IdPrefixContext<'static> = unsafe { std::mem::transmute(context) }; context }) @@ -1288,6 +1298,7 @@ impl WorkspaceCommandTransaction<'_> { formatter: &mut dyn Formatter, commit: &Commit, ) -> std::io::Result<()> { + // TODO: Use the disambiguation revset let id_prefix_context = IdPrefixContext::new(self.tx.repo()); let template = parse_commit_summary_template( self.tx.repo(), diff --git a/src/config-schema.json b/src/config-schema.json index 6bcfbdf8b7..f568dd6f9c 100644 --- a/src/config-schema.json +++ b/src/config-schema.json @@ -270,6 +270,11 @@ "type": "string", "description": "Default set of revisions to show when no explicit revset is given for jj log and similar commands", "default": "@ | (remote_branches() | tags()).. | ((remote_branches() | tags())..)-" + }, + "short-prefixes": { + "type": "string", + "description": "Revisions to give shorter change and commit IDs to", + "default": "" } }, "additionalProperties": { diff --git a/tests/test_commit_template.rs b/tests/test_commit_template.rs index 40a54edd64..d9886888ee 100644 --- a/tests/test_commit_template.rs +++ b/tests/test_commit_template.rs @@ -281,7 +281,7 @@ fn test_log_git_head() { insta::assert_snapshot!(stdout, @r###" @ rlvkpnrzqnoo test.user@example.com 2001-02-03 04:05:09.000 +07:00 50aaf4754c1e │ initial - ◉ qpvuntsmwlqt test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 230dd059e1b0 + ◉ qpvuntsmwlqt test.user@example.com 2001-02-03 04:05:07.000 +07:00 master HEAD@git 230dd059e1b0 │ (empty) (no description set) ◉ zzzzzzzzzzzz 1970-01-01 00:00:00.000 +00:00 000000000000 (empty) (no description set) diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index d1c286e2b8..cc66c33138 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -315,13 +315,49 @@ fn test_log_shortest_accessors() { zn 38 yo 0cf vr 9e - yq 06f + yq 06 ro 1f mz 7b qpv ba1 zzz 00 "###); + insta::assert_snapshot!( + render(":@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), + @r###" + wq[nwkozpkust] 03[f51310b83e] + km[kuslswpqwq] f7[7fb1909080] + kp[qxywonksrl] e7[15ad5db646] + zn[kkpsqqskkl] 38[622e54e2e5] + yo[stqsxwqrlt] 0cf[42f60199c] + vr[uxwmqvtpmx] 9e[6015e4e622] + yq[osqzytrlsw] 06[f34d9b1475] + ro[yxmykxtrkr] 1f[99a5e19891] + mz[vwutvlkqwt] 7b[1f7dee65b4] + qpv[untsmwlqt] ba1[a30916d29] + zzz[zzzzzzzzz] 00[0000000000] + "###); + + // Can get shorter prefixes in configured revset + test_env.add_config(&r#"revsets.short-prefixes = "(@----):""#); + insta::assert_snapshot!( + render(":@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), + @r###" + w[qnwkozpkust] 03[f51310b83e] + km[kuslswpqwq] f[77fb1909080] + kp[qxywonksrl] e[715ad5db646] + z[nkkpsqqskkl] 3[8622e54e2e5] + y[ostqsxwqrlt] 0c[f42f60199c] + vr[uxwmqvtpmx] 9e[6015e4e622] + yq[osqzytrlsw] 06f[34d9b1475] + ro[yxmykxtrkr] 1f[99a5e19891] + mz[vwutvlkqwt] 7b[1f7dee65b4] + qpv[untsmwlqt] ba1[a30916d29] + zzz[zzzzzzzzz] 00[0000000000] + "###); + + // Can disable short prefixes by setting to empty string + test_env.add_config(&r#"revsets.short-prefixes = """#); insta::assert_snapshot!( render(":@", r#"format_id(change_id) ++ " " ++ format_id(commit_id) ++ "\n""#), @r###" @@ -409,7 +445,7 @@ fn test_log_prefix_highlight_styled() { ◉ Change znkkpsqqskkl commit6 38622e54e2e5 ◉ Change yostqsxwqrlt commit5 0cf42f60199c ◉ Change vruxwmqvtpmx commit4 9e6015e4e622 - ◉ Change yqosqzytrlsw commit3 06f34d9b1475 + ◉ Change yqosqzytrlsw commit3 06f34d9b1475 ◉ Change royxmykxtrkr commit2 1f99a5e19891 ◉ Change mzvwutvlkqwt commit1 7b1f7dee65b4 ◉ Change qpvuntsmwlqt initial ba1a30916d29 original @@ -435,7 +471,7 @@ fn test_log_prefix_highlight_styled() { ◉ Change znk commit6 386 ◉ Change yos commit5 0cf ◉ Change vru commit4 9e6 - ◉ Change yqo commit3 06f + ◉ Change yqo commit3 06f ◉ Change roy commit2 1f9 ◉ Change mzv commit1 7b1 ◉ Change qpv initial ba1 original @@ -461,7 +497,7 @@ fn test_log_prefix_highlight_styled() { ◉ Change zn commit6 38 ◉ Change yo commit5 0cf ◉ Change vr commit4 9e - ◉ Change yq commit3 06f + ◉ Change yq commit3 06 ◉ Change ro commit2 1f ◉ Change mz commit1 7b ◉ Change qpv initial ba1 original @@ -514,10 +550,10 @@ fn test_log_prefix_highlight_counts_hidden_commits() { insta::assert_snapshot!( test_env.jj_cmd_success(&repo_path, &["log", "-T", prefix_format]), @r###" - @ Change w[qnwkozpkust] 44[4c3c5066d3] - │ ◉ Change q[pvuntsmwlqt] initial ba[1a30916d29] original + @ Change w[qnwkozpkust] 4[44c3c5066d3] + │ ◉ Change q[pvuntsmwlqt] initial b[a1a30916d29] original ├─╯ - ◉ Change z[zzzzzzzzzzz] 00[0000000000] + ◉ Change z[zzzzzzzzzzz] 0[00000000000] "### ); insta::assert_snapshot!( diff --git a/tests/test_obslog_command.rs b/tests/test_obslog_command.rs index 5e29369e5f..d3660436ef 100644 --- a/tests/test_obslog_command.rs +++ b/tests/test_obslog_command.rs @@ -44,7 +44,7 @@ fn test_obslog_with_or_without_diff() { // Color let stdout = test_env.jj_cmd_success(&repo_path, &["--color=always", "obslog"]); insta::assert_snapshot!(stdout, @r###" - @ rlvkpnrzqnoo test.user@example.com 2001-02-03 04:05:10.000 +07:00 66b42ad36073 + @ rlvkpnrzqnoo test.user@example.com 2001-02-03 04:05:10.000 +07:00 66b42ad36073 │ my description ◉ rlvkpnrzqnoo hidden test.user@example.com 2001-02-03 04:05:09.000 +07:00 af536e5af67e conflict │ my description