forked from mirrors/jj
repo: add workaround for shortest prefix calculation of root ids
This is ugly, but we need a special case because root_change_id and root_commit_id aren't equal but share the same prefix bytes. In practice, no one would care for the shortest root id prefix, but we'll need to deal with a similar problem when migrating prefix id resolution to repo layer.
This commit is contained in:
parent
1a4b5c5ee6
commit
a7541e1ba4
5 changed files with 38 additions and 23 deletions
|
@ -270,16 +270,31 @@ impl ReadonlyRepo {
|
|||
}
|
||||
|
||||
pub fn shortest_unique_prefix_length(&self, target_id_bytes: &[u8]) -> usize {
|
||||
// For `len = index.shortest(id)`, a prefix of length `len` will disambiguate
|
||||
// `id` from all other ids in the index. This will be just as true for
|
||||
// `max(len, anything_else)`, so a max of such lengths will disambiguate in all
|
||||
// indices.
|
||||
cmp::max(
|
||||
self.commit_id_index()
|
||||
.shortest_unique_prefix_len(target_id_bytes),
|
||||
self.change_id_index()
|
||||
.shortest_unique_prefix_len(target_id_bytes),
|
||||
)
|
||||
let root_commit_id = self.store().root_commit_id();
|
||||
let root_change_id = backend::root_change_id();
|
||||
if target_id_bytes == root_commit_id.as_bytes()
|
||||
|| target_id_bytes == root_change_id.as_bytes()
|
||||
{
|
||||
// The root change/commit ids share the same prefix, and they are found in both
|
||||
// indices with different lengths. So we have to feed bytes of valid lengths.
|
||||
cmp::max(
|
||||
self.commit_id_index()
|
||||
.shortest_unique_prefix_len(root_commit_id.as_bytes()),
|
||||
self.change_id_index()
|
||||
.shortest_unique_prefix_len(root_change_id.as_bytes()),
|
||||
)
|
||||
} else {
|
||||
// For `len = index.shortest(id)`, a prefix of length `len` will disambiguate
|
||||
// `id` from all other ids in the index. This will be just as true for
|
||||
// `max(len, anything_else)`, so a max of such lengths will disambiguate in all
|
||||
// indices.
|
||||
cmp::max(
|
||||
self.commit_id_index()
|
||||
.shortest_unique_prefix_len(target_id_bytes),
|
||||
self.change_id_index()
|
||||
.shortest_unique_prefix_len(target_id_bytes),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn store(&self) -> &Arc<Store> {
|
||||
|
|
|
@ -131,7 +131,7 @@ fn test_alias_cannot_override_builtin() {
|
|||
// Alias should be ignored
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ fn test_log_default() {
|
|||
| (empty) description 1
|
||||
o 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae]
|
||||
| add a file
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
|
@ -78,7 +78,7 @@ fn test_log_default() {
|
|||
| (empty) description 1
|
||||
o 9a[45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 4[291e264ae]
|
||||
| add a file
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
|
@ -99,7 +99,7 @@ fn test_log_default() {
|
|||
| [1m[38;5;10m(empty) [39mdescription 1[0m
|
||||
o [38;5;5m9a[45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae][39m
|
||||
| add a file
|
||||
o [38;5;5m000000000000[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||
o [38;5;5m0[000000000][39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m0[000000000][39m
|
||||
[38;5;2m(empty) [39m(no description set)
|
||||
"###);
|
||||
|
||||
|
@ -110,7 +110,7 @@ fn test_log_default() {
|
|||
[1m[38;5;10m(empty) [39mdescription 1[0m
|
||||
[38;5;5m9a[45c67d3e][39m [38;5;3mtest.user@example.com[39m [38;5;6m2001-02-03 04:05:08.000 +07:00[39m [38;5;4m4[291e264ae][39m
|
||||
add a file
|
||||
[38;5;5m000000000000[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||
[38;5;5m0[000000000][39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m0[000000000][39m
|
||||
[38;5;2m(empty) [39m(no description set)
|
||||
"###);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ fn test_log_default_divergence() {
|
|||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ 9[a45c67d3e] test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e63]
|
||||
| description 1
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
|
@ -144,7 +144,7 @@ fn test_log_default_divergence() {
|
|||
| description 2
|
||||
| @ 9[a45c67d3e]?? test.user@example.com 2001-02-03 04:05:08.000 +07:00 7[a17d52e63]
|
||||
|/ description 1
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
|
@ -155,7 +155,7 @@ fn test_log_default_divergence() {
|
|||
| description 2
|
||||
| @ [1m[38;5;9m9[a45c67d3e]??[39m [38;5;3mtest.user@example.com[39m [38;5;14m2001-02-03 04:05:08.000 +07:00[39m [38;5;12m7[a17d52e63][39m[0m
|
||||
|/ [1mdescription 1[0m
|
||||
o [38;5;5m000000000000[39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m000000000000[39m
|
||||
o [38;5;5m0[000000000][39m [38;5;6m1970-01-01 00:00:00.000 +00:00[39m [38;5;4m0[000000000][39m
|
||||
[38;5;2m(empty) [39m(no description set)
|
||||
"###);
|
||||
}
|
||||
|
|
|
@ -356,7 +356,7 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
|
|||
test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", prefix_format]),
|
||||
@r###"
|
||||
@ Change 9[a45c67d3e] initial b[a1a30916d] original
|
||||
o Change 000000000000 (no description set) 000000000000
|
||||
o Change 0[000000000] (no description set) 0[000000000]
|
||||
"###
|
||||
);
|
||||
for i in 1..100 {
|
||||
|
@ -376,7 +376,7 @@ fn test_log_prefix_highlight_counts_hidden_commits() {
|
|||
test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", prefix_format]),
|
||||
@r###"
|
||||
@ Change 9a4[5c67d3e] commit99 de[3177d2ac] original
|
||||
o Change 000000000000 (no description set) 000000000000
|
||||
o Change 000[0000000] (no description set) 000[0000000]
|
||||
"###
|
||||
);
|
||||
insta::assert_snapshot!(
|
||||
|
|
|
@ -161,13 +161,13 @@ fn test_alias() {
|
|||
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "my-root"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "identity(my-root)"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
|
||||
|
@ -263,7 +263,7 @@ fn test_bad_alias_decl() {
|
|||
.assert()
|
||||
.success();
|
||||
insta::assert_snapshot!(get_stdout_string(&assert), @r###"
|
||||
o 000000000000 1970-01-01 00:00:00.000 +00:00 000000000000
|
||||
o 0[000000000] 1970-01-01 00:00:00.000 +00:00 0[000000000]
|
||||
(empty) (no description set)
|
||||
"###);
|
||||
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
||||
|
|
Loading…
Reference in a new issue