mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 23:23:20 +00:00
index: add a type parameter to PrefixResolution to prepare for ChangeId prefix
This commit is contained in:
parent
0d9d141705
commit
a3cb0ee3d1
1 changed files with 11 additions and 11 deletions
|
@ -79,7 +79,7 @@ impl<'a> IndexRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
match self {
|
match self {
|
||||||
IndexRef::Readonly(index) => index.resolve_prefix(prefix),
|
IndexRef::Readonly(index) => index.resolve_prefix(prefix),
|
||||||
IndexRef::Mutable(index) => index.resolve_prefix(prefix),
|
IndexRef::Mutable(index) => index.resolve_prefix(prefix),
|
||||||
|
@ -298,14 +298,14 @@ impl HexPrefix {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum PrefixResolution {
|
pub enum PrefixResolution<T> {
|
||||||
NoMatch,
|
NoMatch,
|
||||||
SingleMatch(CommitId),
|
SingleMatch(T),
|
||||||
AmbiguousMatch,
|
AmbiguousMatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixResolution {
|
impl<T: Clone> PrefixResolution<T> {
|
||||||
fn plus(&self, other: &PrefixResolution) -> PrefixResolution {
|
fn plus(&self, other: &PrefixResolution<T>) -> PrefixResolution<T> {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(PrefixResolution::NoMatch, other) => other.clone(),
|
(PrefixResolution::NoMatch, other) => other.clone(),
|
||||||
(local, PrefixResolution::NoMatch) => local.clone(),
|
(local, PrefixResolution::NoMatch) => local.clone(),
|
||||||
|
@ -634,7 +634,7 @@ impl MutableIndex {
|
||||||
CompositeIndex(self).commit_id_to_pos(commit_id)
|
CompositeIndex(self).commit_id_to_pos(commit_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
CompositeIndex(self).resolve_prefix(prefix)
|
CompositeIndex(self).resolve_prefix(prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,7 +688,7 @@ trait IndexSegment {
|
||||||
|
|
||||||
fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option<IndexPosition>;
|
fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option<IndexPosition>;
|
||||||
|
|
||||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution;
|
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId>;
|
||||||
|
|
||||||
fn segment_is_pruned(&self, local_pos: u32) -> bool;
|
fn segment_is_pruned(&self, local_pos: u32) -> bool;
|
||||||
|
|
||||||
|
@ -790,7 +790,7 @@ impl<'a> CompositeIndex<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
let local_match = self.0.segment_resolve_prefix(prefix);
|
let local_match = self.0.segment_resolve_prefix(prefix);
|
||||||
if local_match == PrefixResolution::AmbiguousMatch {
|
if local_match == PrefixResolution::AmbiguousMatch {
|
||||||
// return early to avoid checking the parent file(s)
|
// return early to avoid checking the parent file(s)
|
||||||
|
@ -1139,7 +1139,7 @@ impl IndexSegment for ReadonlyIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
||||||
match self.commit_id_byte_prefix_to_pos(&min_bytes_prefix) {
|
match self.commit_id_byte_prefix_to_pos(&min_bytes_prefix) {
|
||||||
None => PrefixResolution::NoMatch,
|
None => PrefixResolution::NoMatch,
|
||||||
|
@ -1253,7 +1253,7 @@ impl IndexSegment for MutableIndex {
|
||||||
self.lookup.get(commit_id).cloned()
|
self.lookup.get(commit_id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
let (bytes_prefix, min_bytes_prefix) = prefix.bytes_prefixes();
|
||||||
let mut potential_range = self
|
let mut potential_range = self
|
||||||
.lookup
|
.lookup
|
||||||
|
@ -1482,7 +1482,7 @@ impl ReadonlyIndex {
|
||||||
CompositeIndex(self).commit_id_to_pos(commit_id)
|
CompositeIndex(self).commit_id_to_pos(commit_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution {
|
pub fn resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution<CommitId> {
|
||||||
CompositeIndex(self).resolve_prefix(prefix)
|
CompositeIndex(self).resolve_prefix(prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue