ok/jj
1
0
Fork 0
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:
Martin von Zweigbergk 2023-05-05 17:12:08 -07:00 committed by Martin von Zweigbergk
parent 6a4502cb5d
commit eab5218fe5
7 changed files with 73 additions and 10 deletions

View file

@ -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

View file

@ -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.

View file

@ -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(),

View file

@ -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": {

View file

@ -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)

View file

@ -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!(

View file

@ -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