forked from mirrors/jj
cli: allow resolving shorter ids within a configured revset
This adds a config called `revsets.short-prefixes`, which lets the user specify a revset in which to disambiguate otherwise ambiguous change/commit ids. It defaults to the value of `revsets.log`. I made it so you can disable the feature by setting `revsets.short-prefixes = ""`. I don't like that the default value (using `revsets.log`) cannot be configured explicitly by the user. That will be addressed if we decide to merge the `[revsets]` and `[revset-aliases]` sections some day.
This commit is contained in:
parent
6a4502cb5d
commit
eab5218fe5
7 changed files with 73 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -936,7 +936,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().clone()));
|
||||
}
|
||||
let context: IdPrefixContext<'static> = unsafe { std::mem::transmute(context) };
|
||||
context
|
||||
})
|
||||
|
@ -1284,6 +1294,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(),
|
||||
|
|
|
@ -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": "<revsets.log>"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {
|
||||
|
|
|
@ -281,7 +281,7 @@ fn test_log_git_head() {
|
|||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ [1m[38;5;13mr[38;5;8mlvkpnrzqnoo[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:09.000 +07:00[39m [38;5;12m5[38;5;8m0aaf4754c1e[39m[0m
|
||||
│ [1minitial[0m
|
||||
◉ [1m[38;5;5mq[0m[38;5;8mpvuntsmwlqt[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m [38;5;5mmaster[39m [38;5;5mHEAD@git[39m [1m[38;5;4m23[0m[38;5;8m0dd059e1b0[39m
|
||||
◉ [1m[38;5;5mq[0m[38;5;8mpvuntsmwlqt[39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:07.000 +07:00[39m [38;5;5mmaster[39m [38;5;5mHEAD@git[39m [1m[38;5;4m2[0m[38;5;8m30dd059e1b0[39m
|
||||
│ [38;5;2m(empty)[39m (no description set)
|
||||
◉ [1m[38;5;5mz[0m[38;5;8mzzzzzzzzzzz[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [1m[38;5;4m0[0m[38;5;8m00000000000[39m
|
||||
[38;5;2m(empty)[39m (no description set)
|
||||
|
|
|
@ -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 [1m[38;5;5mzn[0m[38;5;8mkkpsqqskkl[39m commit6 [1m[38;5;4m38[0m[38;5;8m622e54e2e5[39m
|
||||
◉ Change [1m[38;5;5myo[0m[38;5;8mstqsxwqrlt[39m commit5 [1m[38;5;4m0cf[0m[38;5;8m42f60199c[39m
|
||||
◉ Change [1m[38;5;5mvr[0m[38;5;8muxwmqvtpmx[39m commit4 [1m[38;5;4m9e[0m[38;5;8m6015e4e622[39m
|
||||
◉ Change [1m[38;5;5myq[0m[38;5;8mosqzytrlsw[39m commit3 [1m[38;5;4m06f[0m[38;5;8m34d9b1475[39m
|
||||
◉ Change [1m[38;5;5myq[0m[38;5;8mosqzytrlsw[39m commit3 [1m[38;5;4m06[0m[38;5;8mf34d9b1475[39m
|
||||
◉ Change [1m[38;5;5mro[0m[38;5;8myxmykxtrkr[39m commit2 [1m[38;5;4m1f[0m[38;5;8m99a5e19891[39m
|
||||
◉ Change [1m[38;5;5mmz[0m[38;5;8mvwutvlkqwt[39m commit1 [1m[38;5;4m7b[0m[38;5;8m1f7dee65b4[39m
|
||||
◉ Change [1m[38;5;5mqpv[0m[38;5;8muntsmwlqt[39m initial [1m[38;5;4mba1[0m[38;5;8ma30916d29[39m [38;5;5moriginal[39m
|
||||
|
@ -435,7 +471,7 @@ fn test_log_prefix_highlight_styled() {
|
|||
◉ Change [1m[38;5;5mzn[0m[38;5;8mk[39m commit6 [1m[38;5;4m38[0m[38;5;8m6[39m
|
||||
◉ Change [1m[38;5;5myo[0m[38;5;8ms[39m commit5 [1m[38;5;4m0cf[0m
|
||||
◉ Change [1m[38;5;5mvr[0m[38;5;8mu[39m commit4 [1m[38;5;4m9e[0m[38;5;8m6[39m
|
||||
◉ Change [1m[38;5;5myq[0m[38;5;8mo[39m commit3 [1m[38;5;4m06f[0m
|
||||
◉ Change [1m[38;5;5myq[0m[38;5;8mo[39m commit3 [1m[38;5;4m06[0m[38;5;8mf[39m
|
||||
◉ Change [1m[38;5;5mro[0m[38;5;8my[39m commit2 [1m[38;5;4m1f[0m[38;5;8m9[39m
|
||||
◉ Change [1m[38;5;5mmz[0m[38;5;8mv[39m commit1 [1m[38;5;4m7b[0m[38;5;8m1[39m
|
||||
◉ Change [1m[38;5;5mqpv[0m initial [1m[38;5;4mba1[0m [38;5;5moriginal[39m
|
||||
|
@ -461,7 +497,7 @@ fn test_log_prefix_highlight_styled() {
|
|||
◉ Change [1m[38;5;5mzn[0m commit6 [1m[38;5;4m38[0m
|
||||
◉ Change [1m[38;5;5myo[0m commit5 [1m[38;5;4m0cf[0m
|
||||
◉ Change [1m[38;5;5mvr[0m commit4 [1m[38;5;4m9e[0m
|
||||
◉ Change [1m[38;5;5myq[0m commit3 [1m[38;5;4m06f[0m
|
||||
◉ Change [1m[38;5;5myq[0m commit3 [1m[38;5;4m06[0m
|
||||
◉ Change [1m[38;5;5mro[0m commit2 [1m[38;5;4m1f[0m
|
||||
◉ Change [1m[38;5;5mmz[0m commit1 [1m[38;5;4m7b[0m
|
||||
◉ Change [1m[38;5;5mqpv[0m initial [1m[38;5;4mba1[0m [38;5;5moriginal[39m
|
||||
|
@ -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!(
|
||||
|
|
|
@ -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###"
|
||||
@ [1m[38;5;13mr[38;5;8mlvkpnrzqnoo[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:10.000 +07:00[39m [38;5;12m66[38;5;8mb42ad36073[39m[0m
|
||||
@ [1m[38;5;13mr[38;5;8mlvkpnrzqnoo[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:10.000 +07:00[39m [38;5;12m6[38;5;8m6b42ad36073[39m[0m
|
||||
│ [1mmy description[0m
|
||||
◉ [1m[39mr[0m[38;5;8mlvkpnrzqnoo[39m hidden [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:09.000 +07:00[39m [1m[38;5;4maf[0m[38;5;8m536e5af67e[39m [38;5;1mconflict[39m
|
||||
│ my description
|
||||
|
|
Loading…
Reference in a new issue