ok/jj
1
0
Fork 0
forked from mirrors/jj

repo: proxy shortest unique prefix function through RepoRef

Since this function depends on both index and view, it can't be moved to
one of the storage objects. If we go forward with this approach, some
revset::resolve_*() functions will also be migrated to RepoRef.

This patch slightly changes the function name since a "prefix" might have
various meanings.
This commit is contained in:
Yuya Nishihara 2023-01-24 19:05:27 +09:00
parent c0c5e8f041
commit c018ef229b
2 changed files with 9 additions and 5 deletions

View file

@ -89,6 +89,13 @@ impl<'a> RepoRef<'a> {
RepoRef::Mutable(repo) => repo.view(),
}
}
pub fn shortest_unique_id_prefix_len(&self, target_id_bytes: &[u8]) -> usize {
match self {
RepoRef::Readonly(repo) => repo.shortest_unique_id_prefix_len(target_id_bytes),
RepoRef::Mutable(_) => target_id_bytes.len() * 2, // TODO
}
}
}
pub struct ReadonlyRepo {
@ -253,7 +260,7 @@ impl ReadonlyRepo {
})
}
pub fn shortest_unique_prefix_length(&self, target_id_bytes: &[u8]) -> usize {
pub fn shortest_unique_id_prefix_len(&self, target_id_bytes: &[u8]) -> usize {
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()

View file

@ -484,10 +484,7 @@ impl Template<()> for CommitOrChangeId<'_> {
}
fn highlight_shortest_prefix(id: &CommitOrChangeId, total_len: usize) -> String {
let prefix_len = id
.repo
.base_repo()
.shortest_unique_prefix_length(id.as_bytes());
let prefix_len = id.repo.shortest_unique_id_prefix_len(id.as_bytes());
let mut hex = id.hex();
if prefix_len < total_len - 2 {
format!(